Eclipse warnings, code formatting, javadoc, ...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1717972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-12-04 14:38:14 +00:00
parent 4aa6108c0d
commit 387fb86d68
5 changed files with 48 additions and 33 deletions

View File

@ -26,11 +26,11 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor; import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch; import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
@ -721,7 +721,6 @@ public class AddDimensionedImage {
String imageFile = null; String imageFile = null;
String outputFile = null; String outputFile = null;
FileOutputStream fos = null; FileOutputStream fos = null;
HSSFWorkbook workbook = null;
HSSFSheet sheet = null; HSSFSheet sheet = null;
try { try {
if(args.length < 2){ if(args.length < 2){
@ -731,13 +730,14 @@ public class AddDimensionedImage {
imageFile = args[0]; imageFile = args[0];
outputFile = args[1]; outputFile = args[1];
workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
sheet = workbook.createSheet("Picture Test"); sheet = workbook.createSheet("Picture Test");
new AddDimensionedImage().addImageToSheet("A1", sheet, new AddDimensionedImage().addImageToSheet("A1", sheet,
imageFile, 125, 125, imageFile, 125, 125,
AddDimensionedImage.EXPAND_ROW_AND_COLUMN); AddDimensionedImage.EXPAND_ROW_AND_COLUMN);
fos = new FileOutputStream(outputFile); fos = new FileOutputStream(outputFile);
workbook.write(fos); workbook.write(fos);
workbook.close();
} }
catch(FileNotFoundException fnfEx) { catch(FileNotFoundException fnfEx) {
System.out.println("Caught an: " + fnfEx.getClass().getName()); System.out.println("Caught an: " + fnfEx.getClass().getName());
@ -752,13 +752,6 @@ public class AddDimensionedImage {
ioEx.printStackTrace(System.out); ioEx.printStackTrace(System.out);
} }
finally { finally {
try {
if (workbook != null) {
workbook.close();
}
} catch(IOException ioEx) {
// I G N O R E
}
try { try {
if(fos != null) { if(fos != null) {
fos.close(); fos.close();

View File

@ -38,6 +38,7 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.SXSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.After; import org.junit.After;
@ -85,12 +86,10 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
public void existingWorkbook() throws IOException { public void existingWorkbook() throws IOException {
XSSFWorkbook xssfWb1 = new XSSFWorkbook(); XSSFWorkbook xssfWb1 = new XSSFWorkbook();
xssfWb1.createSheet("S1"); xssfWb1.createSheet("S1");
@SuppressWarnings("resource")
SXSSFWorkbook wb1 = new SXSSFWorkbook(xssfWb1); SXSSFWorkbook wb1 = new SXSSFWorkbook(xssfWb1);
XSSFWorkbook xssfWb2 = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1); XSSFWorkbook xssfWb2 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
assertTrue(wb1.dispose()); assertTrue(wb1.dispose());
@SuppressWarnings("resource")
SXSSFWorkbook wb2 = new SXSSFWorkbook(xssfWb2); SXSSFWorkbook wb2 = new SXSSFWorkbook(xssfWb2);
assertEquals(1, wb2.getNumberOfSheets()); assertEquals(1, wb2.getNumberOfSheets());
Sheet sheet = wb2.getSheetAt(0); Sheet sheet = wb2.getSheetAt(0);
@ -99,11 +98,12 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
assertTrue(wb2.dispose()); assertTrue(wb2.dispose());
xssfWb2.close(); xssfWb2.close();
xssfWb1.close(); xssfWb1.close();
wb2.close();
} }
@Test @Test
public void useSharedStringsTable() throws Exception { public void useSharedStringsTable() throws Exception {
@SuppressWarnings("resource")
SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, false, true); SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, false, true);
SharedStringsTable sss = POITestCase.getFieldValue(SXSSFWorkbook.class, wb, SharedStringsTable.class, "_sharedStringSource"); SharedStringsTable sss = POITestCase.getFieldValue(SXSSFWorkbook.class, wb, SharedStringsTable.class, "_sharedStringSource");
@ -116,7 +116,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
row.createCell(1).setCellValue("B"); row.createCell(1).setCellValue("B");
row.createCell(2).setCellValue("A"); row.createCell(2).setCellValue("A");
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb); XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
sss = POITestCase.getFieldValue(SXSSFWorkbook.class, wb, SharedStringsTable.class, "_sharedStringSource"); sss = POITestCase.getFieldValue(SXSSFWorkbook.class, wb, SharedStringsTable.class, "_sharedStringSource");
assertEquals(2, sss.getUniqueCount()); assertEquals(2, sss.getUniqueCount());
assertTrue(wb.dispose()); assertTrue(wb.dispose());
@ -147,9 +147,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
Row row = sheet.createRow(1); Row row = sheet.createRow(1);
Cell cell = row.createCell(1); Cell cell = row.createCell(1);
cell.setCellValue("value 2_1_1"); cell.setCellValue("value 2_1_1");
@SuppressWarnings("resource")
SXSSFWorkbook wb1 = new SXSSFWorkbook(xssfWb1); SXSSFWorkbook wb1 = new SXSSFWorkbook(xssfWb1);
XSSFWorkbook xssfWb2 = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1); XSSFWorkbook xssfWb2 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
assertTrue(wb1.dispose()); assertTrue(wb1.dispose());
xssfWb1.close(); xssfWb1.close();
@ -172,7 +171,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
Cell cell3_1_1 = row3_1.createCell(1); Cell cell3_1_1 = row3_1.createCell(1);
cell3_1_1.setCellValue("value 3_1_1"); cell3_1_1.setCellValue("value 3_1_1");
XSSFWorkbook xssfWb3 = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb2); XSSFWorkbook xssfWb3 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb2);
wb2.close(); wb2.close();
assertEquals(3, xssfWb3.getNumberOfSheets()); assertEquals(3, xssfWb3.getNumberOfSheets());
@ -239,7 +238,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
//Test escaping of Unicode control characters //Test escaping of Unicode control characters
wb = new SXSSFWorkbook(); wb = new SXSSFWorkbook();
wb.createSheet("S1").createRow(0).createCell(0).setCellValue("value\u0019"); wb.createSheet("S1").createRow(0).createCell(0).setCellValue("value\u0019");
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb); XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
Cell cell = xssfWorkbook.getSheet("S1").getRow(0).getCell(0); Cell cell = xssfWorkbook.getSheet("S1").getRow(0).getCell(0);
assertEquals("value?", cell.getStringCellValue()); assertEquals("value?", cell.getStringCellValue());
@ -250,7 +249,6 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
@Test @Test
public void gzipSheetdataWriter() throws IOException { public void gzipSheetdataWriter() throws IOException {
@SuppressWarnings("resource")
SXSSFWorkbook wb = new SXSSFWorkbook(); SXSSFWorkbook wb = new SXSSFWorkbook();
wb.setCompressTempFiles(true); wb.setCompressTempFiles(true);
int rowNum = 1000; int rowNum = 1000;
@ -270,7 +268,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
} }
} }
XSSFWorkbook xwb = (XSSFWorkbook)SXSSFITestDataProvider.instance.writeOutAndReadBack(wb); XSSFWorkbook xwb = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
for(int i = 0; i < sheetNum; i++){ for(int i = 0; i < sheetNum; i++){
Sheet sh = xwb.getSheetAt(i); Sheet sh = xwb.getSheetAt(i);
assertEquals("sheet" + i, sh.getSheetName()); assertEquals("sheet" + i, sh.getSheetName());
@ -322,7 +320,6 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
} }
} }
@SuppressWarnings("resource")
@Test @Test
public void workbookDispose() public void workbookDispose()
{ {
@ -337,8 +334,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
} }
// currently writing the same sheet multiple times is not supported... @Ignore("currently writing the same sheet multiple times is not supported...")
@Ignore @Test
public void bug53515() throws Exception { public void bug53515() throws Exception {
Workbook wb1 = new SXSSFWorkbook(10); Workbook wb1 = new SXSSFWorkbook(10);
populateWorkbook(wb1); populateWorkbook(wb1);
@ -350,10 +347,9 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
wb1.close(); wb1.close();
} }
// Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files @Ignore("Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files, "
// See http://www.oracle.com/technetwork/java/javase/documentation/overview-156328.html + "see http://www.oracle.com/technetwork/java/javase/documentation/overview-156328.html")
@SuppressWarnings("resource") @Test
@Ignore
public void bug53515a() throws Exception { public void bug53515a() throws Exception {
File out = new File("Test.xlsx"); File out = new File("Test.xlsx");
out.delete(); out.delete();
@ -412,4 +408,31 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
} }
} }
} }
@Ignore("Just a local test for http://stackoverflow.com/questions/33627329/apache-poi-streaming-api-using-xssf-template")
@Test
public void testTemplateFile() throws IOException {
XSSFWorkbook workBook = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
SXSSFWorkbook streamingWorkBook = new SXSSFWorkbook(workBook,10);
Sheet sheet = streamingWorkBook.getSheet("Sheet1");
for(int rowNum = 10;rowNum < 1000000;rowNum++) {
Row row = sheet.createRow(rowNum);
for(int cellNum = 0;cellNum < 700;cellNum++) {
Cell cell = row.createCell(cellNum);
cell.setCellValue("somevalue");
}
if(rowNum % 100 == 0) {
System.out.print(".");
if(rowNum % 10000 == 0) {
System.out.println(rowNum);
}
}
}
streamingWorkBook.write(new FileOutputStream("C:\\temp\\streaming.xlsx"));
streamingWorkBook.close();
workBook.close();
}
} }

