Eclipse warnings, close resources in CommandLineTextExtractor, add try/finally, formatting, ...
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de46578051
commit
b2bd6a0a4c
@ -27,11 +27,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
import org.apache.poi.POIOLE2TextExtractor;
|
||||
import org.apache.poi.POITextExtractor;
|
||||
import org.apache.poi.dev.OOXMLPrettyPrint;
|
||||
import org.apache.poi.extractor.ExtractorFactory;
|
||||
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
|
@ -42,14 +42,18 @@ public class CommandLineTextExtractor {
|
||||
|
||||
POITextExtractor extractor =
|
||||
ExtractorFactory.createExtractor(f);
|
||||
POITextExtractor metadataExtractor =
|
||||
extractor.getMetadataTextExtractor();
|
||||
|
||||
System.out.println(" " + DIVIDER);
|
||||
System.out.println(metadataExtractor.getText());
|
||||
System.out.println(" " + DIVIDER);
|
||||
System.out.println(extractor.getText());
|
||||
System.out.println(DIVIDER);
|
||||
try {
|
||||
POITextExtractor metadataExtractor =
|
||||
extractor.getMetadataTextExtractor();
|
||||
|
||||
System.out.println(" " + DIVIDER);
|
||||
System.out.println(metadataExtractor.getText());
|
||||
System.out.println(" " + DIVIDER);
|
||||
System.out.println(extractor.getText());
|
||||
System.out.println(DIVIDER);
|
||||
} finally {
|
||||
extractor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ import org.apache.poi.util.TempFile;
|
||||
/**
|
||||
* Physical zip package.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class ZipPackage extends Package {
|
||||
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
|
||||
|
||||
@ -62,7 +63,6 @@ public final class ZipPackage extends Package {
|
||||
/**
|
||||
* Constructor. Creates a new, empty ZipPackage.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public ZipPackage() {
|
||||
super(defaultPackageAccess);
|
||||
this.zipArchive = null;
|
||||
@ -84,7 +84,6 @@ public final class ZipPackage extends Package {
|
||||
* If the specified input stream not an instance of
|
||||
* ZipInputStream.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
ZipPackage(InputStream in, PackageAccess access) throws IOException {
|
||||
super(access);
|
||||
InputStream zis = new ZipInputStream(in);
|
||||
@ -102,7 +101,6 @@ public final class ZipPackage extends Package {
|
||||
* @throws InvalidFormatException
|
||||
* If the content type part parsing encounters an error.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
ZipPackage(String path, PackageAccess access) {
|
||||
super(access);
|
||||
|
||||
@ -128,7 +126,6 @@ public final class ZipPackage extends Package {
|
||||
* @throws InvalidFormatException
|
||||
* If the content type part parsing encounters an error.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
ZipPackage(File file, PackageAccess access) {
|
||||
super(access);
|
||||
|
||||
@ -156,7 +153,6 @@ public final class ZipPackage extends Package {
|
||||
* @throws InvalidFormatException
|
||||
* If the content type part parsing encounters an error.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
|
||||
super(access);
|
||||
this.zipArchive = zipEntry;
|
||||
|
@ -917,8 +917,8 @@ public class XSSFCellStyle implements CellStyle {
|
||||
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
|
||||
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
|
||||
*/
|
||||
@Override
|
||||
public void setBorderRight(short border) {
|
||||
@Override
|
||||
public void setBorderRight(short border) {
|
||||
CTBorder ct = getCTBorder();
|
||||
CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
|
||||
if(border == BORDER_NONE) ct.unsetRight();
|
||||
|
@ -18,6 +18,8 @@ package org.apache.poi.xslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.sl.usermodel.*;
|
||||
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
||||
import org.apache.poi.sl.usermodel.TextShape.TextAutofit;
|
||||
@ -32,7 +34,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
||||
*/
|
||||
public class TestXSLFAutoShape {
|
||||
@Test
|
||||
public void testTextBodyProperies() {
|
||||
public void testTextBodyProperies() throws IOException {
|
||||
XMLSlideShow ppt = new XMLSlideShow();
|
||||
XSLFSlide slide = ppt.createSlide();
|
||||
|
||||
@ -102,10 +104,12 @@ public class TestXSLFAutoShape {
|
||||
assertEquals(TextDirection.VERTICAL, shape.getTextDirection());
|
||||
shape.setTextDirection(null);
|
||||
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextParagraph() {
|
||||
public void testTextParagraph() throws IOException {
|
||||
XMLSlideShow ppt = new XMLSlideShow();
|
||||
XSLFSlide slide = ppt.createSlide();
|
||||
assertTrue(slide.getShapes().isEmpty());
|
||||
@ -202,10 +206,12 @@ public class TestXSLFAutoShape {
|
||||
p.setTextAlign(null);
|
||||
assertEquals(TextAlign.LEFT, p.getTextAlign());
|
||||
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextRun() {
|
||||
public void testTextRun() throws IOException {
|
||||
XMLSlideShow ppt = new XMLSlideShow();
|
||||
XSLFSlide slide = ppt.createSlide();
|
||||
|
||||
@ -272,10 +278,12 @@ public class TestXSLFAutoShape {
|
||||
assertEquals("POI", r.getRawText());
|
||||
r.setText(null);
|
||||
assertNull(r.getRawText());
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShapeType() {
|
||||
public void testShapeType() throws IOException {
|
||||
XMLSlideShow ppt = new XMLSlideShow();
|
||||
XSLFSlide slide = ppt.createSlide();
|
||||
|
||||
@ -290,5 +298,7 @@ public class TestXSLFAutoShape {
|
||||
shape.setShapeType(tp);
|
||||
assertEquals(tp, shape.getShapeType());
|
||||
}
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
}
|
@ -2381,9 +2381,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||
|
||||
// using temp file instead of ByteArrayOutputStream because of OOM in gump run
|
||||
File tmp = TempFile.createTempFile("poi-test", ".bug57880");
|
||||
FileOutputStream fos = new FileOutputStream(tmp);
|
||||
wb.write(fos);
|
||||
fos.close();
|
||||
OutputStream fos = new FileOutputStream(tmp);
|
||||
try {
|
||||
wb.write(fos);
|
||||
} finally {
|
||||
fos.close();
|
||||
}
|
||||
|
||||
wb.close();
|
||||
fmt = null; /*s = null;*/ wb = null;
|
||||
|
@ -139,5 +139,7 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
|
||||
|
||||
// Print not PrintLn as already has \n added to it
|
||||
System.out.print(extractor.getText());
|
||||
|
||||
extractor.close();
|
||||
}
|
||||
}
|
||||
|
@ -228,6 +228,7 @@ public final class TestHSSFDataFormatter extends TestCase {
|
||||
row = wb.getSheetAt(0).getRow(1);
|
||||
it = row.cellIterator();
|
||||
log("==== VALID TIME FORMATS ====");
|
||||
|
||||
while (it.hasNext()) {
|
||||
Cell cell = it.next();
|
||||
String fmt = cell.getCellStyle().getDataFormatString();
|
||||
@ -239,7 +240,8 @@ public final class TestHSSFDataFormatter extends TestCase {
|
||||
assertTrue( ! "555.47431".equals(fmtval));
|
||||
|
||||
// check we found the time properly
|
||||
assertTrue("Format came out incorrect - " + fmt, fmtval.indexOf("11:23") > -1);
|
||||
assertTrue("Format came out incorrect - " + fmt + ": " + fmtval + ", but expected to find '11:23'",
|
||||
fmtval.indexOf("11:23") > -1);
|
||||
}
|
||||
|
||||
// test number formats
|
||||
@ -409,8 +411,8 @@ public final class TestHSSFDataFormatter extends TestCase {
|
||||
}
|
||||
|
||||
private static void log(String msg) {
|
||||
if (false) { // successful tests should be silent
|
||||
System.out.println(msg);
|
||||
}
|
||||
// if (false) { // successful tests should be silent
|
||||
// System.out.println(msg);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user