import java.io.InputStream;\r
import java.util.HashSet;\r
import java.util.Set;\r
-import java.util.zip.ZipException;\r
\r
import org.apache.poi.POIOLE2TextExtractor;\r
import org.apache.poi.POITextExtractor;\r
-import org.apache.poi.dev.OOXMLPrettyPrint;\r
import org.apache.poi.extractor.ExtractorFactory;\r
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;\r
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
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();
+ }
}
}
}
/**
* Physical zip package.
*/
+@SuppressWarnings("deprecation")
public final class ZipPackage extends Package {
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
/**
* Constructor. Creates a new, empty ZipPackage.
*/
- @SuppressWarnings("deprecation")
public ZipPackage() {
super(defaultPackageAccess);
this.zipArchive = null;
* 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);
* @throws InvalidFormatException
* If the content type part parsing encounters an error.
*/
- @SuppressWarnings("deprecation")
ZipPackage(String path, PackageAccess access) {
super(access);
* @throws InvalidFormatException
* If the content type part parsing encounters an error.
*/
- @SuppressWarnings("deprecation")
ZipPackage(File file, PackageAccess access) {
super(access);
* @throws InvalidFormatException
* If the content type part parsing encounters an error.
*/
- @SuppressWarnings("deprecation")
ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
super(access);
this.zipArchive = zipEntry;
* @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();
\r
import static org.junit.Assert.*;\r
\r
+import java.io.IOException;\r
+\r
import org.apache.poi.sl.usermodel.*;\r
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;\r
import org.apache.poi.sl.usermodel.TextShape.TextAutofit;\r
*/\r
public class TestXSLFAutoShape {\r
@Test\r
- public void testTextBodyProperies() {\r
+ public void testTextBodyProperies() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
\r
assertEquals(TextDirection.VERTICAL, shape.getTextDirection());\r
shape.setTextDirection(null);\r
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());\r
+ \r
+ ppt.close();\r
}\r
\r
@Test\r
- public void testTextParagraph() {\r
+ public void testTextParagraph() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
assertTrue(slide.getShapes().isEmpty());\r
p.setTextAlign(null);\r
assertEquals(TextAlign.LEFT, p.getTextAlign());\r
assertFalse(p.getXmlObject().getPPr().isSetAlgn());\r
+ \r
+ ppt.close();\r
}\r
\r
@Test\r
- public void testTextRun() {\r
+ public void testTextRun() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
\r
assertEquals("POI", r.getRawText());\r
r.setText(null);\r
assertNull(r.getRawText());\r
+ \r
+ ppt.close();\r
}\r
\r
@Test\r
- public void testShapeType() {\r
+ public void testShapeType() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
\r
shape.setShapeType(tp);\r
assertEquals(tp, shape.getShapeType());\r
}\r
+ \r
+ ppt.close();\r
}\r
}
\ No newline at end of file
// 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;
// Print not PrintLn as already has \n added to it
System.out.print(extractor.getText());
+
+ extractor.close();
}
}
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();
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
}
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);
+// }
}
}