close resources
fix a few eclipse warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1717077 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d7c3a9b2ca
commit
ee0f9b84e1
@ -72,7 +72,7 @@ public final class ApacheconEU08 {
|
|||||||
FileOutputStream out = new FileOutputStream("apachecon_eu_08."+ext);
|
FileOutputStream out = new FileOutputStream("apachecon_eu_08."+ext);
|
||||||
ppt.write(out);
|
ppt.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void slide1(SlideShow<?,?> ppt) throws IOException {
|
public static void slide1(SlideShow<?,?> ppt) throws IOException {
|
||||||
|
@ -19,11 +19,15 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows how various alignment options work.
|
* Shows how various alignment options work.
|
||||||
*
|
*
|
||||||
@ -46,6 +50,8 @@ public class Alignment {
|
|||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +50,7 @@ public class AligningCells {
|
|||||||
FileOutputStream fileOut = new FileOutputStream("ss-example-align.xlsx");
|
FileOutputStream fileOut = new FileOutputStream("ss-example-align.xlsx");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,8 +21,13 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
import org.apache.poi.xssf.usermodel.*;
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +68,8 @@ public class AligningCells {
|
|||||||
FileOutputStream fileOut = new FileOutputStream("xssf-align.xlsx");
|
FileOutputStream fileOut = new FileOutputStream("xssf-align.xlsx");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -278,12 +278,11 @@ public class AgileDecryptor extends Decryptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException {
|
public InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException {
|
||||||
DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY);
|
DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY);
|
||||||
_length = dis.readLong();
|
_length = dis.readLong();
|
||||||
|
return new AgileCipherInputStream(dis, _length);
|
||||||
ChunkedCipherInputStream cipherStream = new AgileCipherInputStream(dis, _length);
|
|
||||||
return cipherStream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLength(){
|
public long getLength(){
|
||||||
|
@ -29,3 +29,6 @@ java.util.Date#toString() @ Do not use methods that depend on the current Local,
|
|||||||
# Disallow reflection on private object fields/methods
|
# Disallow reflection on private object fields/methods
|
||||||
java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[], boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9
|
java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[], boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9
|
||||||
java.lang.reflect.AccessibleObject#setAccessible(boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9
|
java.lang.reflect.AccessibleObject#setAccessible(boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9
|
||||||
|
|
||||||
|
java.text.DecimalFormatSymbols#DecimalFormatSymbols() @ use DecimalFormatSymbols.getInstance()
|
||||||
|
java.text.DecimalFormatSymbols#DecimalFormatSymbols(Locale) @ use DecimalFormatSymbols.getInstance()
|
||||||
|
@ -37,7 +37,6 @@ import org.apache.poi.hwpf.usermodel.TableRow;
|
|||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.poi.util.IOUtils;
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.w3c.dom.Attr;
|
import org.w3c.dom.Attr;
|
||||||
@ -484,13 +483,10 @@ public class AbstractWordUtils
|
|||||||
public static HWPFDocumentCore loadDoc( File docFile ) throws IOException
|
public static HWPFDocumentCore loadDoc( File docFile ) throws IOException
|
||||||
{
|
{
|
||||||
final FileInputStream istream = new FileInputStream( docFile );
|
final FileInputStream istream = new FileInputStream( docFile );
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return loadDoc( istream );
|
return loadDoc( istream );
|
||||||
}
|
} finally {
|
||||||
finally
|
istream.close();
|
||||||
{
|
|
||||||
IOUtils.closeQuietly( istream );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,11 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.ss.formula.eval;
|
package org.apache.poi.ss.formula.eval;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import static org.junit.Assert.assertEquals;
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
@ -26,12 +29,15 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
|||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common superclass for testing cases of circular references
|
* Common superclass for testing cases of circular references
|
||||||
* both for HSSF and XSSF
|
* both for HSSF and XSSF
|
||||||
*/
|
*/
|
||||||
public abstract class BaseTestCircularReferences extends TestCase {
|
public abstract class BaseTestCircularReferences {
|
||||||
|
|
||||||
protected final ITestDataProvider _testDataProvider;
|
protected final ITestDataProvider _testDataProvider;
|
||||||
|
|
||||||
@ -68,8 +74,8 @@ public abstract class BaseTestCircularReferences extends TestCase {
|
|||||||
* ASF Bugzilla Bug 44413
|
* ASF Bugzilla Bug 44413
|
||||||
* "INDEX() formula cannot contain its own location in the data array range"
|
* "INDEX() formula cannot contain its own location in the data array range"
|
||||||
*/
|
*/
|
||||||
public void testIndexFormula() {
|
@Test
|
||||||
|
public void testIndexFormula() throws IOException {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet = wb.createSheet("Sheet1");
|
Sheet sheet = wb.createSheet("Sheet1");
|
||||||
|
|
||||||
@ -91,13 +97,14 @@ public abstract class BaseTestCircularReferences extends TestCase {
|
|||||||
|
|
||||||
assertTrue(cellValue.getCellType() == Cell.CELL_TYPE_NUMERIC);
|
assertTrue(cellValue.getCellType() == Cell.CELL_TYPE_NUMERIC);
|
||||||
assertEquals(2, cellValue.getNumberValue(), 0);
|
assertEquals(2, cellValue.getNumberValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cell A1 has formula "=A1"
|
* Cell A1 has formula "=A1"
|
||||||
*/
|
*/
|
||||||
public void testSimpleCircularReference() {
|
@Test
|
||||||
|
public void testSimpleCircularReference() throws IOException {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet = wb.createSheet("Sheet1");
|
Sheet sheet = wb.createSheet("Sheet1");
|
||||||
|
|
||||||
@ -108,13 +115,15 @@ public abstract class BaseTestCircularReferences extends TestCase {
|
|||||||
CellValue cellValue = evaluateWithCycles(wb, testCell);
|
CellValue cellValue = evaluateWithCycles(wb, testCell);
|
||||||
|
|
||||||
confirmCycleErrorCode(cellValue);
|
confirmCycleErrorCode(cellValue);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A1=B1, B1=C1, C1=D1, D1=A1
|
* A1=B1, B1=C1, C1=D1, D1=A1
|
||||||
*/
|
*/
|
||||||
public void testMultiLevelCircularReference() {
|
@Test
|
||||||
|
public void testMultiLevelCircularReference() throws IOException {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet = wb.createSheet("Sheet1");
|
Sheet sheet = wb.createSheet("Sheet1");
|
||||||
|
|
||||||
@ -128,9 +137,12 @@ public abstract class BaseTestCircularReferences extends TestCase {
|
|||||||
CellValue cellValue = evaluateWithCycles(wb, testCell);
|
CellValue cellValue = evaluateWithCycles(wb, testCell);
|
||||||
|
|
||||||
confirmCycleErrorCode(cellValue);
|
confirmCycleErrorCode(cellValue);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIntermediateCircularReferenceResults_bug46898() {
|
@Test
|
||||||
|
public void testIntermediateCircularReferenceResults_bug46898() throws IOException {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet = wb.createSheet("Sheet1");
|
Sheet sheet = wb.createSheet("Sheet1");
|
||||||
|
|
||||||
@ -162,9 +174,8 @@ public abstract class BaseTestCircularReferences extends TestCase {
|
|||||||
// Show the bug - evaluate another cell from the loop first
|
// Show the bug - evaluate another cell from the loop first
|
||||||
fe.clearAllCachedResultValues();
|
fe.clearAllCachedResultValues();
|
||||||
cv = fe.evaluate(cellB1);
|
cv = fe.evaluate(cellB1);
|
||||||
if (cv.getCellType() == ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()) {
|
// Identified bug 46898
|
||||||
throw new AssertionFailedError("Identified bug 46898");
|
assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode());
|
||||||
}
|
|
||||||
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
|
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
|
||||||
assertEquals(46.0, cv.getNumberValue(), 0.0);
|
assertEquals(46.0, cv.getNumberValue(), 0.0);
|
||||||
|
|
||||||
@ -173,5 +184,7 @@ public abstract class BaseTestCircularReferences extends TestCase {
|
|||||||
cv = fe.evaluate(cellE1);
|
cv = fe.evaluate(cellE1);
|
||||||
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
|
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
|
||||||
assertEquals(43.0, cv.getNumberValue(), 0.0);
|
assertEquals(43.0, cv.getNumberValue(), 0.0);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,9 @@ public final class TestText {
|
|||||||
ValueEval formatArg = new StringEval("#,###.00000");
|
ValueEval formatArg = new StringEval("#,###.00000");
|
||||||
ValueEval[] args = { numArg, formatArg };
|
ValueEval[] args = { numArg, formatArg };
|
||||||
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
char groupSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getGroupingSeparator();
|
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale());
|
||||||
char decimalSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getDecimalSeparator();
|
char groupSeparator = dfs.getGroupingSeparator();
|
||||||
|
char decimalSeparator = dfs.getDecimalSeparator();
|
||||||
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
|
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
|
||||||
assertEquals(testResult.toString(), result.toString());
|
assertEquals(testResult.toString(), result.toString());
|
||||||
numArg = new NumberEval(321.321);
|
numArg = new NumberEval(321.321);
|
||||||
|
@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -41,13 +42,13 @@ public abstract class BaseTestHyperlink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void testBasicTypes(){
|
public final void testBasicTypes() throws IOException {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||||
CreationHelper createHelper = wb.getCreationHelper();
|
CreationHelper createHelper = wb1.getCreationHelper();
|
||||||
|
|
||||||
Cell cell;
|
Cell cell;
|
||||||
Hyperlink link;
|
Hyperlink link;
|
||||||
Sheet sheet = wb.createSheet("Hyperlinks");
|
Sheet sheet = wb1.createSheet("Hyperlinks");
|
||||||
|
|
||||||
//URL
|
//URL
|
||||||
cell = sheet.createRow(0).createCell((short) 0);
|
cell = sheet.createRow(0).createCell((short) 0);
|
||||||
@ -74,7 +75,7 @@ public abstract class BaseTestHyperlink {
|
|||||||
//link to a place in this workbook
|
//link to a place in this workbook
|
||||||
|
|
||||||
//create a target sheet and cell
|
//create a target sheet and cell
|
||||||
Sheet sheet2 = wb.createSheet("Target Sheet");
|
Sheet sheet2 = wb1.createSheet("Target Sheet");
|
||||||
sheet2.createRow(0).createCell((short) 0).setCellValue("Target Cell");
|
sheet2.createRow(0).createCell((short) 0).setCellValue("Target Cell");
|
||||||
|
|
||||||
cell = sheet.createRow(3).createCell((short) 0);
|
cell = sheet.createRow(3).createCell((short) 0);
|
||||||
@ -83,9 +84,10 @@ public abstract class BaseTestHyperlink {
|
|||||||
link.setAddress("'Target Sheet'!A1");
|
link.setAddress("'Target Sheet'!A1");
|
||||||
cell.setHyperlink(link);
|
cell.setHyperlink(link);
|
||||||
|
|
||||||
wb = _testDataProvider.writeOutAndReadBack(wb);
|
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||||
|
wb1.close();
|
||||||
|
|
||||||
sheet = wb.getSheetAt(0);
|
sheet = wb2.getSheetAt(0);
|
||||||
link = sheet.getRow(0).getCell(0).getHyperlink();
|
link = sheet.getRow(0).getCell(0).getHyperlink();
|
||||||
|
|
||||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||||
@ -95,11 +97,13 @@ public abstract class BaseTestHyperlink {
|
|||||||
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
|
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
|
||||||
link = sheet.getRow(3).getCell(0).getHyperlink();
|
link = sheet.getRow(3).getCell(0).getHyperlink();
|
||||||
assertEquals("'Target Sheet'!A1", link.getAddress());
|
assertEquals("'Target Sheet'!A1", link.getAddress());
|
||||||
|
|
||||||
|
wb2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy a hyperlink via the copy constructor
|
// copy a hyperlink via the copy constructor
|
||||||
@Test
|
@Test
|
||||||
public void testCopyHyperlink() {
|
public void testCopyHyperlink() throws IOException {
|
||||||
final Workbook wb = _testDataProvider.createWorkbook();
|
final Workbook wb = _testDataProvider.createWorkbook();
|
||||||
final CreationHelper createHelper = wb.getCreationHelper();
|
final CreationHelper createHelper = wb.getCreationHelper();
|
||||||
|
|
||||||
@ -136,6 +140,8 @@ public abstract class BaseTestHyperlink {
|
|||||||
assertEquals(2, actualHyperlinks.size());
|
assertEquals(2, actualHyperlinks.size());
|
||||||
assertEquals(link1, actualHyperlinks.get(0));
|
assertEquals(link1, actualHyperlinks.get(0));
|
||||||
assertEquals(link2, actualHyperlinks.get(1));
|
assertEquals(link2, actualHyperlinks.get(1));
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Hyperlink copyHyperlink(Hyperlink link);
|
public abstract Hyperlink copyHyperlink(Hyperlink link);
|
||||||
|
Loading…
Reference in New Issue
Block a user