FileOutputStream out = new FileOutputStream("apachecon_eu_08."+ext);
ppt.write(out);
out.close();
-
+ ppt.close();
}
public static void slide1(SlideShow<?,?> ppt) throws IOException {
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.
*
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
+
+ wb.close();
}
/**
FileOutputStream fileOut = new FileOutputStream("ss-example-align.xlsx");\r
wb.write(fileOut);\r
fileOut.close();\r
+ wb.close();\r
}\r
\r
/**\r
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;
/**
FileOutputStream fileOut = new FileOutputStream("xssf-align.xlsx");
wb.write(fileOut);
fileOut.close();
+
+ wb.close();
}
/**
}
}
+ @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(){
# Disallow reflection on private object fields/methods\r
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\r
java.lang.reflect.AccessibleObject#setAccessible(boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9\r
+\r
+java.text.DecimalFormatSymbols#DecimalFormatSymbols() @ use DecimalFormatSymbols.getInstance()\r
+java.text.DecimalFormatSymbols#DecimalFormatSymbols(Locale) @ use DecimalFormatSymbols.getInstance()\r
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;
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();
}
}
==================================================================== */
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;
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;
* 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");
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");
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");
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");
// 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);
cv = fe.evaluate(cellE1);
assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
assertEquals(43.0, cv.getNumberValue(), 0.0);
+
+ wb.close();
}
}
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);
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
+import java.io.IOException;
import java.util.List;
import org.junit.Test;
}
@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);
//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);
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());
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();
assertEquals(2, actualHyperlinks.size());
assertEquals(link1, actualHyperlinks.get(0));
assertEquals(link2, actualHyperlinks.get(1));
+
+ wb.close();
}
public abstract Hyperlink copyHyperlink(Hyperlink link);