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:
Andreas Beeker 2015-11-29 15:26:53 +00:00
parent d7c3a9b2ca
commit ee0f9b84e1
10 changed files with 70 additions and 38 deletions

View File

@ -72,7 +72,7 @@ public final class ApacheconEU08 {
FileOutputStream out = new FileOutputStream("apachecon_eu_08."+ext);
ppt.write(out);
out.close();
ppt.close();
}
public static void slide1(SlideShow<?,?> ppt) throws IOException {

View File

@ -19,11 +19,15 @@
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
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.
*
@ -46,6 +50,8 @@ public class Alignment {
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
/**

View File

@ -50,6 +50,7 @@ public class AligningCells {
FileOutputStream fileOut = new FileOutputStream("ss-example-align.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
/**

View File

@ -21,8 +21,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.CellStyle;
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;
/**
@ -63,6 +68,8 @@ public class AligningCells {
FileOutputStream fileOut = new FileOutputStream("xssf-align.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
/**

View File

@ -278,12 +278,11 @@ public class AgileDecryptor extends Decryptor {
}
}
@SuppressWarnings("resource")
public InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException {
DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY);
_length = dis.readLong();
ChunkedCipherInputStream cipherStream = new AgileCipherInputStream(dis, _length);
return cipherStream;
return new AgileCipherInputStream(dis, _length);
}
public long getLength(){

View File

@ -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
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.text.DecimalFormatSymbols#DecimalFormatSymbols() @ use DecimalFormatSymbols.getInstance()
java.text.DecimalFormatSymbols#DecimalFormatSymbols(Locale) @ use DecimalFormatSymbols.getInstance()

View File

@ -37,7 +37,6 @@ import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.w3c.dom.Attr;
@ -484,13 +483,10 @@ public class AbstractWordUtils
public static HWPFDocumentCore loadDoc( File docFile ) throws IOException
{
final FileInputStream istream = new FileInputStream( docFile );
try
{
try {
return loadDoc( istream );
}
finally
{
IOUtils.closeQuietly( istream );
} finally {
istream.close();
}
}

View File

@ -16,8 +16,11 @@
==================================================================== */
package org.apache.poi.ss.formula.eval;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
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.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.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
import junit.framework.AssertionFailedError;
/**
* Common superclass for testing cases of circular references
* both for HSSF and XSSF
*/
public abstract class BaseTestCircularReferences extends TestCase {
public abstract class BaseTestCircularReferences {
protected final ITestDataProvider _testDataProvider;
@ -68,8 +74,8 @@ public abstract class BaseTestCircularReferences extends TestCase {
* ASF Bugzilla Bug 44413
* "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();
Sheet sheet = wb.createSheet("Sheet1");
@ -91,13 +97,14 @@ public abstract class BaseTestCircularReferences extends TestCase {
assertTrue(cellValue.getCellType() == Cell.CELL_TYPE_NUMERIC);
assertEquals(2, cellValue.getNumberValue(), 0);
wb.close();
}
/**
* Cell A1 has formula "=A1"
*/
public void testSimpleCircularReference() {
@Test
public void testSimpleCircularReference() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
@ -108,13 +115,15 @@ public abstract class BaseTestCircularReferences extends TestCase {
CellValue cellValue = evaluateWithCycles(wb, testCell);
confirmCycleErrorCode(cellValue);
wb.close();
}
/**
* A1=B1, B1=C1, C1=D1, D1=A1
*/
public void testMultiLevelCircularReference() {
@Test
public void testMultiLevelCircularReference() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
@ -128,9 +137,12 @@ public abstract class BaseTestCircularReferences extends TestCase {
CellValue cellValue = evaluateWithCycles(wb, testCell);
confirmCycleErrorCode(cellValue);
wb.close();
}
public void testIntermediateCircularReferenceResults_bug46898() {
@Test
public void testIntermediateCircularReferenceResults_bug46898() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
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
fe.clearAllCachedResultValues();
cv = fe.evaluate(cellB1);
if (cv.getCellType() == ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()) {
throw new AssertionFailedError("Identified bug 46898");
}
// Identified bug 46898
assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode());
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
assertEquals(46.0, cv.getNumberValue(), 0.0);
@ -173,5 +184,7 @@ public abstract class BaseTestCircularReferences extends TestCase {
cv = fe.evaluate(cellE1);
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
assertEquals(43.0, cv.getNumberValue(), 0.0);
wb.close();
}
}

View File

@ -50,8 +50,9 @@ public final class TestText {
ValueEval formatArg = new StringEval("#,###.00000");
ValueEval[] args = { numArg, formatArg };
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
char groupSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getGroupingSeparator();
char decimalSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getDecimalSeparator();
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale());
char groupSeparator = dfs.getGroupingSeparator();
char decimalSeparator = dfs.getDecimalSeparator();
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
assertEquals(testResult.toString(), result.toString());
numArg = new NumberEval(321.321);

View File

@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
@ -41,13 +42,13 @@ public abstract class BaseTestHyperlink {
}
@Test
public final void testBasicTypes(){
Workbook wb = _testDataProvider.createWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
public final void testBasicTypes() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook();
CreationHelper createHelper = wb1.getCreationHelper();
Cell cell;
Hyperlink link;
Sheet sheet = wb.createSheet("Hyperlinks");
Sheet sheet = wb1.createSheet("Hyperlinks");
//URL
cell = sheet.createRow(0).createCell((short) 0);
@ -74,7 +75,7 @@ public abstract class BaseTestHyperlink {
//link to a place in this workbook
//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");
cell = sheet.createRow(3).createCell((short) 0);
@ -83,9 +84,10 @@ public abstract class BaseTestHyperlink {
link.setAddress("'Target Sheet'!A1");
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();
assertEquals("http://poi.apache.org/", link.getAddress());
@ -95,11 +97,13 @@ public abstract class BaseTestHyperlink {
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
link = sheet.getRow(3).getCell(0).getHyperlink();
assertEquals("'Target Sheet'!A1", link.getAddress());
wb2.close();
}
// copy a hyperlink via the copy constructor
@Test
public void testCopyHyperlink() {
public void testCopyHyperlink() throws IOException {
final Workbook wb = _testDataProvider.createWorkbook();
final CreationHelper createHelper = wb.getCreationHelper();
@ -136,6 +140,8 @@ public abstract class BaseTestHyperlink {
assertEquals(2, actualHyperlinks.size());
assertEquals(link1, actualHyperlinks.get(0));
assertEquals(link2, actualHyperlinks.get(1));
wb.close();
}
public abstract Hyperlink copyHyperlink(Hyperlink link);