Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java Fri Aug 31 00:25:50 2018 @@ -35,7 +35,6 @@ import org.apache.commons.compress.archi import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.junit.Assume; @@ -134,7 +133,7 @@ public class TestDecryptor { // the fix limits the available size and tries to read all entries File f = samples.getFile("extenxls_pwd123.xlsx"); - try (NPOIFSFileSystem fs = new NPOIFSFileSystem(f, true)) { + try (POIFSFileSystem fs = new POIFSFileSystem(f, true)) { EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.getInstance(info); d.verifyPassword("pwd123");
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java Fri Aug 31 00:25:50 2018 @@ -37,7 +37,6 @@ import org.apache.poi.poifs.filesystem.D import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentNode; import org.apache.poi.poifs.filesystem.Entry; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; @@ -102,7 +101,7 @@ public class TestEncryptor { final EncryptionInfo infoExpected; final Decryptor decExpected; - try (NPOIFSFileSystem nfs = new NPOIFSFileSystem(file, true)) { + try (POIFSFileSystem nfs = new POIFSFileSystem(file, true)) { // Check the encryption details infoExpected = new EncryptionInfo(nfs); @@ -159,7 +158,7 @@ public class TestEncryptor { final EncryptionInfo infoActual2; final byte[] payloadActual, encPackActual; final long decPackLenActual; - try (NPOIFSFileSystem nfs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()))) { + try (POIFSFileSystem nfs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()))) { infoActual2 = new EncryptionInfo(nfs.getRoot()); Decryptor decActual = Decryptor.getInstance(infoActual2); boolean passed = decActual.verifyPassword(pass); @@ -196,7 +195,7 @@ public class TestEncryptor { final byte[] payloadExpected; final EncryptionInfo infoExpected; final Decryptor d; - try (NPOIFSFileSystem nfs = new NPOIFSFileSystem(file, true)) { + try (POIFSFileSystem nfs = new POIFSFileSystem(file, true)) { // Check the encryption details infoExpected = new EncryptionInfo(nfs); @@ -260,7 +259,7 @@ public class TestEncryptor { } final byte[] payloadActual; - try (NPOIFSFileSystem nfs = new NPOIFSFileSystem(new ByteArrayInputStream(encBytes))) { + try (POIFSFileSystem nfs = new POIFSFileSystem(new ByteArrayInputStream(encBytes))) { final EncryptionInfo ei = new EncryptionInfo(nfs); Decryptor d2 = Decryptor.getInstance(ei); assertTrue("Unable to process: document is encrypted", d2.verifyPassword(pass)); @@ -297,7 +296,7 @@ public class TestEncryptor { Encryptor enc = info.getEncryptor(); enc.confirmPassword("password"); - try (NPOIFSFileSystem fs = new NPOIFSFileSystem()) { + try (POIFSFileSystem fs = new POIFSFileSystem()) { try (OutputStream os = enc.getDataStream(fs)) { pkg.save(os); @@ -311,11 +310,11 @@ public class TestEncryptor { } - try (NPOIFSFileSystem inpFS = new NPOIFSFileSystem(new ByteArrayInputStream(encBytes))) { + try (POIFSFileSystem inpFS = new POIFSFileSystem(new ByteArrayInputStream(encBytes))) { // Check we can decrypt it EncryptionInfo info = new EncryptionInfo(inpFS); Decryptor d = Decryptor.getInstance(info); - assertEquals(true, d.verifyPassword("password")); + assertTrue(d.verifyPassword("password")); try (OPCPackage inpPkg = OPCPackage.open(d.getDataStream(inpFS))) { // Check it now has empty core properties @@ -338,7 +337,7 @@ public class TestEncryptor { IOUtils.copy(fis, fos); } - try (NPOIFSFileSystem fs = new NPOIFSFileSystem(f, false)) { + try (POIFSFileSystem fs = new POIFSFileSystem(f, false)) { // decrypt the protected file - in this case it was encrypted with the default password EncryptionInfo encInfo = new EncryptionInfo(fs); @@ -480,7 +479,7 @@ public class TestEncryptor { final byte[] epNewBytes; final EncryptionInfo infoReload; - try (NPOIFSFileSystem fsNew = new NPOIFSFileSystem()) { + try (POIFSFileSystem fsNew = new POIFSFileSystem()) { try (OutputStream os = enc.getDataStream(fsNew)) { os.write(zipInput); } @@ -488,7 +487,7 @@ public class TestEncryptor { ByteArrayOutputStream bos = new ByteArrayOutputStream(); fsNew.writeFilesystem(bos); - try (NPOIFSFileSystem fsReload = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()))) { + try (POIFSFileSystem fsReload = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()))) { infoReload = new EncryptionInfo(fsReload); try (InputStream epReload = fsReload.getRoot().createDocumentInputStream("EncryptedPackage")) { epNewBytes = IOUtils.toByteArray(epReload, 9400); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java Fri Aug 31 00:25:50 2018 @@ -28,7 +28,7 @@ import org.apache.poi.POIDataSamples; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.crypt.EncryptionMode; import org.apache.poi.poifs.crypt.Encryptor; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.usermodel.BaseTestSlideShowFactory; import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; @@ -93,27 +93,20 @@ public final class TestXSLFSlideShowFact } private static File createProtected() throws IOException, GeneralSecurityException { - return createProtected(filename, password); - } - - private static File createProtected(String basefile, String password) - throws IOException, GeneralSecurityException { - NPOIFSFileSystem fs = new NPOIFSFileSystem(); - EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); - Encryptor enc = info.getEncryptor(); - enc.confirmPassword(password); - InputStream fis = _slTests.openResourceAsStream(basefile); - OutputStream os = enc.getDataStream(fs); - IOUtils.copy(fis, os); - os.close(); - fis.close(); - - File tf = TempFile.createTempFile("test-xslf-slidefactory", ".pptx"); - FileOutputStream fos = new FileOutputStream(tf); - fs.writeFilesystem(fos); - fos.close(); - fs.close(); - - return tf; + try (POIFSFileSystem fs = new POIFSFileSystem()) { + EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); + Encryptor enc = info.getEncryptor(); + enc.confirmPassword(password); + try (InputStream fis = _slTests.openResourceAsStream(filename); + OutputStream os = enc.getDataStream(fs)) { + IOUtils.copy(fis, os); + } + + File tf = TempFile.createTempFile("test-xslf-slidefactory", ".pptx"); + try (FileOutputStream fos = new FileOutputStream(tf)) { + fs.writeFilesystem(fos); + } + return tf; + } } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Fri Aug 31 00:25:50 2018 @@ -67,7 +67,6 @@ import org.apache.poi.openxml4j.opc.Pack import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.util.ZipSecureFile; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.SpreadsheetVersion; @@ -1004,10 +1003,10 @@ public final class TestXSSFBugs extends // Add some more tables, and check - t = s2.createTable(); + t = s2.createTable(null); t.setName("New 2"); t.setDisplayName("New 2"); - t = s3.createTable(); + t = s3.createTable(null); t.setName("New 3"); t.setDisplayName("New 3"); @@ -1478,7 +1477,7 @@ public final class TestXSSFBugs extends } @Test - public void bug55692_stream() throws IOException, InvalidFormatException { + public void bug55692_stream() throws IOException { // Directly on a Stream, will go via NPOIFS and spot it's // actually a .xlsx file encrypted with the default password, and open Workbook wb = WorkbookFactory.create( @@ -1492,7 +1491,7 @@ public final class TestXSSFBugs extends public void bug55692_npoifs() throws IOException { // Via a NPOIFSFileSystem, will spot it's actually a .xlsx file // encrypted with the default password, and open - NPOIFSFileSystem fsNP = new NPOIFSFileSystem( + POIFSFileSystem fsNP = new POIFSFileSystem( POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx")); Workbook wb = WorkbookFactory.create(fsNP); assertNotNull(wb); @@ -1972,7 +1971,7 @@ public final class TestXSSFBugs extends * error message if given one */ @Test - public void bug56800_xlsb() throws IOException, InvalidFormatException { + public void bug56800_xlsb() throws IOException { // Can be opened at the OPC level OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("Simple.xlsb"); @@ -2519,7 +2518,7 @@ public final class TestXSSFBugs extends } private void runTest56574(boolean createRow) throws IOException { - Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56574.xlsx"); + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56574.xlsx"); Sheet sheet = wb.getSheet("Func"); assertNotNull(sheet); @@ -2562,17 +2561,17 @@ public final class TestXSSFBugs extends } } - XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) wb); + XSSFFormulaEvaluator.evaluateAllFormulaCells(wb); wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); - CalculationChain chain = ((XSSFWorkbook) wb).getCalculationChain(); + CalculationChain chain = wb.getCalculationChain(); checkCellsAreGone(chain); - Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); + XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); Sheet sheetBack = wbBack.getSheet("Func"); assertNotNull(sheetBack); - chain = ((XSSFWorkbook) wbBack).getCalculationChain(); + chain = wbBack.getCalculationChain(); checkCellsAreGone(chain); wbBack.close(); @@ -2653,7 +2652,7 @@ public final class TestXSSFBugs extends } @Test - public void test51626() throws IOException, InvalidFormatException { + public void test51626() throws IOException { Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51626.xlsx"); assertNotNull(wb); wb.close(); @@ -3204,7 +3203,7 @@ public final class TestXSSFBugs extends final String initialFormula = "A1"; final String expectedFormula = "#REF!"; // from ms excel - Workbook wb = new XSSFWorkbook(); + XSSFWorkbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("sheet1"); sheet.createRow(0).createCell(0).setCellValue(1); // A1 = 1 @@ -3219,7 +3218,7 @@ public final class TestXSSFBugs extends { FormulaShifter formulaShifter = FormulaShifter.createForRowCopy(0, "sheet1", 2/*firstRowToShift*/, 2/*lastRowToShift*/ , -1/*step*/, SpreadsheetVersion.EXCEL2007); // parameters 2, 2, -1 should mean : move row range [2-2] one level up - XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb); + XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); Ptg[] ptgs = FormulaParser.parse(initialFormula, fpb, FormulaType.CELL, 0); // [A1] formulaShifter.adjustFormula(ptgs, 0); // adjusted to [A] String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs); //A @@ -3231,7 +3230,7 @@ public final class TestXSSFBugs extends { FormulaShifter formulaShifter = FormulaShifter.createForRowShift(0, "sheet1", 2/*firstRowToShift*/, 2/*lastRowToShift*/ , -1/*step*/, SpreadsheetVersion.EXCEL2007); // parameters 2, 2, -1 should mean : move row range [2-2] one level up - XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb); + XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); Ptg[] ptgs = FormulaParser.parse(initialFormula, fpb, FormulaType.CELL, 0); // [A1] formulaShifter.adjustFormula(ptgs, 0); // adjusted to [A] String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs); //A @@ -3276,18 +3275,18 @@ public final class TestXSSFBugs extends XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); - XSSFTable table1 = sheet.createTable(); - XSSFTable table2 = sheet.createTable(); - XSSFTable table3 = sheet.createTable(); + XSSFTable table1 = sheet.createTable(null); + XSSFTable table2 = sheet.createTable(null); + XSSFTable table3 = sheet.createTable(null); sheet.removeTable(table1); - sheet.createTable(); + sheet.createTable(null); sheet.removeTable(table2); sheet.removeTable(table3); - sheet.createTable(); + sheet.createTable(null); wb.close(); } @@ -3295,7 +3294,6 @@ public final class TestXSSFBugs extends /** * Auto column sizing failed when there were loads of fonts with * errors like ArrayIndexOutOfBoundsException: -32765 - * TODO Get this to actually reproduce the bug... */ @Test public void test62108() { @@ -3309,6 +3307,7 @@ public final class TestXSSFBugs extends for (int i=0; i<fonts.length; i++) { XSSFFont font = wb.createFont(); font.setFontHeight(i); + fonts[i] = font; } // Create a moderate number of columns, which use @@ -3356,7 +3355,5 @@ public final class TestXSSFBugs extends sheet = wbBack.getSheetAt(0); assertEquals("E11", sheet.getActiveCell().formatAsString()); wbBack.close(); - - //wb.write(new FileOutputStream("c:/temp/61905." + instance.getStandardFileNameExtension())); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java Fri Aug 31 00:25:50 2018 @@ -34,7 +34,7 @@ import org.apache.poi.poifs.crypt.Cipher import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.crypt.HashAlgorithm; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.xmlbeans.XmlException; @@ -50,7 +50,7 @@ public class TestXWPFBugs { @Test public void bug53475NoCSPName() throws Exception { File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-solrcell.docx"); - NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true); + POIFSFileSystem filesystem = new POIFSFileSystem(file, true); // Check the encryption details EncryptionInfo info = new EncryptionInfo(filesystem); @@ -85,7 +85,7 @@ public class TestXWPFBugs { Assume.assumeTrue("Please install JCE Unlimited Strength Jurisdiction Policy files for AES 256", maxKeyLen == 2147483647); File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-pass.docx"); - NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true); + POIFSFileSystem filesystem = new POIFSFileSystem(file, true); // Check the encryption details EncryptionInfo info = new EncryptionInfo(filesystem); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java Fri Aug 31 00:25:50 2018 @@ -17,7 +17,6 @@ package org.apache.poi.hdgf; -import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -30,7 +29,6 @@ import org.apache.poi.hdgf.streams.Strea import org.apache.poi.hdgf.streams.StringsStream; import org.apache.poi.hdgf.streams.TrailerStream; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -46,30 +44,23 @@ import org.apache.poi.util.LocaleUtil; public final class HDGFDiagram extends POIReadOnlyDocument { private static final String VISIO_HEADER = "Visio (TM) Drawing\r\n"; - private byte[] _docstream; - - private short version; private long docSize; private Pointer trailerPointer; private TrailerStream trailer; - private ChunkFactory chunkFactory; - private PointerFactory ptrFactory; - public HDGFDiagram(POIFSFileSystem fs) throws IOException { this(fs.getRoot()); } - public HDGFDiagram(NPOIFSFileSystem fs) throws IOException { - this(fs.getRoot()); - } + public HDGFDiagram(DirectoryNode dir) throws IOException { super(dir); // Grab the document stream - InputStream is = dir.createDocumentInputStream("VisioDocument"); - _docstream = IOUtils.toByteArray(is); - is.close(); + final byte[] _docstream; + try (InputStream is = dir.createDocumentInputStream("VisioDocument")) { + _docstream = IOUtils.toByteArray(is); + } // Check it's really visio String typeString = new String(_docstream, 0, 20, LocaleUtil.CHARSET_1252 ); @@ -78,14 +69,14 @@ public final class HDGFDiagram extends P } // Grab the version number, 0x1a -> 0x1b - version = LittleEndian.getShort(_docstream, 0x1a); + short version = LittleEndian.getShort(_docstream, 0x1a); // Grab the document size, 0x1c -> 0x1f docSize = LittleEndian.getUInt(_docstream, 0x1c); // ??? 0x20 -> 0x23 // Create the Chunk+Pointer Factories for the document version - ptrFactory = new PointerFactory(version); - chunkFactory = new ChunkFactory(version); + PointerFactory ptrFactory = new PointerFactory(version); + ChunkFactory chunkFactory = new ChunkFactory(version); // Grab the pointer to the trailer trailerPointer = ptrFactory.createPointer(_docstream, 0x24); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java Fri Aug 31 00:25:50 2018 @@ -28,7 +28,7 @@ import org.apache.poi.hdgf.pointers.Poin import org.apache.poi.hdgf.streams.ChunkStream; import org.apache.poi.hdgf.streams.PointerContainingStream; import org.apache.poi.hdgf.streams.Stream; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * Developer helper class to dump out the pointer+stream structure @@ -51,7 +51,7 @@ public final class VSDDumper { System.exit(1); } - NPOIFSFileSystem poifs = new NPOIFSFileSystem(new File(args[0])); + POIFSFileSystem poifs = new POIFSFileSystem(new File(args[0])); try { HDGFDiagram hdgf = new HDGFDiagram(poifs); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java Fri Aug 31 00:25:50 2018 @@ -31,7 +31,6 @@ import org.apache.poi.hdgf.streams.Chunk import org.apache.poi.hdgf.streams.PointerContainingStream; import org.apache.poi.hdgf.streams.Stream; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** @@ -49,14 +48,13 @@ public final class VisioTextExtractor ex public VisioTextExtractor(POIFSFileSystem fs) throws IOException { this(fs.getRoot()); } - public VisioTextExtractor(NPOIFSFileSystem fs) throws IOException { - this(fs.getRoot()); - } + public VisioTextExtractor(DirectoryNode dir) throws IOException { this(new HDGFDiagram(dir)); } + public VisioTextExtractor(InputStream inp) throws IOException { - this(new NPOIFSFileSystem(inp)); + this(new POIFSFileSystem(inp)); } /** @@ -70,7 +68,7 @@ public final class VisioTextExtractor ex for(Stream stream : hdgf.getTopLevelStreams()) { findText(stream, text); } - return text.toArray( new String[text.size()] ); + return text.toArray(new String[0]); } private void findText(Stream stream, List<String> text) { if(stream instanceof PointerContainingStream) { @@ -113,7 +111,7 @@ public final class VisioTextExtractor ex */ @Override public String getText() { - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); for(String t : getAllText()) { text.append(t); if(!t.endsWith("\r") && !t.endsWith("\n")) { Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java Fri Aug 31 00:25:50 2018 @@ -26,7 +26,6 @@ import org.apache.poi.hpbf.model.EscherS import org.apache.poi.hpbf.model.MainContents; import org.apache.poi.hpbf.model.QuillContents; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** @@ -46,11 +45,9 @@ public final class HPBFDocument extends public HPBFDocument(POIFSFileSystem fs) throws IOException { this(fs.getRoot()); } - public HPBFDocument(NPOIFSFileSystem fs) throws IOException { - this(fs.getRoot()); - } + public HPBFDocument(InputStream inp) throws IOException { - this(new NPOIFSFileSystem(inp)); + this(new POIFSFileSystem(inp)); } /** Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java Fri Aug 31 00:25:50 2018 @@ -24,7 +24,7 @@ import java.io.InputStream; import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LocaleUtil; @@ -36,14 +36,14 @@ import org.apache.poi.util.StringUtil; * constructed. */ public final class HPBFDumper { - private NPOIFSFileSystem fs; - public HPBFDumper(NPOIFSFileSystem fs) { + private POIFSFileSystem fs; + public HPBFDumper(POIFSFileSystem fs) { this.fs = fs; } @SuppressWarnings("resource") public HPBFDumper(InputStream inp) throws IOException { - this(new NPOIFSFileSystem(inp)); + this(new POIFSFileSystem(inp)); } private static byte[] getData(DirectoryNode dir, String name) throws IOException { @@ -83,7 +83,7 @@ public final class HPBFDumper { System.err.println(" HPBFDumper <filename>"); System.exit(1); } - HPBFDumper dump = new HPBFDumper(new NPOIFSFileSystem(new File(args[0]))); + HPBFDumper dump = new HPBFDumper(new POIFSFileSystem(new File(args[0]))); System.out.println("Dumping " + args[0]); dump.dumpContents(); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java Fri Aug 31 00:25:50 2018 @@ -24,7 +24,7 @@ import java.io.InputStream; import org.apache.poi.hpbf.HPBFDocument; import org.apache.poi.hpbf.model.QuillContents; import org.apache.poi.hpbf.model.qcbits.QCBit; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.HexDump; /** @@ -40,11 +40,11 @@ public final class PLCDumper { doc = hpbfDoc; qc = doc.getQuillContents(); } - public PLCDumper(NPOIFSFileSystem fs) throws IOException { + public PLCDumper(POIFSFileSystem fs) throws IOException { this(new HPBFDocument(fs)); } public PLCDumper(InputStream inp) throws IOException { - this(new NPOIFSFileSystem(inp)); + this(new POIFSFileSystem(inp)); } public static void main(String[] args) throws Exception { Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java Fri Aug 31 00:25:50 2018 @@ -27,7 +27,6 @@ import org.apache.poi.hpbf.model.qcbits. import org.apache.poi.hpbf.model.qcbits.QCTextBit; import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** @@ -47,9 +46,6 @@ public final class PublisherTextExtracto public PublisherTextExtractor(POIFSFileSystem fs) throws IOException { this(new HPBFDocument(fs)); } - public PublisherTextExtractor(NPOIFSFileSystem fs) throws IOException { - this(new HPBFDocument(fs)); - } public PublisherTextExtractor(InputStream is) throws IOException { this(new POIFSFileSystem(is)); } @@ -69,10 +65,10 @@ public final class PublisherTextExtracto // Get the text from the Quill Contents QCBit[] bits = doc.getQuillContents().getBits(); - for(int i=0; i<bits.length; i++) { - if(bits[i] != null && bits[i] instanceof QCTextBit) { - QCTextBit t = (QCTextBit)bits[i]; - text.append( t.getText().replace('\r', '\n') ); + for (QCBit bit1 : bits) { + if (bit1 != null && bit1 instanceof QCTextBit) { + QCTextBit t = (QCTextBit) bit1; + text.append(t.getText().replace('\r', '\n')); } } @@ -82,10 +78,10 @@ public final class PublisherTextExtracto // hyperlink is in, and we have yet to figure out // how to tie that together. if(hyperlinksByDefault) { - for(int i=0; i<bits.length; i++) { - if(bits[i] != null && bits[i] instanceof Type12) { - Type12 hyperlinks = (Type12)bits[i]; - for(int j=0; j<hyperlinks.getNumberOfHyperlinks(); j++) { + for (QCBit bit : bits) { + if (bit != null && bit instanceof Type12) { + Type12 hyperlinks = (Type12) bit; + for (int j = 0; j < hyperlinks.getNumberOfHyperlinks(); j++) { text.append("<"); text.append(hyperlinks.getHyperlink(j)); text.append(">\n"); @@ -107,15 +103,12 @@ public final class PublisherTextExtracto System.err.println(" PublisherTextExtractor <file.pub>"); } - for(int i=0; i<args.length; i++) { - FileInputStream fis = new FileInputStream(args[i]); - try { - PublisherTextExtractor te = new PublisherTextExtractor(fis); - System.out.println(te.getText()); - te.close(); - } finally { - fis.close(); - } + for (String arg : args) { + try (FileInputStream fis = new FileInputStream(arg)) { + PublisherTextExtractor te = new PublisherTextExtractor(fis); + System.out.println(te.getText()); + te.close(); + } } } } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java Fri Aug 31 00:25:50 2018 @@ -30,7 +30,7 @@ import java.nio.charset.StandardCharsets import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -54,7 +54,7 @@ public final class PPTXMLDump { private boolean hexHeader = true; public PPTXMLDump(File ppt) throws IOException { - NPOIFSFileSystem fs = new NPOIFSFileSystem(ppt, true); + POIFSFileSystem fs = new POIFSFileSystem(ppt, true); try { docstream = readEntry(fs, HSLFSlideShow.POWERPOINT_DOCUMENT); pictstream = readEntry(fs, PICTURES_ENTRY); @@ -63,7 +63,7 @@ public final class PPTXMLDump { } } - private static byte[] readEntry(NPOIFSFileSystem fs, String entry) + private static byte[] readEntry(POIFSFileSystem fs, String entry) throws IOException { DirectoryNode dn = fs.getRoot(); if (!dn.hasEntry(entry)) { @@ -198,19 +198,19 @@ public final class PPTXMLDump { return; } boolean outFile = false; - for (int i = 0; i < args.length; i++){ + for (String arg : args) { - if (args[i].startsWith("-")) { - if ("-f".equals(args[i])){ + if (arg.startsWith("-")) { + if ("-f".equals(arg)) { //write ouput to a file outFile = true; } } else { - File ppt = new File(args[i]); + File ppt = new File(arg); PPTXMLDump dump = new PPTXMLDump(ppt); - System.out.println("Dumping " + args[i]); + System.out.println("Dumping " + arg); - if (outFile){ + if (outFile) { FileOutputStream fos = new FileOutputStream(ppt.getName() + ".xml"); OutputStreamWriter out = new OutputStreamWriter(fos, StandardCharsets.UTF_8); dump.dump(out); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java Fri Aug 31 00:25:50 2018 @@ -30,7 +30,7 @@ import org.apache.poi.ddf.EscherTextboxR import org.apache.poi.hslf.record.HSLFEscherRecordFactory; import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.usermodel.HSLFSlideShow; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.HexDump; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -77,7 +77,7 @@ public final class SlideShowDumper { filename = args[1]; } - NPOIFSFileSystem poifs = new NPOIFSFileSystem(new File(filename)); + POIFSFileSystem poifs = new POIFSFileSystem(new File(filename)); SlideShowDumper foo = new SlideShowDumper(poifs, System.out); poifs.close(); @@ -99,7 +99,7 @@ public final class SlideShowDumper { * @param filesystem the POIFS FileSystem to read from * @throws IOException if there is a problem while parsing the document. */ - public SlideShowDumper(NPOIFSFileSystem filesystem, PrintStream out) throws IOException { + public SlideShowDumper(POIFSFileSystem filesystem, PrintStream out) throws IOException { // Grab the document stream InputStream is = filesystem.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT); docstream = IOUtils.toByteArray(is); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java Fri Aug 31 00:25:50 2018 @@ -30,7 +30,6 @@ import org.apache.poi.hslf.usermodel.HSL import org.apache.poi.hslf.usermodel.HSLFTextParagraph; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.extractor.SlideShowExtractor; import org.apache.poi.sl.usermodel.SlideShowFactory; @@ -117,15 +116,6 @@ public final class PowerPointExtractor e } /** - * Creates a PowerPointExtractor, from an open NPOIFSFileSystem - * - * @param fs the NPOIFSFileSystem containing the PowerPoint document - */ - public PowerPointExtractor(NPOIFSFileSystem fs) throws IOException { - this((HSLFSlideShow)SlideShowFactory.create(fs, Biff8EncryptionKey.getCurrentUserPassword())); - } - - /** * Creates a PowerPointExtractor, from a specific place * inside an open NPOIFSFileSystem * Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java Fri Aug 31 00:25:50 2018 @@ -30,7 +30,7 @@ import org.apache.poi.hslf.record.TextBy import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFTextParagraph; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -53,7 +53,7 @@ import org.apache.poi.util.LittleEndian; * lucene indexers) that would ever want to use this! */ public final class QuickButCruddyTextExtractor { - private NPOIFSFileSystem fs; + private POIFSFileSystem fs; private InputStream is; private byte[] pptContents; @@ -82,7 +82,7 @@ public final class QuickButCruddyTextExt */ @SuppressWarnings("resource") public QuickButCruddyTextExtractor(String fileName) throws IOException { - this(new NPOIFSFileSystem(new File(fileName))); + this(new POIFSFileSystem(new File(fileName))); } /** @@ -91,7 +91,7 @@ public final class QuickButCruddyTextExt */ @SuppressWarnings("resource") public QuickButCruddyTextExtractor(InputStream iStream) throws IOException { - this(new NPOIFSFileSystem(iStream)); + this(new POIFSFileSystem(iStream)); is = iStream; } @@ -99,7 +99,7 @@ public final class QuickButCruddyTextExt * Creates an extractor from a POIFS Filesystem * @param poifs */ - public QuickButCruddyTextExtractor(NPOIFSFileSystem poifs) throws IOException { + public QuickButCruddyTextExtractor(POIFSFileSystem poifs) throws IOException { fs = poifs; // Find the PowerPoint bit, and get out the bytes Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java Fri Aug 31 00:25:50 2018 @@ -30,7 +30,7 @@ import org.apache.poi.hslf.exceptions.Co import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DocumentEntry; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.POILogFactory; @@ -49,13 +49,13 @@ public class CurrentUserAtom private static final int MAX_RECORD_LENGTH = 1_000_000; /** Standard Atom header */ - public static final byte[] atomHeader = new byte[] { 0, 0, -10, 15 }; + private static final byte[] atomHeader = new byte[] { 0, 0, -10, 15 }; /** The PowerPoint magic number for a non-encrypted file */ - public static final byte[] headerToken = new byte[] { 95, -64, -111, -29 }; - /** The PowerPoint magic number for an encrypted file */ - public static final byte[] encHeaderToken = new byte[] { -33, -60, -47, -13 }; - /** The Powerpoint 97 version, major and minor numbers */ - public static final byte[] ppt97FileVer = new byte[] { 8, 00, -13, 03, 03, 00 }; + private static final byte[] headerToken = new byte[] { 95, -64, -111, -29 }; + /** The PowerPoint magic number for an encrypted file */ + private static final byte[] encHeaderToken = new byte[] { -33, -60, -47, -13 }; + // The Powerpoint 97 version, major and minor numbers + // byte[] ppt97FileVer = new byte[] { 8, 00, -13, 03, 03, 00 }; /** The version, major and minor numbers */ private int docFinalVersion; @@ -274,7 +274,7 @@ public class CurrentUserAtom /** * Writes ourselves back out to a filesystem */ - public void writeToFS(NPOIFSFileSystem fs) throws IOException { + public void writeToFS(POIFSFileSystem fs) throws IOException { // Grab contents ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeOut(baos); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Fri Aug 31 00:25:50 2018 @@ -46,9 +46,8 @@ import org.apache.poi.hslf.model.MovieSh import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; -import org.apache.poi.poifs.filesystem.Ole10Native; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.poifs.filesystem.Ole10Native; import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.Resources; @@ -149,7 +148,7 @@ public final class HSLFSlideShow impleme * Constructs a Powerpoint document from an POIFSFileSystem. */ @SuppressWarnings("resource") - public HSLFSlideShow(NPOIFSFileSystem npoifs) throws IOException { + public HSLFSlideShow(POIFSFileSystem npoifs) throws IOException { this(new HSLFSlideShowImpl(npoifs)); } @@ -164,7 +163,7 @@ public final class HSLFSlideShow impleme /** * @return the current loading/saving phase */ - protected static LoadSavePhase getLoadSavePhase() { + static LoadSavePhase getLoadSavePhase() { return loadSavePhase.get(); } @@ -185,9 +184,7 @@ public final class HSLFSlideShow impleme // PersistPtr, remove their old positions int[] ids = pph.getKnownSlideIDs(); for (int id : ids) { - if (mostRecentByBytes.containsKey(id)) { - mostRecentByBytes.remove(id); - } + mostRecentByBytes.remove(id); } // Now, update the byte level locations with their latest values @@ -205,7 +202,7 @@ public final class HSLFSlideShow impleme // We'll also want to be able to turn the slide IDs into a position // in this array _sheetIdToCoreRecordsLookup = new HashMap<>(); - Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[mostRecentByBytes.size()]); + Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[0]); Arrays.sort(allIDs); for (int i = 0; i < allIDs.length; i++) { _sheetIdToCoreRecordsLookup.put(allIDs[i], i); @@ -534,6 +531,7 @@ public final class HSLFSlideShow impleme /** * Returns the data of all the embedded OLE object in the SlideShow */ + @SuppressWarnings("WeakerAccess") public HSLFObjectData[] getEmbeddedObjects() { return _hslfSlideShow.getEmbeddedObjects(); } @@ -563,7 +561,7 @@ public final class HSLFSlideShow impleme /** * Helper method for usermodel: Get the font collection */ - protected FontCollection getFontCollection() { + FontCollection getFontCollection() { return _fonts; } @@ -582,6 +580,7 @@ public final class HSLFSlideShow impleme * @param newSlideNumber * The new slide number (1 based) */ + @SuppressWarnings("WeakerAccess") public void reorderSlide(int oldSlideNumber, int newSlideNumber) { // Ensure these numbers are valid if (oldSlideNumber < 1 || newSlideNumber < 1) { @@ -612,7 +611,7 @@ public final class HSLFSlideShow impleme lst.addAll(Arrays.asList(s.getSlideRecords())); } - Record[] r = lst.toArray(new Record[lst.size()]); + Record[] r = lst.toArray(new Record[0]); slwt.setChildRecord(r); } @@ -627,6 +626,7 @@ public final class HSLFSlideShow impleme * the index of the slide to remove (0-based) * @return the slide that was removed from the slide show. */ + @SuppressWarnings("WeakerAccess") public HSLFSlide removeSlide(int index) { int lastSlideIdx = _slides.size() - 1; if (index < 0 || index > lastSlideIdx) { @@ -656,8 +656,8 @@ public final class HSLFSlideShow impleme if (sa.isEmpty()) { _documentRecord.removeSlideListWithText(slwt); } else { - slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()])); - slwt.setChildRecord(records.toArray(new Record[records.size()])); + slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[0])); + slwt.setChildRecord(records.toArray(new Record[0])); } // if the removed slide had notes - remove references to them too @@ -667,21 +667,23 @@ public final class HSLFSlideShow impleme SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText(); records = new ArrayList<>(); ArrayList<SlideAtomsSet> na = new ArrayList<>(); - for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) { - if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) { - continue; - } - na.add(ns); - records.add(ns.getSlidePersistAtom()); - if (ns.getSlideRecords() != null) { - records.addAll(Arrays.asList(ns.getSlideRecords())); + if (nslwt != null) { + for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) { + if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) { + continue; + } + na.add(ns); + records.add(ns.getSlidePersistAtom()); + if (ns.getSlideRecords() != null) { + records.addAll(Arrays.asList(ns.getSlideRecords())); + } } } if (na.isEmpty()) { _documentRecord.removeSlideListWithText(nslwt); } else { - nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[na.size()])); - nslwt.setChildRecord(records.toArray(new Record[records.size()])); + nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0])); + nslwt.setChildRecord(records.toArray(new Record[0])); } } @@ -712,10 +714,7 @@ public final class HSLFSlideShow impleme SlidePersistAtom prev = null; for (SlideAtomsSet sas : slist.getSlideAtomsSets()) { SlidePersistAtom spa = sas.getSlidePersistAtom(); - if (spa.getSlideIdentifier() < 0) { - // This is for a master slide - // Odd, since we only deal with the Slide SLWT - } else { + if (spa.getSlideIdentifier() >= 0) { // Must be for a real slide if (prev == null) { prev = spa; @@ -848,12 +847,9 @@ public final class HSLFSlideShow impleme throw new IllegalArgumentException("Unsupported picture format: " + format); } byte[] data = IOUtils.safelyAllocate(pict.length(), MAX_RECORD_LENGTH); - FileInputStream is = new FileInputStream(pict); - try { + try (FileInputStream is = new FileInputStream(pict)) { IOUtils.readFully(is, data); - } finally { - is.close(); - } + } return addPicture(data, format); } @@ -969,6 +965,7 @@ public final class HSLFSlideShow impleme * "ShockwaveFlash.ShockwaveFlash.9" * @return 0-based index of the control */ + @SuppressWarnings("unused") public int addControl(String name, String progId) { ExControl ctrl = new ExControl(); ctrl.setProgId(progId); @@ -1053,7 +1050,7 @@ public final class HSLFSlideShow impleme return new HPSFPropertiesExtractor(getSlideShowImpl()); } - protected int addToObjListAtom(RecordContainer exObj) { + int addToObjListAtom(RecordContainer exObj) { ExObjList lst = getDocumentRecord().getExObjList(true); ExObjListAtom objAtom = lst.getExObjListAtom(); // increment the object ID seed @@ -1065,7 +1062,7 @@ public final class HSLFSlideShow impleme return objectId; } - protected static Map<String,ClassID> getOleMap() { + private static Map<String,ClassID> getOleMap() { Map<String,ClassID> olemap = new HashMap<>(); olemap.put(POWERPOINT_DOCUMENT, ClassIDPredefined.POWERPOINT_V8.getClassID()); // as per BIFF8 spec @@ -1078,7 +1075,7 @@ public final class HSLFSlideShow impleme return olemap; } - protected int addPersistentObject(PositionDependentRecord slideRecord) { + private int addPersistentObject(PositionDependentRecord slideRecord) { slideRecord.setLastOnDiskOffset(HSLFSlideShowImpl.UNSET_OFFSET); _hslfSlideShow.appendRootLevelRecord((Record)slideRecord); @@ -1117,13 +1114,13 @@ public final class HSLFSlideShow impleme @Override public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException { - // TODO Auto-generated method stub + // TODO implement or throw exception if not supported return null; } @Override public Resources getResources() { - // TODO Auto-generated method stub + // TODO implement or throw exception if not supported return null; } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java Fri Aug 31 00:25:50 2018 @@ -20,7 +20,7 @@ package org.apache.poi.hslf.usermodel; import java.io.IOException; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.util.Internal; @@ -28,6 +28,7 @@ import org.apache.poi.util.Internal; * Helper class which is instantiated by reflection from * {@link SlideShowFactory#create(java.io.File)} and similar */ +@SuppressWarnings("unused") @Internal public class HSLFSlideShowFactory extends SlideShowFactory { /** @@ -35,7 +36,7 @@ public class HSLFSlideShowFactory extend * Note that in order to properly release resources the * SlideShow should be closed after use. */ - public static HSLFSlideShow createSlideShow(final NPOIFSFileSystem fs) throws IOException { + public static HSLFSlideShow createSlideShow(final POIFSFileSystem fs) throws IOException { return new HSLFSlideShow(fs); } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java Fri Aug 31 00:25:50 2018 @@ -49,7 +49,6 @@ import org.apache.poi.poifs.filesystem.D import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.EntryUtils; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.util.IOUtils; @@ -63,7 +62,7 @@ import org.apache.poi.util.POILogger; * "reader". It is only a very basic class for now */ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { - public static final int UNSET_OFFSET = -1; + static final int UNSET_OFFSET = -1; //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 200_000_000; @@ -123,17 +122,6 @@ public final class HSLFSlideShowImpl ext } /** - * Constructs a Powerpoint document from a POIFS Filesystem. Parses the - * document and places all the important stuff into data structures. - * - * @param filesystem the POIFS FileSystem to read from - * @throws IOException if there is a problem while parsing the document. - */ - public HSLFSlideShowImpl(NPOIFSFileSystem filesystem) throws IOException { - this(filesystem.getRoot()); - } - - /** * Constructs a Powerpoint document from a specific point in a * POIFS Filesystem. Parses the document and places all the * important stuff into data structures. @@ -192,7 +180,7 @@ public final class HSLFSlideShowImpl ext * Extracts the main PowerPoint document stream from the * POI file, ready to be passed * - * @throws IOException + * @throws IOException when the powerpoint can't be read */ private void readPowerPointStream() throws IOException { // Get the main document stream @@ -201,11 +189,8 @@ public final class HSLFSlideShowImpl ext // Grab the document stream int len = docProps.getSize(); - InputStream is = getDirectory().createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT); - try { + try (InputStream is = getDirectory().createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT)) { _docstream = IOUtils.toByteArray(is, len); - } finally { - is.close(); } } @@ -276,7 +261,7 @@ public final class HSLFSlideShowImpl ext } decryptData.close(); - return records.values().toArray(new Record[records.size()]); + return records.values().toArray(new Record[0]); } private void initRecordOffsets(byte[] docstream, int usrOffset, NavigableMap<Integer, Record> recordMap, Map<Integer, Integer> offset2id) { @@ -362,16 +347,15 @@ public final class HSLFSlideShowImpl ext byte[] pictstream = IOUtils.toByteArray(is, entry.getSize()); is.close(); - HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom()); - try { - + try (HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom())) { + int pos = 0; // An empty picture record (length 0) will take up 8 bytes while (pos <= (pictstream.length - 8)) { int offset = pos; - + decryptData.decryptPicture(pictstream, offset); - + // Image signature int signature = LittleEndian.getUShort(pictstream, pos); pos += LittleEndianConsts.SHORT_SIZE; @@ -381,20 +365,20 @@ public final class HSLFSlideShowImpl ext // Image size (excluding the 8 byte header) int imgsize = LittleEndian.getInt(pictstream, pos); pos += LittleEndianConsts.INT_SIZE; - + // When parsing the BStoreDelay stream, [MS-ODRAW] says that we // should terminate if the type isn't 0xf007 or 0xf018->0xf117 if (!((type == 0xf007) || (type >= 0xf018 && type <= 0xf117))) { break; } - + // The image size must be 0 or greater // (0 is allowed, but odd, since we do wind on by the header each // time, so we won't get stuck) if (imgsize < 0) { throw new CorruptPowerPointFileException("The file contains a picture, at position " + _pictures.size() + ", which has a negatively sized data length, so we can't trust any of the picture data"); } - + // If they type (including the bonus 0xF018) is 0, skip it PictureType pt = PictureType.forNativeID(type - 0xF018); if (pt == null) { @@ -404,7 +388,7 @@ public final class HSLFSlideShowImpl ext //The pictstream can be truncated halfway through a picture. //This is not a problem if the pictstream contains extra pictures //that are not used in any slide -- BUG-60305 - if (pos+imgsize > pictstream.length) { + if (pos + imgsize > pictstream.length) { logger.log(POILogger.WARN, "\"Pictures\" stream may have ended early. In some circumstances, this is not a problem; " + "in others, this could indicate a corrupt file"); break; @@ -413,12 +397,12 @@ public final class HSLFSlideShowImpl ext try { HSLFPictureData pict = HSLFPictureData.create(pt); pict.setSignature(signature); - + // Copy the data, ready to pass to PictureData byte[] imgdata = IOUtils.safelyAllocate(imgsize, MAX_RECORD_LENGTH); System.arraycopy(pictstream, pos, imgdata, 0, imgdata.length); pict.setRawData(imgdata); - + pict.setOffset(offset); pict.setIndex(_pictures.size()); _pictures.add(pict); @@ -426,11 +410,9 @@ public final class HSLFSlideShowImpl ext logger.log(POILogger.ERROR, "Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!"); } } - + pos += imgsize; } - } finally { - decryptData.close(); } } @@ -456,8 +438,8 @@ public final class HSLFSlideShowImpl ext * @param interestingRecords a map of interesting records (PersistPtrHolder and UserEditAtom) * referenced by their RecordType. Only the very last of each type will be saved to the map. * May be null, if not needed. - * @throws IOException */ + @SuppressWarnings("WeakerAccess") public void updateAndWriteDependantRecords(OutputStream os, Map<RecordTypes, PositionDependentRecord> interestingRecords) throws IOException { // For position dependent records, hold where they were and now are @@ -602,16 +584,13 @@ public final class HSLFSlideShowImpl ext */ public void write(File newFile, boolean preserveNodes) throws IOException { // Get a new FileSystem to write into - POIFSFileSystem outFS = POIFSFileSystem.create(newFile); - try { + try (POIFSFileSystem outFS = POIFSFileSystem.create(newFile)) { // Write into the new FileSystem write(outFS, preserveNodes); // Send the POIFSFileSystem object out to the underlying stream outFS.writeFilesystem(); - } finally { - outFS.close(); } } @@ -645,20 +624,17 @@ public final class HSLFSlideShowImpl ext */ public void write(OutputStream out, boolean preserveNodes) throws IOException { // Get a new FileSystem to write into - POIFSFileSystem outFS = new POIFSFileSystem(); - try { + try (POIFSFileSystem outFS = new POIFSFileSystem()) { // Write into the new FileSystem write(outFS, preserveNodes); // Send the POIFSFileSystem object out to the underlying stream outFS.writeFilesystem(out); - } finally { - outFS.close(); } } - private void write(NPOIFSFileSystem outFS, boolean copyAllOtherNodes) throws IOException { + private void write(POIFSFileSystem outFS, boolean copyAllOtherNodes) throws IOException { // read properties and pictures, with old encryption settings where appropriate if (_pictures == null) { readPictures(); @@ -721,7 +697,7 @@ public final class HSLFSlideShowImpl ext @Override - public EncryptionInfo getEncryptionInfo() throws IOException { + public EncryptionInfo getEncryptionInfo() { DocumentEncryptionAtom dea = getDocumentEncryptionAtom(); return (dea != null) ? dea.getEncryptionInfo() : null; } @@ -735,6 +711,7 @@ public final class HSLFSlideShowImpl ext * Adds a new root level record, at the end, but before the last * PersistPtrIncrementalBlock. */ + @SuppressWarnings({"UnusedReturnValue", "WeakerAccess"}) public synchronized int appendRootLevelRecord(Record newRecord) { int addedAt = -1; Record[] r = new Record[_records.length + 1]; @@ -839,7 +816,7 @@ public final class HSLFSlideShowImpl ext objects.add(new HSLFObjectData((ExOleObjStg) r)); } } - _objects = objects.toArray(new HSLFObjectData[objects.size()]); + _objects = objects.toArray(new HSLFObjectData[0]); } return _objects; } @@ -849,7 +826,7 @@ public final class HSLFSlideShowImpl ext // only close the filesystem, if we are based on the root node. // embedded documents/slideshows shouldn't close the parent container if (getDirectory().getParent() == null) { - NPOIFSFileSystem fs = getDirectory().getFileSystem(); + POIFSFileSystem fs = getDirectory().getFileSystem(); if (fs != null) { fs.close(); } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Fri Aug 31 00:25:50 2018 @@ -48,7 +48,7 @@ import org.apache.poi.hsmf.datatypes.Typ import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.hsmf.parsers.POIFSChunkParser; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.CodePageUtil; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -92,7 +92,7 @@ public class MAPIMessage extends POIRead */ public MAPIMessage() { // TODO - make writing possible - super(new NPOIFSFileSystem()); + super(new POIFSFileSystem()); } @@ -112,7 +112,7 @@ public class MAPIMessage extends POIRead * @exception IOException on errors reading, or invalid data */ public MAPIMessage(File file) throws IOException { - this(new NPOIFSFileSystem(file)); + this(new POIFSFileSystem(file)); } /** @@ -125,7 +125,7 @@ public class MAPIMessage extends POIRead * @exception IOException on errors reading, or invalid data */ public MAPIMessage(InputStream in) throws IOException { - this(new NPOIFSFileSystem(in)); + this(new POIFSFileSystem(in)); } /** * Constructor for reading MSG Files from a POIFS filesystem @@ -133,7 +133,7 @@ public class MAPIMessage extends POIRead * @param fs Open POIFS FileSystem containing the message * @exception IOException on errors reading, or invalid data */ - public MAPIMessage(NPOIFSFileSystem fs) throws IOException { + public MAPIMessage(POIFSFileSystem fs) throws IOException { this(fs.getRoot()); } /** Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java Fri Aug 31 00:25:50 2018 @@ -27,14 +27,14 @@ import org.apache.poi.hsmf.datatypes.MAP import org.apache.poi.hsmf.datatypes.PropertiesChunk; import org.apache.poi.hsmf.datatypes.PropertyValue; import org.apache.poi.hsmf.parsers.POIFSChunkParser; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * Dumps out the chunk details, and where possible contents */ public class HSMFDump { - private NPOIFSFileSystem fs; - public HSMFDump(NPOIFSFileSystem fs) { + private POIFSFileSystem fs; + public HSMFDump(POIFSFileSystem fs) { this.fs = fs; } @@ -84,7 +84,7 @@ public class HSMFDump { public static void main(String[] args) throws Exception { for(String file : args) { - NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true); + POIFSFileSystem fs = new POIFSFileSystem(new File(file), true); HSMFDump dump = new HSMFDump(fs); dump.dump(); fs.close(); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java Fri Aug 31 00:25:50 2018 @@ -30,7 +30,7 @@ import org.apache.poi.hsmf.datatypes.Att import org.apache.poi.hsmf.datatypes.StringChunk; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.StringUtil.StringsIterator; @@ -45,7 +45,7 @@ public class OutlookTextExtactor extends public OutlookTextExtactor(DirectoryNode poifsDir) throws IOException { this(new MAPIMessage(poifsDir)); } - public OutlookTextExtactor(NPOIFSFileSystem fs) throws IOException { + public OutlookTextExtactor(POIFSFileSystem fs) throws IOException { this(new MAPIMessage(fs)); } public OutlookTextExtactor(InputStream inp) throws IOException { @@ -54,15 +54,9 @@ public class OutlookTextExtactor extends public static void main(String[] args) throws Exception { for(String filename : args) { - NPOIFSFileSystem poifs = null; - OutlookTextExtactor extractor = null; - try { - poifs = new NPOIFSFileSystem(new File(filename)); - extractor = new OutlookTextExtactor(poifs); - System.out.println( extractor.getText() ); - } finally { - if (extractor != null) extractor.close(); - if (poifs != null) poifs.close(); + try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename)); + OutlookTextExtactor extractor = new OutlookTextExtactor(poifs)) { + System.out.println(extractor.getText()); } } } @@ -118,18 +112,14 @@ public class OutlookTextExtactor extends // First try via the proper chunk SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT); f.setTimeZone(LocaleUtil.getUserTimeZone()); - s.append("Date: " + f.format(msg.getMessageDate().getTime()) + "\n"); + s.append("Date: ").append(f.format(msg.getMessageDate().getTime())).append("\n"); } catch(ChunkNotFoundException e) { try { // Failing that try via the raw headers String[] headers = msg.getHeaders(); for(String header: headers) { if(startsWithIgnoreCase(header, "date:")) { - s.append( - "Date:" + - header.substring(header.indexOf(':')+1) + - "\n" - ); + s.append("Date:").append(header, header.indexOf(':')+1, header.length()).append("\n"); break; } } @@ -139,7 +129,7 @@ public class OutlookTextExtactor extends } try { - s.append("Subject: " + msg.getSubject() + "\n"); + s.append("Subject: ").append(msg.getSubject()).append("\n"); } catch(ChunkNotFoundException e) {} // Display attachment names @@ -153,11 +143,11 @@ public class OutlookTextExtactor extends att.getAttachMimeTag().getValue() != null) { attName = att.getAttachMimeTag().getValue() + " = " + attName; } - s.append("Attachment: " + attName + "\n"); + s.append("Attachment: ").append(attName).append("\n"); } try { - s.append("\n" + msg.getTextBody() + "\n"); + s.append("\n").append(msg.getTextBody()).append("\n"); } catch(ChunkNotFoundException e) {} return s.toString(); @@ -176,7 +166,7 @@ public class OutlookTextExtactor extends String[] names = displayText.split(";\\s*"); boolean first = true; - s.append(type + ": "); + s.append(type).append(": "); for(String name : names) { if(first) { first = false; @@ -190,7 +180,7 @@ public class OutlookTextExtactor extends // Append the email address in <>, assuming // the name wasn't already the email address if(! email.equals(name)) { - s.append( " <" + email + ">"); + s.append(" <").append(email).append(">"); } } } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java Fri Aug 31 00:25:50 2018 @@ -40,7 +40,7 @@ import org.apache.poi.poifs.filesystem.D import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.DocumentNode; import org.apache.poi.poifs.filesystem.Entry; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -52,7 +52,7 @@ import org.apache.poi.util.POILogger; public final class POIFSChunkParser { private final static POILogger logger = POILogFactory.getLogger(POIFSChunkParser.class); - public static ChunkGroup[] parse(NPOIFSFileSystem fs) throws IOException { + public static ChunkGroup[] parse(POIFSFileSystem fs) throws IOException { return parse(fs.getRoot()); } public static ChunkGroup[] parse(DirectoryNode node) throws IOException { @@ -206,15 +206,11 @@ public final class POIFSChunkParser { if(chunk != null) { if(entry instanceof DocumentNode) { - DocumentInputStream inp = null; - try { - inp = new DocumentInputStream((DocumentNode)entry); + try (DocumentInputStream inp = new DocumentInputStream((DocumentNode) entry)) { chunk.readValue(inp); grouping.record(chunk); - } catch(IOException e) { - logger.log(POILogger.ERROR, "Error reading from part " + entry.getName() + " - " + e); - } finally { - if (inp != null) inp.close(); + } catch (IOException e) { + logger.log(POILogger.ERROR, "Error reading from part " + entry.getName() + " - " + e); } } else { grouping.record(chunk); Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Fri Aug 31 00:25:50 2018 @@ -70,7 +70,6 @@ import org.apache.poi.poifs.crypt.standa import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.EntryUtils; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -90,26 +89,26 @@ public final class HWPFDocument extends private static final String STREAM_DATA = "Data"; /** table stream buffer*/ - protected byte[] _tableStream; + private byte[] _tableStream; /** data stream buffer*/ - protected byte[] _dataStream; + private byte[] _dataStream; /** Document wide Properties*/ - protected DocumentProperties _dop; + private DocumentProperties _dop; /** Contains text of the document wrapped in a obfuscated Word data * structure*/ - protected ComplexFileTable _cft; + private ComplexFileTable _cft; /** Contains text buffer linked directly to single-piece document text piece */ - protected StringBuilder _text; + private StringBuilder _text; /** Holds the save history for this document. */ - protected SavedByTable _sbt; + private SavedByTable _sbt; /** Holds the revision mark authors for this document. */ - protected RevisionMarkAuthorTable _rmat; + private RevisionMarkAuthorTable _rmat; /** Holds FSBA (shape) information */ private FSPATable _fspaHeaders; @@ -118,46 +117,40 @@ public final class HWPFDocument extends private FSPATable _fspaMain; /** Escher Drawing Group information */ - protected EscherRecordHolder _escherRecordHolder; + private EscherRecordHolder _escherRecordHolder; /** Holds pictures table */ - protected PicturesTable _pictures; + private PicturesTable _pictures; /** Holds Office Art objects */ - protected OfficeDrawingsImpl _officeDrawingsHeaders; + private OfficeDrawingsImpl _officeDrawingsHeaders; /** Holds Office Art objects */ - protected OfficeDrawingsImpl _officeDrawingsMain; + private OfficeDrawingsImpl _officeDrawingsMain; /** Holds the bookmarks tables */ - protected BookmarksTables _bookmarksTables; + private BookmarksTables _bookmarksTables; /** Holds the bookmarks */ - protected Bookmarks _bookmarks; + private Bookmarks _bookmarks; /** Holds the ending notes tables */ - protected NotesTables _endnotesTables = new NotesTables( NoteType.ENDNOTE ); + private NotesTables _endnotesTables = new NotesTables( NoteType.ENDNOTE ); /** Holds the footnotes */ - protected Notes _endnotes = new NotesImpl( _endnotesTables ); + private Notes _endnotes = new NotesImpl( _endnotesTables ); /** Holds the footnotes tables */ - protected NotesTables _footnotesTables = new NotesTables( NoteType.FOOTNOTE ); + private NotesTables _footnotesTables = new NotesTables( NoteType.FOOTNOTE ); /** Holds the footnotes */ - protected Notes _footnotes = new NotesImpl( _footnotesTables ); + private Notes _footnotes = new NotesImpl( _footnotesTables ); /** Holds the fields PLCFs */ - protected FieldsTables _fieldsTables; + private FieldsTables _fieldsTables; /** Holds the fields */ - protected Fields _fields; - - protected HWPFDocument() - { - super(); - this._text = new StringBuilder("\r"); - } + private Fields _fields; /** * This constructor loads a Word document from an InputStream. @@ -599,7 +592,7 @@ public final class HWPFDocument extends */ @Override public void write(File newFile) throws IOException { - NPOIFSFileSystem pfs = POIFSFileSystem.create(newFile); + POIFSFileSystem pfs = POIFSFileSystem.create(newFile); write(pfs, true); pfs.writeFilesystem(); } @@ -618,12 +611,12 @@ public final class HWPFDocument extends */ @Override public void write(OutputStream out) throws IOException { - NPOIFSFileSystem pfs = new NPOIFSFileSystem(); + POIFSFileSystem pfs = new POIFSFileSystem(); write(pfs, true); pfs.writeFilesystem( out ); } - private void write(NPOIFSFileSystem pfs, boolean copyOtherEntries) throws IOException { + private void write(POIFSFileSystem pfs, boolean copyOtherEntries) throws IOException { // clear the offsets and sizes in our FileInformationBlock. _fib.clearOffsetsSizes(); @@ -999,7 +992,7 @@ public final class HWPFDocument extends return bos.toByteArray(); } - private static void write(NPOIFSFileSystem pfs, byte[] data, String name) throws IOException { + private static void write(POIFSFileSystem pfs, byte[] data, String name) throws IOException { pfs.createOrUpdateDocument(new ByteArrayInputStream(data), name); } Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java Fri Aug 31 00:25:50 2018 @@ -33,7 +33,6 @@ import org.apache.poi.hpsf.HPSFPropertie import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; import org.apache.poi.hwpf.HWPFTestDataSamples; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.junit.Before; import org.junit.Test; @@ -89,7 +88,7 @@ public final class TestPOIDocumentScratc @Test public void testWriteProperties() throws IOException { // Just check we can write them back out into a filesystem - NPOIFSFileSystem outFS = new NPOIFSFileSystem(); + POIFSFileSystem outFS = new POIFSFileSystem(); doc.writeProperties(outFS); // Should now hold them @@ -103,7 +102,7 @@ public final class TestPOIDocumentScratc ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Write them out - NPOIFSFileSystem outFS = new NPOIFSFileSystem(); + POIFSFileSystem outFS = new POIFSFileSystem(); doc.writeProperties(outFS); outFS.writeFilesystem(baos); Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TestPublisherTextExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TestPublisherTextExtractor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TestPublisherTextExtractor.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TestPublisherTextExtractor.java Fri Aug 31 00:25:50 2018 @@ -26,7 +26,7 @@ import java.io.InputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.hpbf.HPBFDocument; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.junit.Test; public final class TestPublisherTextExtractor { @@ -97,7 +97,7 @@ public final class TestPublisherTextExtr // And with NPOIFS sample = _samples.openResourceAsStream("Sample.pub"); - NPOIFSFileSystem fs = new NPOIFSFileSystem(sample); + POIFSFileSystem fs = new POIFSFileSystem(sample); HPBFDocument docNPOIFS = new HPBFDocument(fs); ext = new PublisherTextExtractor(docNPOIFS); assertEquals(SAMPLE_TEXT, ext.getText()); @@ -116,8 +116,6 @@ public final class TestPublisherTextExtr /** * We have the same file saved for Publisher 98, Publisher 2000 and * Publisher 2007. Check they all agree. - * - * @throws Exception */ @Test public void testMultipleVersions() throws Exception { Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1839709&r1=1839708&r2=1839709&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Fri Aug 31 00:25:50 2018 @@ -37,7 +37,6 @@ import org.apache.poi.hslf.usermodel.HSL import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.extractor.SlideShowExtractor; import org.apache.poi.sl.usermodel.ObjectShape; @@ -376,14 +375,14 @@ public final class TestExtractor { /** * Tests that we can work with both {@link POIFSFileSystem} - * and {@link NPOIFSFileSystem} + * and {@link POIFSFileSystem} */ @SuppressWarnings("resource") @Test public void testDifferentPOIFS() throws IOException { // Open the two filesystems File pptFile = slTests.getFile("basic_test_ppt_file.ppt"); - try (final NPOIFSFileSystem npoifs = new NPOIFSFileSystem(pptFile, true)) { + try (final POIFSFileSystem npoifs = new POIFSFileSystem(pptFile, true)) { // Open directly try (SlideShow<?,?> ppt = SlideShowFactory.create(npoifs.getRoot()); SlideShowExtractor<?,?> extractor = new SlideShowExtractor<>(ppt)) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
