Author: kiwiwings
Date: Sun Aug 26 11:55:00 2018
New Revision: 1839201
URL: http://svn.apache.org/viewvc?rev=1839201&view=rev
Log:
#62649 - Remove OPOIFS
Fix HPSF UTF-8 encoding error with Bug52311.doc while refactoring
CopyCompare/EntryUtils
Added:
poi/trunk/src/java/org/apache/poi/poifs/common/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/common/package.html
poi/trunk/src/java/org/apache/poi/poifs/crypt/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/crypt/package.html
poi/trunk/src/java/org/apache/poi/poifs/dev/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/dev/package.html
poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package.html
poi/trunk/src/java/org/apache/poi/poifs/filesystem/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/filesystem/package.html
poi/trunk/src/java/org/apache/poi/poifs/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/package.html
poi/trunk/src/java/org/apache/poi/poifs/property/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/property/package.html
poi/trunk/src/java/org/apache/poi/poifs/storage/package-info.java
- copied, changed from r1839200,
poi/trunk/src/java/org/apache/poi/poifs/storage/package.html
Removed:
poi/trunk/src/java/org/apache/poi/poifs/common/package.html
poi/trunk/src/java/org/apache/poi/poifs/crypt/package.html
poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java
poi/trunk/src/java/org/apache/poi/poifs/dev/package.html
poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package.html
poi/trunk/src/java/org/apache/poi/poifs/filesystem/ODocumentInputStream.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/OPOIFSDocument.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/package.html
poi/trunk/src/java/org/apache/poi/poifs/package.html
poi/trunk/src/java/org/apache/poi/poifs/property/package.html
poi/trunk/src/java/org/apache/poi/poifs/storage/SmallBlockTableReader.java
poi/trunk/src/java/org/apache/poi/poifs/storage/SmallBlockTableWriter.java
poi/trunk/src/java/org/apache/poi/poifs/storage/SmallDocumentBlock.java
poi/trunk/src/java/org/apache/poi/poifs/storage/SmallDocumentBlockList.java
poi/trunk/src/java/org/apache/poi/poifs/storage/package.html
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableReader.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableWriter.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlockList.java
Modified:
poi/site/src/documentation/content/xdocs/changes.xml
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadCustomPropertySets.java
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/POIBrowser.java
poi/trunk/src/java/org/apache/poi/POIDocument.java
poi/trunk/src/java/org/apache/poi/POIReadOnlyDocument.java
poi/trunk/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java
poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
poi/trunk/src/java/org/apache/poi/hpsf/Property.java
poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java
poi/trunk/src/java/org/apache/poi/hpsf/Section.java
poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java
poi/trunk/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java
poi/trunk/src/java/org/apache/poi/poifs/crypt/Encryptor.java
poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java
poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReaderRegistry.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentNode.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/NDocumentInputStream.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
poi/trunk/src/java/org/apache/poi/poifs/property/DirectoryProperty.java
poi/trunk/src/java/org/apache/poi/poifs/property/DocumentProperty.java
poi/trunk/src/java/org/apache/poi/poifs/property/RootProperty.java
poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java
poi/trunk/src/java/org/apache/poi/util/LittleEndianOutputStream.java
poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java
poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java
poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
poi/trunk/src/testcases/org/apache/poi/hpsf/basic/Util.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
poi/trunk/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/AllPOIFSFileSystemTests.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/ReaderWriter.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java
Modified: poi/site/src/documentation/content/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/changes.xml?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/changes.xml (original)
+++ poi/site/src/documentation/content/xdocs/changes.xml Sun Aug 26 11:55:00
2018
@@ -88,8 +88,10 @@
<release version="4.0.0-SNAPSHOT" date="2018-08-??">
<summary>
<summary-item>Removed support for Java 6 and 7 making Java 8 the
minimum version supported</summary-item>
+ <summary-item>New OOXML schema (1.4) necessary, because of
incompatible XMLBeans loading not anymore through
POIXMLTypeLoader</summary-item>
</summary>
<actions>
+ <action dev="PD" type="remove" fixes-bug="62649"
breaks-compatibility="true" context="POIFS">Remove OPOIFS*</action>
<action dev="PD" type="fix" fixes-bug="61589" context="XSLF">Importing
content does not copy hyperlink address</action>
<action dev="PD" type="fix" fixes-bug="62587" context="XSLF">repeated
call to XSLFSheet.removeShape leads to java.lang.IllegalArgumentException:
partName</action>
<action dev="PD" type="fix" fixes-bug="62513" context="OOXML">Don't
try to parse embedded package relationships</action>
Modified:
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java
Sun Aug 26 11:55:00 2018
@@ -20,8 +20,6 @@ package org.apache.poi.hpsf.examples;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -30,19 +28,21 @@ import java.io.UnsupportedEncodingExcept
import java.util.HashMap;
import java.util.Map;
+import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.HPSFRuntimeException;
import org.apache.poi.hpsf.MarkUnsupportedException;
import org.apache.poi.hpsf.NoPropertySetStreamException;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
import org.apache.poi.hpsf.WritingNotSupportedException;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.Entry;
+import org.apache.poi.poifs.filesystem.EntryUtils;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.TempFile;
@@ -66,36 +66,27 @@ import org.apache.poi.util.TempFile;
* with the same attributes, and the sections must contain the same properties.
* Details like the ordering of the properties do not matter.</p>
*/
-public class CopyCompare {
+public final class CopyCompare {
+ private CopyCompare() {}
+
/**
- * <p>Runs the example program. The application expects one or two
- * arguments:</p>
- * <p>
+ * Runs the example program. The application expects one or two arguments:
+ *
* <ol>
- * <p>
- * <li><p>The first argument is the disk file name of the POI filesystem to
- * copy.</p></li>
- * <p>
- * <li><p>The second argument is optional. If it is given, it is the name
of
+ * <li>The first argument is the disk file name of the POI filesystem to
copy.</li>
+ * <li>The second argument is optional. If it is given, it is the name of
* a disk file the copy of the POI filesystem will be written to. If it is
* not given, the copy will be written to a temporary file which will be
- * deleted at the end of the program.</p></li>
- * <p>
+ * deleted at the end of the program.</li>
* </ol>
*
* @param args Command-line arguments.
- * @throws MarkUnsupportedException if a POI document stream does not
- * support the mark() operation.
- * @throws NoPropertySetStreamException if the application tries to
- * create a property set from a POI
document stream that is not a property
- * set stream.
* @throws IOException if any I/O exception occurs.
* @throws UnsupportedEncodingException if a character encoding is not
* supported.
*/
public static void main(final String[] args)
- throws NoPropertySetStreamException, MarkUnsupportedException,
- UnsupportedEncodingException, IOException {
+ throws UnsupportedEncodingException, IOException {
String originalFileName = null;
String copyFileName = null;
@@ -120,10 +111,9 @@ public class CopyCompare {
final CopyFile cf = new CopyFile(copyFileName);
r.registerListener(cf);
r.setNotifyEmptyDirectories(true);
- try (FileInputStream fis = new FileInputStream(originalFileName)) {
- r.read(fis);
- }
-
+
+ r.read(new File(originalFileName));
+
/* Write the new POIFS to disk. */
cf.close();
@@ -133,124 +123,10 @@ public class CopyCompare {
POIFSFileSystem cpfs = new POIFSFileSystem(new
File(copyFileName))) {
final DirectoryEntry oRoot = opfs.getRoot();
final DirectoryEntry cRoot = cpfs.getRoot();
- final StringBuffer messages = new StringBuffer();
- if (equal(oRoot, cRoot, messages)) {
- System.out.println("Equal");
- } else {
- System.out.println("Not equal: " + messages);
- }
+ System.out.println(EntryUtils.areDirectoriesIdentical(oRoot,
cRoot) ? "Equal" : "Not equal");
}
}
-
- /**
- * <p>Compares two {@link DirectoryEntry} instances of a POI file system.
- * The directories must contain the same streams with the same names and
- * contents.</p>
- *
- * @param d1 The first directory.
- * @param d2 The second directory.
- * @param msg The method may append human-readable comparison messages to
- * this string buffer.
- * @return <code>true</code> if the directories are equal, else
- * <code>false</code>.
- * @throws MarkUnsupportedException if a POI document stream does not
- * support the mark() operation.
- * @throws NoPropertySetStreamException if the application tries to
- * create a property set from a POI
document stream that is not a property
- * set stream.
- * @throws IOException if any I/O exception occurs.
- */
- private static boolean equal(final DirectoryEntry d1,
- final DirectoryEntry d2,
- final StringBuffer msg)
- throws NoPropertySetStreamException, MarkUnsupportedException,
- UnsupportedEncodingException, IOException {
- boolean equal = true;
- /* Iterate over d1 and compare each entry with its counterpart in d2.
*/
- for (final Entry e1 : d1) {
- final String n1 = e1.getName();
- if (!d2.hasEntry(n1)) {
- msg.append("Document \"").append(n1).append("\" exists only in
the source.\n");
- equal = false;
- break;
- }
- Entry e2 = d2.getEntry(n1);
-
- if (e1.isDirectoryEntry() && e2.isDirectoryEntry()) {
- equal = equal((DirectoryEntry) e1, (DirectoryEntry) e2, msg);
- } else if (e1.isDocumentEntry() && e2.isDocumentEntry()) {
- equal = equal((DocumentEntry) e1, (DocumentEntry) e2, msg);
- } else {
- msg.append("One of \"").append(e1).append("\" and
\"").append(e2).append("\" is a ").append("document while the other one is a
directory.\n");
- equal = false;
- }
- }
-
- /* Iterate over d2 just to make sure that there are no entries in d2
- * that are not in d1. */
- for (final Entry e2 : d2) {
- final String n2 = e2.getName();
- Entry e1 = null;
- try {
- e1 = d1.getEntry(n2);
- } catch (FileNotFoundException ex) {
- msg.append("Document \"").append(e2).append("\" exitsts,
document \"").append(e1).append("\" does not.\n");
- equal = false;
- break;
- }
- }
- return equal;
- }
-
-
- /**
- * <p>Compares two {@link DocumentEntry} instances of a POI file system.
- * Documents that are not property set streams must be bitwise identical.
- * Property set streams must be logically equal.</p>
- *
- * @param d1 The first document.
- * @param d2 The second document.
- * @param msg The method may append human-readable comparison messages to
- * this string buffer.
- * @return <code>true</code> if the documents are equal, else
- * <code>false</code>.
- * @throws MarkUnsupportedException if a POI document stream does not
- * support the mark() operation.
- * @throws NoPropertySetStreamException if the application tries to
- * create a property set from a POI
document stream that is not a property
- * set stream.
- * @throws IOException if any I/O exception occurs.
- */
- private static boolean equal(final DocumentEntry d1, final DocumentEntry
d2,
- final StringBuffer msg)
- throws NoPropertySetStreamException, MarkUnsupportedException,
- UnsupportedEncodingException, IOException {
- try (DocumentInputStream dis1 = new DocumentInputStream(d1);
DocumentInputStream dis2 = new DocumentInputStream(d2)) {
- if (PropertySet.isPropertySetStream(dis1) &&
- PropertySet.isPropertySetStream(dis2)) {
- final PropertySet ps1 = PropertySetFactory.create(dis1);
- final PropertySet ps2 = PropertySetFactory.create(dis2);
- if (!ps1.equals(ps2)) {
- msg.append("Property sets are not equal.\n");
- return false;
- }
- } else {
- int i1, i2;
- do {
- i1 = dis1.read();
- i2 = dis2.read();
- if (i1 != i2) {
- msg.append("Documents are not equal.\n");
- return false;
- }
- } while (i1 > -1);
- }
- }
- return true;
- }
-
-
/**
* <p>This class does all the work. Its method {@link
* #processPOIFSReaderEvent(POIFSReaderEvent)} is called for each file in
@@ -274,7 +150,7 @@ public class CopyCompare {
* @param dstName The name of the disk file the destination POIFS is to
* be written to.
*/
- public CopyFile(final String dstName) {
+ CopyFile(final String dstName) {
this.dstName = dstName;
poiFs = new POIFSFileSystem();
}
@@ -332,7 +208,7 @@ public class CopyCompare {
/**
- * <p>Writes a {@link PropertySet} to a POI filesystem.</p>
+ * Writes a {@link PropertySet} to a POI filesystem.
*
* @param poiFs The POI filesystem to write to.
* @param path The file's path in the POI filesystem.
@@ -345,14 +221,25 @@ public class CopyCompare {
final PropertySet ps)
throws WritingNotSupportedException, IOException {
final DirectoryEntry de = getPath(poiFs, path);
- final PropertySet mps = new PropertySet(ps);
+ final PropertySet mps;
+ try {
+ if (ps instanceof DocumentSummaryInformation) {
+ mps = new DocumentSummaryInformation(ps);
+ } else if (ps instanceof SummaryInformation) {
+ mps = new SummaryInformation(ps);
+ } else {
+ mps = new PropertySet(ps);
+ }
+ } catch (UnexpectedPropertySetTypeException e) {
+ throw new IOException(e);
+ }
de.createDocument(name, mps.toInputStream());
}
/**
- * <p>Copies the bytes from a {@link DocumentInputStream} to a new
- * stream in a POI filesystem.</p>
+ * Copies the bytes from a {@link DocumentInputStream} to a new
+ * stream in a POI filesystem.
*
* @param poiFs The POI filesystem to write to.
* @param path The source document's path.
@@ -385,9 +272,9 @@ public class CopyCompare {
/**
- * <p>Writes the POI file system to a disk file.</p>
+ * Writes the POI file system to a disk file.
*/
- public void close() throws FileNotFoundException, IOException {
+ public void close() throws IOException {
out = new FileOutputStream(dstName);
poiFs.writeFilesystem(out);
out.close();
@@ -456,11 +343,7 @@ public class CopyCompare {
/* This exception will be thrown if the directory already
* exists. However, since we have full control about directory
* creation we can ensure that this will never happen. */
- ex.printStackTrace(System.err);
- throw new RuntimeException(ex.toString());
- /* FIXME (2): Replace the previous line by the following once
we
- * no longer need JDK 1.3 compatibility. */
- // throw new RuntimeException(ex);
+ throw new RuntimeException(ex);
}
}
}
Modified:
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadCustomPropertySets.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadCustomPropertySets.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
---
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadCustomPropertySets.java
(original)
+++
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadCustomPropertySets.java
Sun Aug 26 11:55:00 2018
@@ -17,7 +17,7 @@
package org.apache.poi.hpsf.examples;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -37,8 +37,9 @@ import org.apache.poi.util.HexDump;
*
* <p>Explanations can be found in the HPSF HOW-TO.</p>
*/
-public class ReadCustomPropertySets
-{
+public final class ReadCustomPropertySets {
+
+ private ReadCustomPropertySets() {}
/**
* <p>Runs the example program.</p>
@@ -54,7 +55,7 @@ public class ReadCustomPropertySets
/* Register a listener for *all* documents. */
r.registerListener(new MyPOIFSReaderListener());
- r.read(new FileInputStream(filename));
+ r.read(new File(filename));
}
@@ -117,12 +118,12 @@ public class ReadCustomPropertySets
}
}
- static void out(final String msg)
+ private static void out(final String msg)
{
System.out.println(msg);
}
- static String hex(final byte[] bytes)
+ private static String hex(final byte[] bytes)
{
return HexDump.dump(bytes, 0L, 0);
}
Modified: poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java Sun
Aug 26 11:55:00 2018
@@ -17,7 +17,7 @@
package org.apache.poi.hpsf.examples;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import org.apache.poi.hpsf.PropertySetFactory;
@@ -33,8 +33,10 @@ import org.apache.poi.poifs.eventfilesys
*
* <p>Explanations can be found in the HPSF HOW-TO.</p>
*/
-public class ReadTitle
+public final class ReadTitle
{
+ private ReadTitle() {}
+
/**
* <p>Runs the example program.</p>
*
@@ -47,7 +49,7 @@ public class ReadTitle
final String filename = args[0];
POIFSReader r = new POIFSReader();
r.registerListener(new MyPOIFSReaderListener(),
SummaryInformation.DEFAULT_STREAM_NAME);
- r.read(new FileInputStream(filename));
+ r.read(new File(filename));
}
Modified:
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
---
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
(original)
+++
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
Sun Aug 26 11:55:00 2018
@@ -19,8 +19,7 @@ package org.apache.poi.hpsf.examples;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -28,7 +27,15 @@ import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
-import org.apache.poi.hpsf.*;
+import org.apache.poi.hpsf.HPSFRuntimeException;
+import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.Section;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.Variant;
+import org.apache.poi.hpsf.WritingNotSupportedException;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
@@ -72,8 +79,9 @@ import org.apache.poi.poifs.filesystem.P
*
* <p>Further explanations can be found in the HPSF HOW-TO.</p>
*/
-public class WriteAuthorAndTitle
-{
+public final class WriteAuthorAndTitle {
+ private WriteAuthorAndTitle() {}
+
/**
* <p>Runs the example program.</p>
*
@@ -101,10 +109,8 @@ public class WriteAuthorAndTitle
final POIFSReader r = new POIFSReader();
final ModifySICopyTheRest msrl = new ModifySICopyTheRest(dstName);
r.registerListener(msrl);
- FileInputStream fis = new FileInputStream(srcName);
- r.read(fis);
- fis.close();
-
+ r.read(new File(srcName));
+
/* Write the new POIFS to disk. */
msrl.close();
}
@@ -127,14 +133,14 @@ public class WriteAuthorAndTitle
/**
- * <p>The constructor of a {@link ModifySICopyTheRest} instance creates
+ * The constructor of a {@link ModifySICopyTheRest} instance creates
* the target POIFS. It also stores the name of the file the POIFS will
- * be written to once it is complete.</p>
+ * be written to once it is complete.
*
* @param dstName The name of the disk file the destination POIFS is to
* be written to.
*/
- public ModifySICopyTheRest(final String dstName)
+ ModifySICopyTheRest(final String dstName)
{
this.dstName = dstName;
poiFs = new POIFSFileSystem();
@@ -142,8 +148,8 @@ public class WriteAuthorAndTitle
/**
- * <p>The method is called by POI's eventing API for each file in the
- * origin POIFS.</p>
+ * The method is called by POI's eventing API for each file in the
+ * origin POIFS.
*/
@Override
public void processPOIFSReaderEvent(final POIFSReaderEvent event)
@@ -213,7 +219,7 @@ public class WriteAuthorAndTitle
* @param si The property set. It should be a summary information
* property set.
*/
- public void editSI(final POIFSFileSystem poiFs,
+ void editSI(final POIFSFileSystem poiFs,
final POIFSDocumentPath path,
final String name,
final PropertySet si)
@@ -297,9 +303,9 @@ public class WriteAuthorAndTitle
/**
- * <p>Writes the POI file system to a disk file.</p>
+ * Writes the POI file system to a disk file.
*/
- public void close() throws FileNotFoundException, IOException
+ public void close() throws IOException
{
out = new FileOutputStream(dstName);
poiFs.writeFilesystem(out);
Modified:
poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/POIBrowser.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/POIBrowser.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/POIBrowser.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/POIBrowser.java
Sun Aug 26 11:55:00 2018
@@ -19,7 +19,7 @@ package org.apache.poi.poifs.poibrowser;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import javax.swing.JFrame;
@@ -42,12 +42,6 @@ import org.apache.poi.poifs.eventfilesys
public class POIBrowser extends JFrame
{
- /**
- * <p>The tree's root node must be visible to all methods.</p>
- */
- protected MutableTreeNode rootNode;
-
-
/**
* <p>Takes a bunch of file names as command line parameters,
@@ -59,8 +53,6 @@ public class POIBrowser extends JFrame
new POIBrowser().run(args);
}
-
-
protected void run(String[] args)
{
addWindowListener(new WindowAdapter()
@@ -74,8 +66,11 @@ public class POIBrowser extends JFrame
/* Create the tree model with a root node. The latter is
* invisible but it must be present because a tree model
- * always needs a root. */
- rootNode = new DefaultMutableTreeNode("POI Filesystems");
+ * always needs a root.
+ *
+ * The tree's root node must be visible to all methods.
+ */
+ MutableTreeNode rootNode = new DefaultMutableTreeNode("POI
Filesystems");
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
/* Create the tree UI element. */
@@ -85,10 +80,10 @@ public class POIBrowser extends JFrame
/* Add the POI filesystems to the tree. */
int displayedFiles = 0;
for (final String filename : args) {
- try (FileInputStream fis = new FileInputStream(filename)) {
+ try {
POIFSReader r = new POIFSReader();
r.registerListener(new TreeReaderListener(filename, rootNode));
- r.read(fis);
+ r.read(new File(filename));
displayedFiles++;
} catch (IOException ex) {
System.err.println(filename + ": " + ex);
Modified: poi/trunk/src/java/org/apache/poi/POIDocument.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIDocument.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Sun Aug 26 11:55:00 2018
@@ -40,7 +40,6 @@ import org.apache.poi.poifs.crypt.crypto
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
@@ -80,14 +79,6 @@ public abstract class POIDocument implem
*
* @param fs the filesystem the document is read from
*/
- protected POIDocument(OPOIFSFileSystem fs) {
- this(fs.getRoot());
- }
- /**
- * Constructs from an old-style OPOIFS
- *
- * @param fs the filesystem the document is read from
- */
protected POIDocument(NPOIFSFileSystem fs) {
this(fs.getRoot());
}
@@ -195,6 +186,7 @@ public abstract class POIDocument implem
* @param setName The property to read
* @return The value of the given property or null if it wasn't found.
*/
+ @SuppressWarnings("WeakerAccess")
protected PropertySet getPropertySet(String setName) throws IOException {
return getPropertySet(setName, getEncryptionInfo());
}
@@ -207,6 +199,7 @@ public abstract class POIDocument implem
* @param encryptionInfo the encryption descriptor in case of cryptoAPI
encryption
* @return The value of the given property or null if it wasn't found.
*/
+ @SuppressWarnings("WeakerAccess")
protected PropertySet getPropertySet(String setName, EncryptionInfo
encryptionInfo) throws IOException {
DirectoryNode dirNode = directory;
@@ -329,7 +322,7 @@ public abstract class POIDocument implem
* @throws IOException if an error when writing to the
* {@link NPOIFSFileSystem} occurs
*/
- protected void writePropertySet(String name, PropertySet set,
NPOIFSFileSystem outFS) throws IOException {
+ private void writePropertySet(String name, PropertySet set,
NPOIFSFileSystem outFS) throws IOException {
try {
PropertySet mSet = new PropertySet(set);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
@@ -420,8 +413,9 @@ public abstract class POIDocument implem
/**
* Closes the underlying {@link NPOIFSFileSystem} from which
* the document was read, if any. Has no effect on documents
- * opened from an InputStream, or newly created ones.
- * <p>Once close() has been called, no further operations
+ * opened from an InputStream, or newly created ones.<p>
+ *
+ * Once {@code close()} has been called, no further operations
* should be called on the document.
*/
@Override
@@ -468,13 +462,10 @@ public abstract class POIDocument implem
* to a new POIFSFileSystem
*
* @param newDirectory the new directory
- * @return the old/previous directory
*/
@Internal
- protected DirectoryNode replaceDirectory(DirectoryNode newDirectory) {
- DirectoryNode dn = directory;
+ protected void replaceDirectory(DirectoryNode newDirectory) {
directory = newDirectory;
- return dn;
}
/**
Modified: poi/trunk/src/java/org/apache/poi/POIReadOnlyDocument.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIReadOnlyDocument.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIReadOnlyDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIReadOnlyDocument.java Sun Aug 26
11:55:00 2018
@@ -21,8 +21,6 @@ import java.io.OutputStream;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
@@ -32,16 +30,10 @@ import org.apache.poi.poifs.filesystem.P
* @since POI 3.15 beta 3
*/
public abstract class POIReadOnlyDocument extends POIDocument {
- public POIReadOnlyDocument(DirectoryNode dir) {
+ protected POIReadOnlyDocument(DirectoryNode dir) {
super(dir);
}
- public POIReadOnlyDocument(NPOIFSFileSystem fs) {
- super(fs);
- }
- public POIReadOnlyDocument(OPOIFSFileSystem fs) {
- super(fs);
- }
- public POIReadOnlyDocument(POIFSFileSystem fs) {
+ protected POIReadOnlyDocument(NPOIFSFileSystem fs) {
super(fs);
}
Modified: poi/trunk/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java
(original)
+++ poi/trunk/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java Sun
Aug 26 11:55:00 2018
@@ -26,20 +26,14 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
-import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
-import org.apache.poi.poifs.crypt.Decryptor;
-import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -50,24 +44,24 @@ import org.apache.poi.util.POILogger;
* <p>Note 1 - will fail for many file formats if the POI Scratchpad jar is
* not present on the runtime classpath</p>
* <p>Note 2 - for text extractor creation across all formats, use
- * {@link org.apache.poi.extractor.ExtractorFactory} contained within
+ * {@link org.apache.poi.ooxml.extractor.ExtractorFactory} contained within
* the OOXML jar.</p>
* <p>Note 3 - rather than using this, for most cases you would be better
* off switching to <a href="http://tika.apache.org">Apache Tika</a>
instead!</p>
*/
@SuppressWarnings("WeakerAccess")
-public class OLE2ExtractorFactory {
+public final class OLE2ExtractorFactory {
private static final POILogger LOGGER =
POILogFactory.getLogger(OLE2ExtractorFactory.class);
/** Should this thread prefer event based over usermodel based extractors?
*/
- private static final ThreadLocal<Boolean> threadPreferEventExtractors =
new ThreadLocal<Boolean>() {
- @Override
- protected Boolean initialValue() { return Boolean.FALSE; }
- };
+ private static final ThreadLocal<Boolean> threadPreferEventExtractors =
ThreadLocal.withInitial(() -> Boolean.FALSE);
/** Should all threads prefer event based over usermodel based extractors?
*/
private static Boolean allPreferEventExtractors;
+ private OLE2ExtractorFactory() {
+ }
+
/**
* Should this thread prefer event based over usermodel based extractors?
* (usermodel extractors tend to be more accurate, but use more memory)
@@ -113,16 +107,16 @@ public class OLE2ExtractorFactory {
return threadPreferEventExtractors.get();
}
+ @SuppressWarnings("unchecked")
public static <T extends POITextExtractor> T
createExtractor(POIFSFileSystem fs) throws IOException {
return (T)createExtractor(fs.getRoot());
}
+ @SuppressWarnings("unchecked")
public static <T extends POITextExtractor> T
createExtractor(NPOIFSFileSystem fs) throws IOException {
return (T)createExtractor(fs.getRoot());
}
- public static <T extends POITextExtractor> T
createExtractor(OPOIFSFileSystem fs) throws IOException {
- return (T)createExtractor(fs.getRoot());
- }
+ @SuppressWarnings("unchecked")
public static <T extends POITextExtractor> T createExtractor(InputStream
input) throws IOException {
Class<?> cls = getOOXMLClass();
if (cls != null) {
@@ -165,7 +159,7 @@ public class OLE2ExtractorFactory {
/**
* Create the Extractor, if possible. Generally needs the Scratchpad jar.
* Note that this won't check for embedded OOXML resources either, use
- * {@link org.apache.poi.extractor.ExtractorFactory} for that.
+ * {@link org.apache.poi.ooxml.extractor.ExtractorFactory} for that.
*/
public static POITextExtractor createExtractor(DirectoryNode poifsDir)
throws IOException {
// Look for certain entries in the stream, to figure it
@@ -205,6 +199,7 @@ public class OLE2ExtractorFactory {
* empty array. Otherwise, you'll get one open
* {@link POITextExtractor} for each embedded file.
*/
+ @SuppressWarnings("unused")
public static POITextExtractor[]
getEmbededDocsTextExtractors(POIOLE2TextExtractor ext)
throws IOException
{
@@ -254,40 +249,11 @@ public class OLE2ExtractorFactory {
for (InputStream nonPOIF : nonPOIFS) {
try {
e.add(createExtractor(nonPOIF));
- } catch (IllegalArgumentException ie) {
- // Ignore, just means it didn't contain
- // a format we support as yet
- LOGGER.log(POILogger.WARN, ie);
} catch (Exception xe) {
// Ignore, invalid format
LOGGER.log(POILogger.WARN, xe);
}
}
- return e.toArray(new POITextExtractor[e.size()]);
- }
-
- private static POITextExtractor createEncyptedOOXMLExtractor(DirectoryNode
poifsDir)
- throws IOException {
- String pass = Biff8EncryptionKey.getCurrentUserPassword();
- if (pass == null) {
- pass = Decryptor.DEFAULT_PASSWORD;
- }
-
- EncryptionInfo ei = new EncryptionInfo(poifsDir);
- Decryptor dec = ei.getDecryptor();
- InputStream is = null;
- try {
- if (!dec.verifyPassword(pass)) {
- throw new EncryptedDocumentException("Invalid password
specified - use Biff8EncryptionKey.setCurrentUserPassword() before calling
extractor");
- }
- is = dec.getDataStream(poifsDir);
- return createExtractor(is);
- } catch (IOException e) {
- throw e;
- } catch (Exception e) {
- throw new IOException(e);
- } finally {
- IOUtils.closeQuietly(is);
- }
+ return e.toArray(new POITextExtractor[0]);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java Sun
Aug 26 11:55:00 2018
@@ -26,7 +26,6 @@ import org.apache.poi.POIDocument;
import org.apache.poi.poifs.filesystem.EntryUtils;
import org.apache.poi.poifs.filesystem.FilteringDirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
@@ -39,9 +38,6 @@ public class HPSFPropertiesOnlyDocument
public HPSFPropertiesOnlyDocument(NPOIFSFileSystem fs) {
super(fs.getRoot());
}
- public HPSFPropertiesOnlyDocument(OPOIFSFileSystem fs) {
- super(fs);
- }
public HPSFPropertiesOnlyDocument(POIFSFileSystem fs) {
super(fs);
}
@@ -60,24 +56,18 @@ public class HPSFPropertiesOnlyDocument
* Write out, with any properties changes, but nothing else
*/
public void write(File newFile) throws IOException {
- POIFSFileSystem fs = POIFSFileSystem.create(newFile);
- try {
+ try (POIFSFileSystem fs = POIFSFileSystem.create(newFile)) {
write(fs);
fs.writeFilesystem();
- } finally {
- fs.close();
}
}
/**
* Write out, with any properties changes, but nothing else
*/
public void write(OutputStream out) throws IOException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem();
- try {
+ try (NPOIFSFileSystem fs = new NPOIFSFileSystem()) {
write(fs);
fs.writeFilesystem(out);
- } finally {
- fs.close();
}
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/Property.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/Property.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/Property.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/Property.java Sun Aug 26 11:55:00
2018
@@ -345,9 +345,13 @@ public class Property {
* @return the truncated size with a maximum of 4 bytes shorter (3 bytes +
trailing 0 of strings)
*/
private static int unpaddedLength(byte[] buf) {
- int len;
- for (len = buf.length; len > 0 && len > buf.length-4 && buf[len-1] ==
0; len--);
- return len;
+ final int end = (buf.length-(buf.length+3)%4);
+ for (int i = buf.length; i>end; i--) {
+ if (buf[i-1] != 0) {
+ return i;
+ }
+ }
+ return end;
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java Sun Aug 26 11:55:00
2018
@@ -34,8 +34,11 @@ import org.apache.poi.poifs.filesystem.E
import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianOutputStream;
import org.apache.poi.util.NotImplemented;
+import org.apache.poi.util.Removal;
/**
* Represents a property set in the Horrible Property Set Format
@@ -175,8 +178,6 @@ public class PropertySet {
*
* @param stream Holds the data making out the property set
* stream.
- * @throws MarkUnsupportedException
- * if the stream does not support the {@link InputStream#markSupported}
method.
* @throws IOException
* if the {@link InputStream} cannot be accessed as needed.
* @exception NoPropertySetStreamException
@@ -185,8 +186,7 @@ public class PropertySet {
* if a character encoding is not supported.
*/
public PropertySet(final InputStream stream)
- throws NoPropertySetStreamException, MarkUnsupportedException,
- IOException, UnsupportedEncodingException {
+ throws NoPropertySetStreamException, IOException {
if (!isPropertySetStream(stream)) {
throw new NoPropertySetStreamException();
}
@@ -266,6 +266,7 @@ public class PropertySet {
*
* @param byteOrder The property set stream's low-level "byte order" field.
*/
+ @SuppressWarnings("WeakerAccess")
public void setByteOrder(int byteOrder) {
this.byteOrder = byteOrder;
}
@@ -298,6 +299,7 @@ public class PropertySet {
*
* @param osVersion The property set stream's low-level "OS version" field.
*/
+ @SuppressWarnings("WeakerAccess")
public void setOSVersion(int osVersion) {
this.osVersion = osVersion;
}
@@ -315,6 +317,7 @@ public class PropertySet {
*
* @param classID The property set stream's low-level "class ID" field.
*/
+ @SuppressWarnings("WeakerAccess")
public void setClassID(ClassID classID) {
this.classID = classID;
}
@@ -374,12 +377,10 @@ public class PropertySet {
* {@link InputStream#mark} method.
* @return {@code true} if the stream is a property set
* stream, else {@code false}.
- * @throws MarkUnsupportedException if the {@link InputStream}
- * does not support the {@link InputStream#mark} method.
* @exception IOException if an I/O error occurs
*/
public static boolean isPropertySetStream(final InputStream stream)
- throws MarkUnsupportedException, IOException {
+ throws IOException {
/*
* Read at most this many bytes.
*/
@@ -408,30 +409,34 @@ public class PropertySet {
* @return {@code true} if the byte array is a property set
* stream, {@code false} if not.
*/
+ @SuppressWarnings({"unused", "WeakerAccess"})
public static boolean isPropertySetStream(final byte[] src, final int
offset, final int length) {
- /* FIXME (3): Ensure that at most "length" bytes are read. */
+ LittleEndianByteArrayInputStream leis = new
LittleEndianByteArrayInputStream(src, offset, length);
/*
* Read the header fields of the stream. They must always be
* there.
*/
- int o = offset;
- final int byteOrder = LittleEndian.getUShort(src, o);
- o += LittleEndianConsts.SHORT_SIZE;
- if (byteOrder != BYTE_ORDER_ASSERTION) {
- return false;
- }
- final int format = LittleEndian.getUShort(src, o);
- o += LittleEndianConsts.SHORT_SIZE;
- if (format != FORMAT_ASSERTION) {
+ try {
+ final int byteOrder = leis.readUShort();
+ if (byteOrder != BYTE_ORDER_ASSERTION) {
+ return false;
+ }
+ final int format = leis.readUShort();
+ if (format != FORMAT_ASSERTION) {
+ return false;
+ }
+ final long osVersion = leis.readUInt();
+ byte[] clsBuf = new byte[ClassID.LENGTH];
+ leis.readFully(clsBuf);
+
+ final ClassID classID = new ClassID(clsBuf, 0);
+
+ final long sectionCount = leis.readUInt();
+ return (sectionCount >= 0);
+ } catch (RuntimeException e) {
return false;
}
- // final long osVersion = LittleEndian.getUInt(src, offset);
- o += LittleEndianConsts.INT_SIZE;
- // final ClassID classID = new ClassID(src, offset);
- o += ClassID.LENGTH;
- final long sectionCount = LittleEndian.getUInt(src, o);
- return (sectionCount >= 0);
}
@@ -452,7 +457,7 @@ public class PropertySet {
private void init(final byte[] src, final int offset, final int length)
throws UnsupportedEncodingException {
/* FIXME (3): Ensure that at most "length" bytes are read. */
-
+
/*
* Read the stream's header fields.
*/
@@ -504,50 +509,60 @@ public class PropertySet {
* @exception WritingNotSupportedException if HPSF does not yet support
* writing a property's variant type.
*/
- public void write(final OutputStream out)
- throws WritingNotSupportedException, IOException {
+ public void write(final OutputStream out) throws IOException,
WritingNotSupportedException {
+
+ out.write(toBytes());
+
+ /* Indicate that we're done */
+ out.close();
+ }
+
+ private byte[] toBytes() throws WritingNotSupportedException, IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
+
/* Write the number of sections in this property set stream. */
final int nrSections = getSectionCount();
/* Write the property set's header. */
- LittleEndian.putShort(out, (short) getByteOrder());
- LittleEndian.putShort(out, (short) getFormat());
- LittleEndian.putInt(getOSVersion(), out);
- putClassId(out, getClassID());
- LittleEndian.putInt(nrSections, out);
- int offset = OFFSET_HEADER;
+ leos.writeShort(getByteOrder());
+ leos.writeShort(getFormat());
+ leos.writeInt(getOSVersion());
+ putClassId(bos, getClassID());
+ leos.writeInt(nrSections);
+
+ assert(bos.size() == OFFSET_HEADER);
+
+ final int[][] offsets = new int[getSectionCount()][2];
/* Write the section list, i.e. the references to the sections. Each
* entry in the section list consist of the section's class ID and the
* section's offset relative to the beginning of the stream. */
- offset += nrSections * (ClassID.LENGTH + LittleEndianConsts.INT_SIZE);
- final int sectionsBegin = offset;
+ int secCnt = 0;
for (final Section section : getSections()) {
final ClassID formatID = section.getFormatID();
if (formatID == null) {
throw new NoFormatIDException();
}
- putClassId(out, formatID);
- LittleEndian.putUInt(offset, out);
- try {
- offset += section.getSize();
- } catch (HPSFRuntimeException ex) {
- final Throwable cause = ex.getReason();
- if (cause instanceof UnsupportedEncodingException) {
- throw new IllegalPropertySetDataException(cause);
- }
- throw ex;
- }
+ putClassId(bos, formatID);
+ offsets[secCnt++][0] = bos.size();
+ // offset dummy - filled later
+ leos.writeInt(-1);
}
/* Write the sections themselves. */
- offset = sectionsBegin;
+ secCnt = 0;
for (final Section section : getSections()) {
- offset += section.write(out);
+ offsets[secCnt++][1] = bos.size();
+ section.write(bos);
}
-
- /* Indicate that we're done */
- out.close();
+
+ byte[] result = bos.toByteArray();
+ for (int[] off : offsets) {
+ LittleEndian.putInt(result, off[0], off[1]);
+ }
+
+ return result;
}
/**
@@ -586,15 +601,8 @@ public class PropertySet {
* of a property's variant type.
* @throws IOException if an I/O exception occurs.
*/
- public InputStream toInputStream() throws IOException,
WritingNotSupportedException {
- final ByteArrayOutputStream psStream = new ByteArrayOutputStream();
- try {
- write(psStream);
- } finally {
- psStream.close();
- }
- final byte[] streamData = psStream.toByteArray();
- return new ByteArrayInputStream(streamData);
+ public InputStream toInputStream() throws WritingNotSupportedException,
IOException {
+ return new ByteArrayInputStream(toBytes());
}
/**
@@ -605,7 +613,7 @@ public class PropertySet {
*
* @return The property as a String, or null if unavailable
*/
- protected String getPropertyStringValue(final int propertyId) {
+ String getPropertyStringValue(final int propertyId) {
Object propertyValue = getProperty(propertyId);
return getPropertyStringValue(propertyValue);
}
@@ -724,7 +732,7 @@ public class PropertySet {
* @throws NoSingleSectionException if the {@link PropertySet} has
* more or less than one {@link Section}.
*/
- protected boolean getPropertyBooleanValue(final int id) throws
NoSingleSectionException {
+ boolean getPropertyBooleanValue(final int id) throws
NoSingleSectionException {
return getFirstSection().getPropertyBooleanValue(id);
}
@@ -742,7 +750,7 @@ public class PropertySet {
* @throws NoSingleSectionException if the {@link PropertySet} has
* more or less than one {@link Section}.
*/
- protected int getPropertyIntValue(final int id) throws
NoSingleSectionException {
+ int getPropertyIntValue(final int id) throws NoSingleSectionException {
return getFirstSection().getPropertyIntValue(id);
}
@@ -774,6 +782,7 @@ public class PropertySet {
*
* @return The {@link PropertySet}'s first section.
*/
+ @SuppressWarnings("WeakerAccess")
public Section getFirstSection() {
if (sections.isEmpty()) {
throw new MissingSectionException("Property set does not contain
any sections.");
@@ -787,7 +796,11 @@ public class PropertySet {
* If the {@link PropertySet} has only a single section this method
returns it.
*
* @return The singleSection value
+ *
+ * @deprecated superfluous convenience method
*/
+ @Deprecated
+ @Removal(version="5.0.0")
public Section getSingleSection() {
final int sectionCount = getSectionCount();
if (sectionCount != 1) {
@@ -809,7 +822,7 @@ public class PropertySet {
*/
@Override
public boolean equals(final Object o) {
- if (o == null || !(o instanceof PropertySet)) {
+ if (!(o instanceof PropertySet)) {
return false;
}
final PropertySet ps = (PropertySet) o;
@@ -877,27 +890,28 @@ public class PropertySet {
}
- protected void remove1stProperty(long id) {
+ void remove1stProperty(long id) {
getFirstSection().removeProperty(id);
}
- protected void set1stProperty(long id, String value) {
+ void set1stProperty(long id, String value) {
getFirstSection().setProperty((int)id, value);
}
- protected void set1stProperty(long id, int value) {
+ void set1stProperty(long id, int value) {
getFirstSection().setProperty((int)id, value);
}
- protected void set1stProperty(long id, boolean value) {
+ void set1stProperty(long id, boolean value) {
getFirstSection().setProperty((int)id, value);
}
- protected void set1stProperty(long id, byte[] value) {
+ @SuppressWarnings("SameParameterValue")
+ void set1stProperty(long id, byte[] value) {
getFirstSection().setProperty((int)id, value);
}
- private static void putClassId(final OutputStream out, final ClassID n)
throws IOException {
+ private static void putClassId(final ByteArrayOutputStream out, final
ClassID n) {
byte[] b = new byte[16];
n.write(b, 0);
out.write(b, 0, b.length);
Modified: poi/trunk/src/java/org/apache/poi/hpsf/Section.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/Section.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/Section.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/Section.java Sun Aug 26 11:55:00 2018
@@ -36,6 +36,7 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianOutputStream;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -81,7 +82,7 @@ public class Section {
* #getPropertyIntValue} or {@link #getProperty} tried to access a
* property that was not available, else {@code false}.
*/
- private boolean wasNull;
+ private transient boolean wasNull;
/**
* Creates an empty {@link Section}.
@@ -292,6 +293,7 @@ public class Section {
* @param formatID The section's format ID as a byte array. It components
* are in big-endian format.
*/
+ @SuppressWarnings("WeakerAccess")
public void setFormatID(final byte[] formatID) {
ClassID fid = getFormatID();
if (fid == null) {
@@ -325,7 +327,7 @@ public class Section {
* @return This section's properties.
*/
public Property[] getProperties() {
- return properties.values().toArray(new Property[properties.size()]);
+ return properties.values().toArray(new Property[0]);
}
/**
@@ -375,7 +377,7 @@ public class Section {
* @see #getProperty
*/
public void setProperty(final int id, final int value) {
- setProperty(id, Variant.VT_I4, Integer.valueOf(value));
+ setProperty(id, Variant.VT_I4, value);
}
@@ -390,7 +392,7 @@ public class Section {
* @see #getProperty
*/
public void setProperty(final int id, final long value) {
- setProperty(id, Variant.VT_I8, Long.valueOf(value));
+ setProperty(id, Variant.VT_I8, value);
}
@@ -405,7 +407,7 @@ public class Section {
* @see #getProperty
*/
public void setProperty(final int id, final boolean value) {
- setProperty(id, Variant.VT_BOOL, Boolean.valueOf(value));
+ setProperty(id, Variant.VT_BOOL, value);
}
@@ -487,7 +489,7 @@ public class Section {
*
* @return The property's value
*/
- protected int getPropertyIntValue(final long id) {
+ int getPropertyIntValue(final long id) {
final Number i;
final Object o = getProperty(id);
if (o == null) {
@@ -513,9 +515,9 @@ public class Section {
*
* @return The property's value
*/
- protected boolean getPropertyBooleanValue(final int id) {
+ boolean getPropertyBooleanValue(final int id) {
final Boolean b = (Boolean) getProperty(id);
- return b != null && b.booleanValue();
+ return b != null && b;
}
/**
@@ -529,8 +531,9 @@ public class Section {
* @see #getProperty
* @see Variant
*/
+ @SuppressWarnings("unused")
protected void setPropertyBooleanValue(final int id, final boolean value) {
- setProperty(id, Variant.VT_BOOL, Boolean.valueOf(value));
+ setProperty(id, Variant.VT_BOOL, value);
}
/**
@@ -588,6 +591,7 @@ public class Section {
* #getPropertyIntValue} or {@link #getProperty} tried to access a
* property that was not available, else {@code false}.
*/
+ @SuppressWarnings("WeakerAccess")
public boolean wasNull() {
return wasNull;
}
@@ -674,7 +678,7 @@ public class Section {
for (Long id : propIds) {
Property p1 = properties.get(id);
Property p2 = s.properties.get(id);
- if (p1 == null || p2 == null || !p1.equals(p2)) {
+ if (p1 == null || !p1.equals(p2)) {
return false;
}
}
@@ -683,7 +687,7 @@ public class Section {
Map<Long,String> d1 = getDictionary();
Map<Long,String> d2 = s.getDictionary();
- return (d1 == null && d2 == null) || (d1 != null && d2 != null &&
d1.equals(d2));
+ return (d1 == null && d2 == null) || (d1 != null && d1.equals(d2));
}
/**
@@ -691,6 +695,7 @@ public class Section {
*
* @param id The ID of the property to be removed
*/
+ @SuppressWarnings("WeakerAccess")
public void removeProperty(final long id) {
if (properties.remove(id) != null) {
sectionBytes.reset();
@@ -731,60 +736,54 @@ public class Section {
codepage = Property.DEFAULT_CODEPAGE;
}
- /* The properties are written to this stream. */
- final ByteArrayOutputStream propertyStream = new
ByteArrayOutputStream();
+ final int[][] offsets = new int[properties.size()][2];
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final LittleEndianOutputStream leos = new
LittleEndianOutputStream(bos);
- /* The property list is established here. After each property that has
- * been written to "propertyStream", a property list entry is written
to
- * "propertyListStream". */
- final ByteArrayOutputStream propertyListStream = new
ByteArrayOutputStream();
-
- /* Maintain the current position in the list. */
- int position = 0;
-
- /* Increase the position variable by the size of the property list so
- * that it points behind the property list and to the beginning of the
- * properties themselves. */
- position += 2 * LittleEndianConsts.INT_SIZE + getPropertyCount() * 2 *
LittleEndianConsts.INT_SIZE;
+ /* Write the section's length - dummy value, fixed later */
+ leos.writeInt(-1);
- /* Write the properties and the property list into their respective
- * streams: */
- for (Property p : properties.values()) {
- final long id = p.getID();
+ /* Write the section's number of properties: */
+ leos.writeInt(properties.size());
+ int propCnt = 0;
+ for (Property p : properties.values()) {
/* Write the property list entry. */
- LittleEndian.putUInt(id, propertyListStream);
- LittleEndian.putUInt(position, propertyListStream);
+ leos.writeUInt(p.getID());
+ // dummy offset to be fixed later
+ offsets[propCnt++][0] = bos.size();
+ leos.writeInt(-1);
+ }
+
+ /* Write the properties and the property list into their respective
+ * streams: */
+ propCnt = 0;
+ for (Property p : properties.values()) {
+ offsets[propCnt++][1] = bos.size();
/* If the property ID is not equal 0 we write the property and all
* is fine. However, if it equals 0 we have to write the section's
* dictionary which has an implicit type only and an explicit
* value. */
- if (id != 0) {
+ if (p.getID() != 0) {
/* Write the property and update the position to the next
* property. */
- position += p.write(propertyStream, codepage);
+ p.write(bos, codepage);
} else {
- position += writeDictionary(propertyStream, codepage);
+ writeDictionary(bos, codepage);
}
}
- /* Write the section: */
- int streamLength = LittleEndianConsts.INT_SIZE * 2 +
propertyListStream.size() + propertyStream.size();
+ byte[] result = bos.toByteArray();
+ LittleEndian.putInt(result, 0, bos.size());
- /* Write the section's length: */
- LittleEndian.putInt(streamLength, out);
-
- /* Write the section's number of properties: */
- LittleEndian.putInt(getPropertyCount(), out);
-
- /* Write the property list: */
- propertyListStream.writeTo(out);
+ for (int[] off : offsets) {
+ LittleEndian.putUInt(result, off[0], off[1]);
+ }
- /* Write the properties: */
- propertyStream.writeTo(out);
+ out.write(result);
- return streamLength;
+ return bos.size();
}
/**
@@ -795,12 +794,8 @@ public class Section {
* @param codepage The codepage of the string values.
*
* @return {@code true} if dictionary was read successful, {@code false}
otherwise
- *
- * @throws UnsupportedEncodingException if the dictionary's codepage is not
- * (yet) supported.
*/
- private boolean readDictionary(LittleEndianByteArrayInputStream leis,
final int length, final int codepage)
- throws UnsupportedEncodingException {
+ private boolean readDictionary(LittleEndianByteArrayInputStream leis,
final int length, final int codepage) {
Map<Long,String> dic = new HashMap<>();
/*
@@ -863,13 +858,12 @@ public class Section {
*
* @param out The output stream to write to.
* @param codepage The codepage to be used to write the dictionary items.
- * @return The number of bytes written
* @exception IOException if an I/O exception occurs.
*/
- private int writeDictionary(final OutputStream out, final int codepage)
+ private void writeDictionary(final OutputStream out, final int codepage)
throws IOException {
final byte padding[] = new byte[4];
- Map<Long,String> dic = getDictionary();
+ final Map<Long,String> dic = getDictionary();
LittleEndian.putUInt(dic.size(), out);
int length = LittleEndianConsts.INT_SIZE;
@@ -878,26 +872,23 @@ public class Section {
LittleEndian.putUInt(ls.getKey(), out);
length += LittleEndianConsts.INT_SIZE;
- String value = ls.getValue()+"\0";
- LittleEndian.putUInt( value.length(), out );
+ final String value = ls.getValue()+"\0";
+ final byte bytes[] = CodePageUtil.getBytesInCodePage(value,
codepage);
+ final int len = (codepage == CodePageUtil.CP_UNICODE) ?
value.length() : bytes.length;
+
+ LittleEndian.putUInt( len, out );
length += LittleEndianConsts.INT_SIZE;
- byte bytes[] = CodePageUtil.getBytesInCodePage(value, codepage);
out.write(bytes);
length += bytes.length;
- if (codepage == CodePageUtil.CP_UNICODE) {
- int pad = (4 - (length & 0x3)) & 0x3;
- out.write(padding, 0, pad);
- length += pad;
- }
+ final int pad = (codepage == CodePageUtil.CP_UNICODE) ? ((4 -
(length & 0x3)) & 0x3) : 0;
+ out.write(padding, 0, pad);
+ length += pad;
}
- int pad = (4 - (length & 0x3)) & 0x3;
+ final int pad = (4 - (length & 0x3)) & 0x3;
out.write(padding, 0, pad);
- length += pad;
-
- return length;
}
/**
Copied: poi/trunk/src/java/org/apache/poi/poifs/common/package-info.java (from
r1839200, poi/trunk/src/java/org/apache/poi/poifs/common/package.html)
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/common/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/common/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/common/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/common/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/common/package-info.java Sun Aug 26
11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
- ====================================================================
+/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
@@ -15,21 +13,9 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
-common package contains constants and other classes shared across all POIFS
subpackages
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-</body>
-</html>
+/**
+ * common package contains constants and other classes shared across all POIFS
subpackages
+ */
+package org.apache.poi.poifs.common;
\ No newline at end of file
Modified: poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java Sun Aug 26
11:55:00 2018
@@ -27,7 +27,6 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public abstract class Decryptor implements Cloneable {
@@ -87,7 +86,7 @@ public abstract class Decryptor implemen
* @param cipher may be null, otherwise the given instance is reset to the
new block index
* @param block the block index, e.g. the persist/slide id (hslf)
* @return a new cipher object, if cipher was null, otherwise the
reinitialized cipher
- * @throws GeneralSecurityException
+ * @throws GeneralSecurityException if the cipher can't be initialized
*/
public Cipher initCipherForBlock(Cipher cipher, int block)
throws GeneralSecurityException {
@@ -126,10 +125,6 @@ public abstract class Decryptor implemen
return getDataStream(fs.getRoot());
}
- public InputStream getDataStream(OPOIFSFileSystem fs) throws IOException,
GeneralSecurityException {
- return getDataStream(fs.getRoot());
- }
-
public InputStream getDataStream(POIFSFileSystem fs) throws IOException,
GeneralSecurityException {
return getDataStream(fs.getRoot());
}
@@ -147,6 +142,7 @@ public abstract class Decryptor implemen
return integrityHmacKey;
}
+ @SuppressWarnings("unused")
public byte[] getIntegrityHmacValue() {
return integrityHmacValue;
}
@@ -167,6 +163,7 @@ public abstract class Decryptor implemen
this.integrityHmacValue = (integrityHmacValue == null) ? null :
integrityHmacValue.clone();
}
+ @SuppressWarnings("unused")
protected int getBlockSizeInBytes() {
return encryptionInfo.getHeader().getBlockSize();
}
Modified: poi/trunk/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java Sun Aug
26 11:55:00 2018
@@ -27,7 +27,6 @@ import java.io.IOException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
@@ -59,12 +58,14 @@ public class EncryptionInfo implements C
* A value that MUST be 0 if document properties are encrypted.
* The encryption of document properties is specified in section 2.3.5.4.
*/
+ @SuppressWarnings("WeakerAccess")
public static final BitField flagDocProps =
BitFieldFactory.getInstance(0x08);
/**
* A value that MUST be 1 if extensible encryption is used. If this value
is 1,
* the value of every other field in this structure MUST be 0.
*/
+ @SuppressWarnings("WeakerAccess")
public static final BitField flagExternal =
BitFieldFactory.getInstance(0x10);
/**
@@ -84,13 +85,6 @@ public class EncryptionInfo implements C
/**
* Opens for decryption
*/
- public EncryptionInfo(OPOIFSFileSystem fs) throws IOException {
- this(fs.getRoot());
- }
-
- /**
- * Opens for decryption
- */
public EncryptionInfo(NPOIFSFileSystem fs) throws IOException {
this(fs.getRoot());
}
@@ -167,11 +161,11 @@ public class EncryptionInfo implements C
*
* @param encryptionMode see {@link EncryptionMode} for values, {@link
EncryptionMode#cryptoAPI} is for
* internal use only, as it's record based
- * @param cipherAlgorithm
- * @param hashAlgorithm
- * @param keyBits
- * @param blockSize
- * @param chainingMode
+ * @param cipherAlgorithm the cipher algorithm
+ * @param hashAlgorithm the hash algorithm
+ * @param keyBits the bit count of the key
+ * @param blockSize the size of a cipher block
+ * @param chainingMode the chaining mode
*
* @throws EncryptedDocumentException if the given parameters mismatch,
e.g. only certain combinations
* of keyBits, blockSize are allowed for a given {@link CipherAlgorithm}
@@ -211,10 +205,11 @@ public class EncryptionInfo implements C
*
* @param encryptionMode the encryption mode
* @return an encryption info builder
- * @throws ClassNotFoundException
- * @throws IllegalAccessException
- * @throws InstantiationException
+ * @throws ClassNotFoundException if the builder class is not on the
classpath
+ * @throws IllegalAccessException if the builder class can't be loaded
+ * @throws InstantiationException if the builder class can't be loaded
*/
+ @SuppressWarnings("WeakerAccess")
protected static EncryptionInfoBuilder getBuilder(EncryptionMode
encryptionMode)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
ClassLoader cl = EncryptionInfo.class.getClassLoader();
Modified: poi/trunk/src/java/org/apache/poi/poifs/crypt/Encryptor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/Encryptor.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/crypt/Encryptor.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/crypt/Encryptor.java Sun Aug 26
11:55:00 2018
@@ -26,7 +26,6 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public abstract class Encryptor implements Cloneable {
@@ -55,9 +54,6 @@ public abstract class Encryptor implemen
public OutputStream getDataStream(NPOIFSFileSystem fs) throws IOException,
GeneralSecurityException {
return getDataStream(fs.getRoot());
}
- public OutputStream getDataStream(OPOIFSFileSystem fs) throws IOException,
GeneralSecurityException {
- return getDataStream(fs.getRoot());
- }
public OutputStream getDataStream(POIFSFileSystem fs) throws IOException,
GeneralSecurityException {
return getDataStream(fs.getRoot());
}
Copied: poi/trunk/src/java/org/apache/poi/poifs/crypt/package-info.java (from
r1839200, poi/trunk/src/java/org/apache/poi/poifs/crypt/package.html)
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/crypt/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/crypt/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/crypt/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/crypt/package-info.java Sun Aug 26
11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
- ====================================================================
+/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
@@ -15,30 +13,23 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
-<p>Implementation of the <a
href="http://msdn.microsoft.com/en-us/library/dd952186(v=office.12).aspx">ECMA-376
Document Encryption</a></p>
-<p>The implementation is split into three packages:</p>
-<ul>
-<li>This package contains common functions for both current implemented cipher
modes.</li>
-<li>the {@link org.apache.poi.poifs.crypt.standard standard} package is part
of the base poi jar and contains classes for the standard encryption ...</li>
-<li>the {@link org.apache.poi.poifs.crypt.agile agile} package is part of the
poi ooxml jar and the provides agile encryption support.</li>
-</ul>
-
-<h2>Related Documentation</h2>
-
-Some implementations informations can be found under:
-<ul>
-<li><a href="http://poi.apache.org/encryption.html">Apache POI - Encryption
support</a>
-</ul>
-
-<!-- Put @see and @since tags down here. -->
-@see org.apache.poi.poifs.crypt.standard
-@see org.apache.poi.poifs.crypt.agile
-</body>
-</html>
+/**
+ * Implementation of the ECMA-376 and MS-propritary document encryptions<p>
+ *
+ * The implementation is split into the following packages:<p>
+ *
+ * <ul>
+ * <li>This package contains common functions for both current implemented
cipher modes.</li>
+ * <li>the {@link org.apache.poi.poifs.crypt.agile agile} package is part of
the poi ooxml jar and the provides agile encryption support.</li>
+ * <li>the {@link org.apache.poi.poifs.crypt.binaryrc4 binaryrc} package is
used for the fixed length RC4 encryption of biff/H**F formats</li>
+ * <li>the {@link org.apache.poi.poifs.crypt.cryptoapi cryptoapi} package is
used for the variable length RC encryption of biff/H**F formats</li>
+ * <li>the {@link org.apache.poi.poifs.crypt.standard standard} package
contains classes for the standard encryption ...</li>
+ * <li>the {@link org.apache.poi.poifs.crypt.xor xor} package contains classes
for the xor obfuscation of biff/H**F formats</li>
+ * </ul>
+ *
+ * @see <a href="http://poi.apache.org/encryption.html">Apache POI -
Encryption support</a>
+ * @see <a
href="http://msdn.microsoft.com/en-us/library/dd952186(v=office.12).aspx">ECMA-376
Document Encryption</a>
+ */
+package org.apache.poi.poifs.crypt;
\ No newline at end of file
Copied: poi/trunk/src/java/org/apache/poi/poifs/dev/package-info.java (from
r1839200, poi/trunk/src/java/org/apache/poi/poifs/dev/package.html)
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/dev/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/dev/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/dev/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/dev/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/dev/package-info.java Sun Aug 26
11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
- ====================================================================
+/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
@@ -15,22 +13,14 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
-DEV package serves two purposes. 1. Examples for how to use POIFS and 2.
tools for developing
-and validating POIFS.
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-</body>
-</html>
+/**
+ * DEV package serves two purposes.
+ *
+ * <ol>
+ * <li>Examples for how to use POIFS</li>
+ * <li>tools for developing and validating POIFS</li>
+ * </ol>
+ */
+package org.apache.poi.poifs.dev;
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]