diff options
Diffstat (limited to 'src/ooxml/java/org')
8 files changed, 25 insertions, 46 deletions
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index 767abc239d..1a4bef5939 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -293,6 +293,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { * @return A PackageBase object * * @throws InvalidFormatException + * Throws if the specified file exist and is not valid. + * @throws IOException If reading the stream fails */ public static OPCPackage open(InputStream in) throws InvalidFormatException, IOException { @@ -1466,14 +1468,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { } // Do the save - FileOutputStream fos = null; - try { - fos = new FileOutputStream(targetFile); + try (FileOutputStream fos = new FileOutputStream(targetFile)) { this.save(fos); - } finally { - if (fos != null) { - fos.close(); - } } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java index baee7e2abd..8bcfb33e92 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java @@ -161,7 +161,7 @@ public final class PackagePartName implements Comparable<PackagePartName> { * * @param partUri * The part name to check. - * @throws Exception + * @throws InvalidFormatException * Throws if the part name is invalid. */ private static void throwExceptionIfInvalidPartUri(URI partUri) @@ -513,7 +513,7 @@ public final class PackagePartName implements Comparable<PackagePartName> { * (lexigraphical sort) * * @param str1 first string to compare - * @param str1 second string to compare + * @param str2 second string to compare * @return a negative integer, zero, or a positive integer as the first argument is less than, * equal to, or greater than the second. */ diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java index 174f2f901b..9f82d512fa 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java @@ -210,18 +210,11 @@ public final class PackageRelationship { @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(id == null ? "id=null" : "id=" + id); - sb.append(container == null ? " - container=null" : " - container=" - + container); - sb.append(relationshipType == null ? " - relationshipType=null" - : " - relationshipType=" + relationshipType); - sb.append(source == null ? " - source=null" : " - source=" - + getSourceURI().toASCIIString()); - sb.append(targetUri == null ? " - target=null" : " - target=" - + getTargetURI().toASCIIString()); - sb.append(targetMode == null ? ",targetMode=null" : ",targetMode=" - + targetMode); - return sb.toString(); + return (id == null ? "id=null" : "id=" + id) + + (container == null ? " - container=null" : " - container=" + container) + + (relationshipType == null ? " - relationshipType=null" : " - relationshipType=" + relationshipType) + + (source == null ? " - source=null" : " - source=" + getSourceURI().toASCIIString()) + + (targetUri == null ? " - target=null" : " - target=" + getTargetURI().toASCIIString()) + + (targetMode == null ? ",targetMode=null" : ",targetMode=" + targetMode); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java index 5a8db38ff0..b5da3d9bcb 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java @@ -48,32 +48,32 @@ public final class PackagingURIHelper { /** * Extension name of a relationship part. */ - public static final String RELATIONSHIP_PART_EXTENSION_NAME; + public static final String RELATIONSHIP_PART_EXTENSION_NAME = ".rels"; /** * Segment name of a relationship part. */ - public static final String RELATIONSHIP_PART_SEGMENT_NAME; + public static final String RELATIONSHIP_PART_SEGMENT_NAME = "_rels"; /** * Segment name of the package properties folder. */ - public static final String PACKAGE_PROPERTIES_SEGMENT_NAME; + public static final String PACKAGE_PROPERTIES_SEGMENT_NAME = "docProps"; /** * Core package properties art name. */ - public static final String PACKAGE_CORE_PROPERTIES_NAME; + public static final String PACKAGE_CORE_PROPERTIES_NAME = "core.xml"; /** * Forward slash URI separator. */ - public static final char FORWARD_SLASH_CHAR; + public static final char FORWARD_SLASH_CHAR = '/'; /** * Forward slash URI separator. */ - public static final String FORWARD_SLASH_STRING; + public static final String FORWARD_SLASH_STRING = "/"; /** * Package relationships part URI @@ -107,13 +107,6 @@ public final class PackagingURIHelper { /* Static initialization */ static { - RELATIONSHIP_PART_SEGMENT_NAME = "_rels"; - RELATIONSHIP_PART_EXTENSION_NAME = ".rels"; - FORWARD_SLASH_CHAR = '/'; - FORWARD_SLASH_STRING = "/"; - PACKAGE_PROPERTIES_SEGMENT_NAME = "docProps"; - PACKAGE_CORE_PROPERTIES_NAME = "core.xml"; - // Make URI URI uriPACKAGE_ROOT_URI = null; URI uriPACKAGE_RELATIONSHIPS_ROOT_URI = null; diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index ecec63ce9f..f31808f697 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -94,7 +94,7 @@ public final class ZipPackage extends OPCPackage { * @param access * The package access mode. * @throws IllegalArgumentException - * If the specified input stream not an instance of + * If the specified input stream is not an instance of * ZipInputStream. * @throws IOException * if input stream cannot be opened, read, or closed diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java index 43449b20a9..ec4a1a2080 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java @@ -92,7 +92,7 @@ public final class ContentType { * * CHAR = <any US-ASCII character (octets 0 - 127)> */ - String token = "[\\x21-\\x7E&&[^\\(\\)<>@,;:\\\\/\"\\[\\]\\?={}\\x20\\x09]]"; + String token = "[\\x21-\\x7E&&[^()<>@,;:\\\\/\"\\[\\]?={}\\x20\\x09]]"; /* * parameter = attribute "=" value @@ -248,7 +248,7 @@ public final class ContentType { public String[] getParameterKeys() { if (parameters == null) return new String[0]; - return parameters.keySet().toArray(new String[parameters.size()]); + return parameters.keySet().toArray(new String[0]); } /** diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/FileHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/FileHelper.java index b1e8192d52..44e3766eb1 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/FileHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/FileHelper.java @@ -69,7 +69,6 @@ public final class FileHelper { FileChannel destinationChannel = fos.getChannel()) { sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel); - sourceChannel.close(); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PartUnmarshaller.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PartUnmarshaller.java index e5487a6381..b3f74323f3 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PartUnmarshaller.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PartUnmarshaller.java @@ -26,7 +26,7 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext; /** - * Object implemented this interface are considered as part unmarshaller. A part + * Classes implementing this interface are considered as part unmarshaller. A part * unmarshaller is responsible to unmarshall a part in order to load it from a * package. * @@ -38,12 +38,10 @@ public interface PartUnmarshaller { /** * Save the content of the package in the stream * - * @param in - * The input stream from which the part will be unmarshall. - * @return The part freshly unmarshall from the input stream. - * @throws OpenXML4JException - * Throws only if any other exceptions are thrown by inner - * methods. + * @param in The input stream from which the part will be read. + * @return The part freshly read from the input stream. + * @throws InvalidFormatException If the data can not be interpreted correctly + * @throws IOException if reading from the stream fails */ public PackagePart unmarshall(UnmarshallContext context, InputStream in) throws InvalidFormatException, IOException; |