View File

@ -2130,7 +2130,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* in read-only mode * in read-only mode
* @throws InvalidFormatException * @throws InvalidFormatException
*/ */
@SuppressWarnings("resource")
@Test @Test
public void bug57482() throws IOException, InvalidFormatException { public void bug57482() throws IOException, InvalidFormatException {
for (PackageAccess access : new PackageAccess[] { for (PackageAccess access : new PackageAccess[] {

View File

@ -177,8 +177,8 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compar
return false; return false;
} }
public T clone() @SuppressWarnings("unchecked")
throws CloneNotSupportedException public T clone() throws CloneNotSupportedException
{ {
return (T) super.clone(); return (T) super.clone();
} }

View File

@ -60,8 +60,8 @@ public final class TestReWriteSanity extends TestCase {
// Find the location of the PersistPtrIncrementalBlocks and // Find the location of the PersistPtrIncrementalBlocks and
// UserEditAtoms // UserEditAtoms
Record[] r = wss.getRecords(); Record[] r = wss.getRecords();
Hashtable pp = new Hashtable(); Map<Integer,Record> pp = new Hashtable<Integer,Record>();
Hashtable ue = new Hashtable(); Map<Integer,Object> ue = new Hashtable<Integer,Object>();
ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first
int pos = 0; int pos = 0;
int lastUEPos = -1; int lastUEPos = -1;