This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push: new 9c798f58 Sort members 9c798f58 is described below commit 9c798f58077dbfb73224a78fad64e22d2fd18de8 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Dec 7 20:29:32 2022 -0500 Sort members --- .../archivers/sevenz/SevenZArchiveEntry.java | 664 ++++++++++----------- .../commons/compress/archivers/zip/X000A_NTFS.java | 452 +++++++------- 2 files changed, 558 insertions(+), 558 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java index 5cc82cf4..5ea2fe92 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java @@ -35,6 +35,30 @@ import org.apache.commons.compress.utils.TimeUtils; * @since 1.6 */ public class SevenZArchiveEntry implements ArchiveEntry { + static final SevenZArchiveEntry[] EMPTY_SEVEN_Z_ARCHIVE_ENTRY_ARRAY = new SevenZArchiveEntry[0]; + /** + * Converts Java time to NTFS time. + * @param date the Java time + * @return the NTFS time + * @deprecated Use {@link TimeUtils#toNtfsTime(Date)} instead. + * @see TimeUtils#toNtfsTime(Date) + */ + @Deprecated + public static long javaTimeToNtfsTime(final Date date) { + return TimeUtils.toNtfsTime(date); + } + /** + * Converts NTFS time (100 nanosecond units since 1 January 1601) + * to Java time. + * @param ntfsTime the NTFS time in 100 nanosecond units + * @return the Java time + * @deprecated Use {@link TimeUtils#ntfsTimeToDate(long)} instead. + * @see TimeUtils#ntfsTimeToDate(long) + */ + @Deprecated + public static Date ntfsTimeToJavaTime(final long ntfsTime) { + return TimeUtils.ntfsTimeToDate(ntfsTime); + } private String name; private boolean hasStream; private boolean isDirectory; @@ -49,101 +73,154 @@ public class SevenZArchiveEntry implements ArchiveEntry { private int windowsAttributes; private boolean hasCrc; private long crc, compressedCrc; + private long size, compressedSize; + private Iterable<? extends SevenZMethodConfiguration> contentMethods; - static final SevenZArchiveEntry[] EMPTY_SEVEN_Z_ARCHIVE_ENTRY_ARRAY = new SevenZArchiveEntry[0]; public SevenZArchiveEntry() { } - /** - * Get this entry's name. - * - * <p>This method returns the raw name as it is stored inside of the archive.</p> - * - * @return This entry's name. - */ @Override - public String getName() { - return name; + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final SevenZArchiveEntry other = (SevenZArchiveEntry) obj; + return + Objects.equals(name, other.name) && + hasStream == other.hasStream && + isDirectory == other.isDirectory && + isAntiItem == other.isAntiItem && + hasCreationDate == other.hasCreationDate && + hasLastModifiedDate == other.hasLastModifiedDate && + hasAccessDate == other.hasAccessDate && + Objects.equals(creationDate, other.creationDate) && + Objects.equals(lastModifiedDate, other.lastModifiedDate) && + Objects.equals(accessDate, other.accessDate) && + hasWindowsAttributes == other.hasWindowsAttributes && + windowsAttributes == other.windowsAttributes && + hasCrc == other.hasCrc && + crc == other.crc && + compressedCrc == other.compressedCrc && + size == other.size && + compressedSize == other.compressedSize && + equalSevenZMethods(contentMethods, other.contentMethods); } - /** - * Set this entry's name. - * - * @param name This entry's new name. - */ - public void setName(final String name) { - this.name = name; + private boolean equalSevenZMethods(final Iterable<? extends SevenZMethodConfiguration> c1, + final Iterable<? extends SevenZMethodConfiguration> c2) { + if (c1 == null) { + return c2 == null; + } + if (c2 == null) { + return false; + } + final Iterator<? extends SevenZMethodConfiguration> i2 = c2.iterator(); + for (SevenZMethodConfiguration element : c1) { + if (!i2.hasNext()) { + return false; + } + if (!element.equals(i2.next())) { + return false; + } + } + return !i2.hasNext(); } /** - * Whether there is any content associated with this entry. - * @return whether there is any content associated with this entry. + * Gets the access date. + * This is equivalent to {@link SevenZArchiveEntry#getAccessTime()}, but precision is truncated to milliseconds. + * + * @throws UnsupportedOperationException if the entry hasn't got an access date. + * @return the access date + * @see SevenZArchiveEntry#getAccessTime() */ - public boolean hasStream() { - return hasStream; + public Date getAccessDate() { + return TimeUtils.toDate(getAccessTime()); } /** - * Sets whether there is any content associated with this entry. - * @param hasStream whether there is any content associated with this entry. + * Gets the access time. + * + * @throws UnsupportedOperationException if the entry hasn't got an access time. + * @return the access time + * @since 1.23 */ - public void setHasStream(final boolean hasStream) { - this.hasStream = hasStream; + public FileTime getAccessTime() { + if (hasAccessDate) { + return accessDate; + } + throw new UnsupportedOperationException( + "The entry doesn't have this timestamp"); } /** - * Return whether or not this entry represents a directory. - * - * @return True if this entry is a directory. + * Gets the compressed CRC. + * @deprecated use getCompressedCrcValue instead. + * @return the compressed CRC */ - @Override - public boolean isDirectory() { - return isDirectory; + @Deprecated + int getCompressedCrc() { + return (int) compressedCrc; } /** - * Sets whether or not this entry represents a directory. - * - * @param isDirectory True if this entry is a directory. + * Gets the compressed CRC. + * @since 1.7 + * @return the CRC */ - public void setDirectory(final boolean isDirectory) { - this.isDirectory = isDirectory; + long getCompressedCrcValue() { + return compressedCrc; } /** - * Indicates whether this is an "anti-item" used in differential backups, - * meaning it should delete the same file from a previous backup. - * @return true if it is an anti-item, false otherwise + * Get this entry's compressed file size. + * + * @return This entry's compressed file size. */ - public boolean isAntiItem() { - return isAntiItem; + long getCompressedSize() { + return compressedSize; } /** - * Sets whether this is an "anti-item" used in differential backups, - * meaning it should delete the same file from a previous backup. - * @param isAntiItem true if it is an anti-item, false otherwise + * Gets the (compression) methods to use for entry's content - the + * default is LZMA2. + * + * <p>Currently only {@link SevenZMethod#COPY}, {@link + * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link + * SevenZMethod#DEFLATE} are supported when writing archives.</p> + * + * <p>The methods will be consulted in iteration order to create + * the final output.</p> + * + * @since 1.8 + * @return the methods to use for the content */ - public void setAntiItem(final boolean isAntiItem) { - this.isAntiItem = isAntiItem; + public Iterable<? extends SevenZMethodConfiguration> getContentMethods() { + return contentMethods; } /** - * Returns whether this entry has got a creation date at all. - * @return whether the entry has got a creation date + * Gets the CRC. + * @deprecated use getCrcValue instead. + * @return the CRC */ - public boolean getHasCreationDate() { - return hasCreationDate; + @Deprecated + public int getCrc() { + return (int) crc; } /** - * Sets whether this entry has got a creation date at all. - * @param hasCreationDate whether the entry has got a creation date + * Gets the CRC. + * @since 1.7 + * @return the CRC */ - public void setHasCreationDate(final boolean hasCreationDate) { - this.hasCreationDate = hasCreationDate; + public long getCrcValue() { + return crc; } /** @@ -174,35 +251,29 @@ public class SevenZArchiveEntry implements ArchiveEntry { } /** - * Sets the creation date using NTFS time (100 nanosecond units - * since 1 January 1601) - * @param ntfsCreationDate the creation date + * Returns whether this entry has got an access date at all. + * @return whether this entry has got an access date at all. */ - public void setCreationDate(final long ntfsCreationDate) { - this.creationDate = TimeUtils.ntfsTimeToFileTime(ntfsCreationDate); + public boolean getHasAccessDate() { + return hasAccessDate; } /** - * Sets the creation date. + * Returns whether this entry has got a crc. * - * @param creationDate the new creation date - * @see SevenZArchiveEntry#setCreationTime(FileTime) + * <p>In general entries without streams don't have a CRC either.</p> + * @return whether this entry has got a crc. */ - public void setCreationDate(final Date creationDate) { - setCreationTime(TimeUtils.toFileTime(creationDate)); + public boolean getHasCrc() { + return hasCrc; } /** - * Sets the creation time. - * - * @param time the new creation time - * @since 1.23 + * Returns whether this entry has got a creation date at all. + * @return whether the entry has got a creation date */ - public void setCreationTime(final FileTime time) { - hasCreationDate = time != null; - if (hasCreationDate) { - this.creationDate = time; - } + public boolean getHasCreationDate() { + return hasCreationDate; } /** @@ -214,12 +285,11 @@ public class SevenZArchiveEntry implements ArchiveEntry { } /** - * Sets whether this entry has got a last modified date at all. - * @param hasLastModifiedDate whether this entry has got a last - * modified date at all + * Returns whether this entry has windows attributes. + * @return whether this entry has windows attributes. */ - public void setHasLastModifiedDate(final boolean hasLastModifiedDate) { - this.hasLastModifiedDate = hasLastModifiedDate; + public boolean getHasWindowsAttributes() { + return hasWindowsAttributes; } /** @@ -251,78 +321,76 @@ public class SevenZArchiveEntry implements ArchiveEntry { } /** - * Sets the last modified date using NTFS time (100 nanosecond - * units since 1 January 1601) - * @param ntfsLastModifiedDate the last modified date + * Get this entry's name. + * + * <p>This method returns the raw name as it is stored inside of the archive.</p> + * + * @return This entry's name. */ - public void setLastModifiedDate(final long ntfsLastModifiedDate) { - this.lastModifiedDate = TimeUtils.ntfsTimeToFileTime(ntfsLastModifiedDate); + @Override + public String getName() { + return name; } /** - * Sets the last modified date. + * Get this entry's file size. * - * @param lastModifiedDate the new last modified date - * @see SevenZArchiveEntry#setLastModifiedTime(FileTime) + * @return This entry's file size. */ - public void setLastModifiedDate(final Date lastModifiedDate) { - setLastModifiedTime(TimeUtils.toFileTime(lastModifiedDate)); + @Override + public long getSize() { + return size; } /** - * Sets the last modified time. - * - * @param time the new last modified time - * @since 1.23 + * Gets the windows attributes. + * @return the windows attributes */ - public void setLastModifiedTime(final FileTime time) { - hasLastModifiedDate = time != null; - if (hasLastModifiedDate) { - this.lastModifiedDate = time; - } + public int getWindowsAttributes() { + return windowsAttributes; + } + + @Override + public int hashCode() { + final String n = getName(); + return n == null ? 0 : n.hashCode(); } /** - * Returns whether this entry has got an access date at all. - * @return whether this entry has got an access date at all. + * Whether there is any content associated with this entry. + * @return whether there is any content associated with this entry. */ - public boolean getHasAccessDate() { - return hasAccessDate; + public boolean hasStream() { + return hasStream; } /** - * Sets whether this entry has got an access date at all. - * @param hasAcessDate whether this entry has got an access date at all. + * Indicates whether this is an "anti-item" used in differential backups, + * meaning it should delete the same file from a previous backup. + * @return true if it is an anti-item, false otherwise */ - public void setHasAccessDate(final boolean hasAcessDate) { - this.hasAccessDate = hasAcessDate; + public boolean isAntiItem() { + return isAntiItem; } /** - * Gets the access date. - * This is equivalent to {@link SevenZArchiveEntry#getAccessTime()}, but precision is truncated to milliseconds. + * Return whether or not this entry represents a directory. * - * @throws UnsupportedOperationException if the entry hasn't got an access date. - * @return the access date - * @see SevenZArchiveEntry#getAccessTime() + * @return True if this entry is a directory. */ - public Date getAccessDate() { - return TimeUtils.toDate(getAccessTime()); + @Override + public boolean isDirectory() { + return isDirectory; } /** - * Gets the access time. + * Sets the access date. * - * @throws UnsupportedOperationException if the entry hasn't got an access time. - * @return the access time - * @since 1.23 + * @param accessDate the new access date + * @see SevenZArchiveEntry#setAccessTime(FileTime) */ - public FileTime getAccessTime() { - if (hasAccessDate) { - return accessDate; - } - throw new UnsupportedOperationException( - "The entry doesn't have this timestamp"); + public void setAccessDate(final Date accessDate) { + setAccessTime(TimeUtils.toFileTime(accessDate)); } /** @@ -334,16 +402,6 @@ public class SevenZArchiveEntry implements ArchiveEntry { this.accessDate = TimeUtils.ntfsTimeToFileTime(ntfsAccessDate); } - /** - * Sets the access date. - * - * @param accessDate the new access date - * @see SevenZArchiveEntry#setAccessTime(FileTime) - */ - public void setAccessDate(final Date accessDate) { - setAccessTime(TimeUtils.toFileTime(accessDate)); - } - /** * Sets the access time. * @@ -358,63 +416,82 @@ public class SevenZArchiveEntry implements ArchiveEntry { } /** - * Returns whether this entry has windows attributes. - * @return whether this entry has windows attributes. - */ - public boolean getHasWindowsAttributes() { - return hasWindowsAttributes; - } - - /** - * Sets whether this entry has windows attributes. - * @param hasWindowsAttributes whether this entry has windows attributes. + * Sets whether this is an "anti-item" used in differential backups, + * meaning it should delete the same file from a previous backup. + * @param isAntiItem true if it is an anti-item, false otherwise */ - public void setHasWindowsAttributes(final boolean hasWindowsAttributes) { - this.hasWindowsAttributes = hasWindowsAttributes; + public void setAntiItem(final boolean isAntiItem) { + this.isAntiItem = isAntiItem; } /** - * Gets the windows attributes. - * @return the windows attributes + * Sets the compressed CRC. + * @deprecated use setCompressedCrcValue instead. + * @param crc the CRC */ - public int getWindowsAttributes() { - return windowsAttributes; + @Deprecated + void setCompressedCrc(final int crc) { + this.compressedCrc = crc; } /** - * Sets the windows attributes. - * @param windowsAttributes the windows attributes + * Sets the compressed CRC. + * @since 1.7 + * @param crc the CRC */ - public void setWindowsAttributes(final int windowsAttributes) { - this.windowsAttributes = windowsAttributes; + void setCompressedCrcValue(final long crc) { + this.compressedCrc = crc; } /** - * Returns whether this entry has got a crc. + * Set this entry's compressed file size. * - * <p>In general entries without streams don't have a CRC either.</p> - * @return whether this entry has got a crc. + * @param size This entry's new compressed file size. */ - public boolean getHasCrc() { - return hasCrc; + void setCompressedSize(final long size) { + this.compressedSize = size; } /** - * Sets whether this entry has got a crc. - * @param hasCrc whether this entry has got a crc. + * Sets the (compression) methods to use for entry's content - the + * default is LZMA2. + * + * <p>Currently only {@link SevenZMethod#COPY}, {@link + * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link + * SevenZMethod#DEFLATE} are supported when writing archives.</p> + * + * <p>The methods will be consulted in iteration order to create + * the final output.</p> + * + * @param methods the methods to use for the content + * @since 1.8 */ - public void setHasCrc(final boolean hasCrc) { - this.hasCrc = hasCrc; + public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods) { + if (methods != null) { + final LinkedList<SevenZMethodConfiguration> l = new LinkedList<>(); + methods.forEach(l::addLast); + contentMethods = Collections.unmodifiableList(l); + } else { + contentMethods = null; + } } /** - * Gets the CRC. - * @deprecated use getCrcValue instead. - * @return the CRC + * Sets the (compression) methods to use for entry's content - the + * default is LZMA2. + * + * <p>Currently only {@link SevenZMethod#COPY}, {@link + * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link + * SevenZMethod#DEFLATE} are supported when writing archives.</p> + * + * <p>The methods will be consulted in iteration order to create + * the final output.</p> + * + * @param methods the methods to use for the content + * @since 1.22 */ - @Deprecated - public int getCrc() { - return (int) crc; + public void setContentMethods(SevenZMethodConfiguration... methods) { + setContentMethods(Arrays.asList(methods)); } /** @@ -427,15 +504,6 @@ public class SevenZArchiveEntry implements ArchiveEntry { this.crc = crc; } - /** - * Gets the CRC. - * @since 1.7 - * @return the CRC - */ - public long getCrcValue() { - return crc; - } - /** * Sets the CRC. * @since 1.7 @@ -446,218 +514,150 @@ public class SevenZArchiveEntry implements ArchiveEntry { } /** - * Gets the compressed CRC. - * @deprecated use getCompressedCrcValue instead. - * @return the compressed CRC + * Sets the creation date. + * + * @param creationDate the new creation date + * @see SevenZArchiveEntry#setCreationTime(FileTime) */ - @Deprecated - int getCompressedCrc() { - return (int) compressedCrc; + public void setCreationDate(final Date creationDate) { + setCreationTime(TimeUtils.toFileTime(creationDate)); } /** - * Sets the compressed CRC. - * @deprecated use setCompressedCrcValue instead. - * @param crc the CRC + * Sets the creation date using NTFS time (100 nanosecond units + * since 1 January 1601) + * @param ntfsCreationDate the creation date */ - @Deprecated - void setCompressedCrc(final int crc) { - this.compressedCrc = crc; + public void setCreationDate(final long ntfsCreationDate) { + this.creationDate = TimeUtils.ntfsTimeToFileTime(ntfsCreationDate); } /** - * Gets the compressed CRC. - * @since 1.7 - * @return the CRC + * Sets the creation time. + * + * @param time the new creation time + * @since 1.23 */ - long getCompressedCrcValue() { - return compressedCrc; + public void setCreationTime(final FileTime time) { + hasCreationDate = time != null; + if (hasCreationDate) { + this.creationDate = time; + } } /** - * Sets the compressed CRC. - * @since 1.7 - * @param crc the CRC + * Sets whether or not this entry represents a directory. + * + * @param isDirectory True if this entry is a directory. */ - void setCompressedCrcValue(final long crc) { - this.compressedCrc = crc; + public void setDirectory(final boolean isDirectory) { + this.isDirectory = isDirectory; } /** - * Get this entry's file size. - * - * @return This entry's file size. + * Sets whether this entry has got an access date at all. + * @param hasAcessDate whether this entry has got an access date at all. */ - @Override - public long getSize() { - return size; + public void setHasAccessDate(final boolean hasAcessDate) { + this.hasAccessDate = hasAcessDate; } /** - * Set this entry's file size. - * - * @param size This entry's new file size. + * Sets whether this entry has got a crc. + * @param hasCrc whether this entry has got a crc. */ - public void setSize(final long size) { - this.size = size; + public void setHasCrc(final boolean hasCrc) { + this.hasCrc = hasCrc; } /** - * Get this entry's compressed file size. - * - * @return This entry's compressed file size. + * Sets whether this entry has got a creation date at all. + * @param hasCreationDate whether the entry has got a creation date */ - long getCompressedSize() { - return compressedSize; + public void setHasCreationDate(final boolean hasCreationDate) { + this.hasCreationDate = hasCreationDate; } /** - * Set this entry's compressed file size. - * - * @param size This entry's new compressed file size. + * Sets whether this entry has got a last modified date at all. + * @param hasLastModifiedDate whether this entry has got a last + * modified date at all */ - void setCompressedSize(final long size) { - this.compressedSize = size; + public void setHasLastModifiedDate(final boolean hasLastModifiedDate) { + this.hasLastModifiedDate = hasLastModifiedDate; } /** - * Sets the (compression) methods to use for entry's content - the - * default is LZMA2. - * - * <p>Currently only {@link SevenZMethod#COPY}, {@link - * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link - * SevenZMethod#DEFLATE} are supported when writing archives.</p> - * - * <p>The methods will be consulted in iteration order to create - * the final output.</p> - * - * @param methods the methods to use for the content - * @since 1.8 + * Sets whether there is any content associated with this entry. + * @param hasStream whether there is any content associated with this entry. */ - public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods) { - if (methods != null) { - final LinkedList<SevenZMethodConfiguration> l = new LinkedList<>(); - methods.forEach(l::addLast); - contentMethods = Collections.unmodifiableList(l); - } else { - contentMethods = null; - } + public void setHasStream(final boolean hasStream) { + this.hasStream = hasStream; } /** - * Sets the (compression) methods to use for entry's content - the - * default is LZMA2. - * - * <p>Currently only {@link SevenZMethod#COPY}, {@link - * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link - * SevenZMethod#DEFLATE} are supported when writing archives.</p> - * - * <p>The methods will be consulted in iteration order to create - * the final output.</p> - * - * @param methods the methods to use for the content - * @since 1.22 + * Sets whether this entry has windows attributes. + * @param hasWindowsAttributes whether this entry has windows attributes. */ - public void setContentMethods(SevenZMethodConfiguration... methods) { - setContentMethods(Arrays.asList(methods)); + public void setHasWindowsAttributes(final boolean hasWindowsAttributes) { + this.hasWindowsAttributes = hasWindowsAttributes; } /** - * Gets the (compression) methods to use for entry's content - the - * default is LZMA2. - * - * <p>Currently only {@link SevenZMethod#COPY}, {@link - * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link - * SevenZMethod#DEFLATE} are supported when writing archives.</p> - * - * <p>The methods will be consulted in iteration order to create - * the final output.</p> + * Sets the last modified date. * - * @since 1.8 - * @return the methods to use for the content + * @param lastModifiedDate the new last modified date + * @see SevenZArchiveEntry#setLastModifiedTime(FileTime) */ - public Iterable<? extends SevenZMethodConfiguration> getContentMethods() { - return contentMethods; + public void setLastModifiedDate(final Date lastModifiedDate) { + setLastModifiedTime(TimeUtils.toFileTime(lastModifiedDate)); } - @Override - public int hashCode() { - final String n = getName(); - return n == null ? 0 : n.hashCode(); + /** + * Sets the last modified date using NTFS time (100 nanosecond + * units since 1 January 1601) + * @param ntfsLastModifiedDate the last modified date + */ + public void setLastModifiedDate(final long ntfsLastModifiedDate) { + this.lastModifiedDate = TimeUtils.ntfsTimeToFileTime(ntfsLastModifiedDate); } - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; + /** + * Sets the last modified time. + * + * @param time the new last modified time + * @since 1.23 + */ + public void setLastModifiedTime(final FileTime time) { + hasLastModifiedDate = time != null; + if (hasLastModifiedDate) { + this.lastModifiedDate = time; } - final SevenZArchiveEntry other = (SevenZArchiveEntry) obj; - return - Objects.equals(name, other.name) && - hasStream == other.hasStream && - isDirectory == other.isDirectory && - isAntiItem == other.isAntiItem && - hasCreationDate == other.hasCreationDate && - hasLastModifiedDate == other.hasLastModifiedDate && - hasAccessDate == other.hasAccessDate && - Objects.equals(creationDate, other.creationDate) && - Objects.equals(lastModifiedDate, other.lastModifiedDate) && - Objects.equals(accessDate, other.accessDate) && - hasWindowsAttributes == other.hasWindowsAttributes && - windowsAttributes == other.windowsAttributes && - hasCrc == other.hasCrc && - crc == other.crc && - compressedCrc == other.compressedCrc && - size == other.size && - compressedSize == other.compressedSize && - equalSevenZMethods(contentMethods, other.contentMethods); } /** - * Converts NTFS time (100 nanosecond units since 1 January 1601) - * to Java time. - * @param ntfsTime the NTFS time in 100 nanosecond units - * @return the Java time - * @deprecated Use {@link TimeUtils#ntfsTimeToDate(long)} instead. - * @see TimeUtils#ntfsTimeToDate(long) + * Set this entry's name. + * + * @param name This entry's new name. */ - @Deprecated - public static Date ntfsTimeToJavaTime(final long ntfsTime) { - return TimeUtils.ntfsTimeToDate(ntfsTime); + public void setName(final String name) { + this.name = name; } /** - * Converts Java time to NTFS time. - * @param date the Java time - * @return the NTFS time - * @deprecated Use {@link TimeUtils#toNtfsTime(Date)} instead. - * @see TimeUtils#toNtfsTime(Date) + * Set this entry's file size. + * + * @param size This entry's new file size. */ - @Deprecated - public static long javaTimeToNtfsTime(final Date date) { - return TimeUtils.toNtfsTime(date); + public void setSize(final long size) { + this.size = size; } - private boolean equalSevenZMethods(final Iterable<? extends SevenZMethodConfiguration> c1, - final Iterable<? extends SevenZMethodConfiguration> c2) { - if (c1 == null) { - return c2 == null; - } - if (c2 == null) { - return false; - } - final Iterator<? extends SevenZMethodConfiguration> i2 = c2.iterator(); - for (SevenZMethodConfiguration element : c1) { - if (!i2.hasNext()) { - return false; - } - if (!element.equals(i2.next())) { - return false; - } - } - return !i2.hasNext(); + /** + * Sets the windows attributes. + * @param windowsAttributes the windows attributes + */ + public void setWindowsAttributes(final int windowsAttributes) { + this.windowsAttributes = windowsAttributes; } } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java b/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java index c3ca7525..30a91200 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java @@ -72,32 +72,89 @@ public class X000A_NTFS implements ZipExtraField { private static final ZipShort TIME_ATTR_TAG = new ZipShort(0x0001); private static final ZipShort TIME_ATTR_SIZE = new ZipShort(3 * 8); + private static ZipEightByteInteger dateToZip(final Date d) { + if (d == null) { + return null; + } + return new ZipEightByteInteger(TimeUtils.toNtfsTime(d)); + } + private static ZipEightByteInteger fileTimeToZip(final FileTime time) { + if (time == null) { + return null; + } + return new ZipEightByteInteger(TimeUtils.toNtfsTime(time)); + } + private static Date zipToDate(final ZipEightByteInteger z) { + if (z == null || ZipEightByteInteger.ZERO.equals(z)) { + return null; + } + return TimeUtils.ntfsTimeToDate(z.getLongValue()); + } + + private static FileTime zipToFileTime(final ZipEightByteInteger z) { + if (z == null || ZipEightByteInteger.ZERO.equals(z)) { + return null; + } + return TimeUtils.ntfsTimeToFileTime(z.getLongValue()); + } + private ZipEightByteInteger modifyTime = ZipEightByteInteger.ZERO; + private ZipEightByteInteger accessTime = ZipEightByteInteger.ZERO; + private ZipEightByteInteger createTime = ZipEightByteInteger.ZERO; + @Override + public boolean equals(final Object o) { + if (o instanceof X000A_NTFS) { + final X000A_NTFS xf = (X000A_NTFS) o; + + return Objects.equals(modifyTime, xf.modifyTime) && + Objects.equals(accessTime, xf.accessTime) && + Objects.equals(createTime, xf.createTime); + } + return false; + } + /** - * The Header-ID. + * Gets the access time as a {@link FileTime} + * of this zip entry, or null if no such timestamp exists in the zip entry. * - * @return the value for the header id for this extrafield + * @return access time as a {@link FileTime} or null. + * @since 1.23 */ - @Override - public ZipShort getHeaderId() { - return HEADER_ID; + public FileTime getAccessFileTime() { + return zipToFileTime(accessTime); } /** - * Length of the extra field in the local file data - without - * Header-ID or length specifier. + * Returns the access time as a java.util.Date + * of this zip entry, or null if no such timestamp exists in the zip entry. * - * @return a {@code ZipShort} for the length of the data of this extra field + * @return access time as java.util.Date or null. + */ + public Date getAccessJavaTime() { + return zipToDate(accessTime); + } + + /** + * Returns the "File last access time" of this zip entry as a + * ZipEightByteInteger object, or {@link ZipEightByteInteger#ZERO} + * if no such timestamp exists in the zip entry. + * + * @return File last access time + */ + public ZipEightByteInteger getAccessTime() { return accessTime; } + + /** + * The actual data to put into central directory data - without Header-ID + * or length specifier. + * + * @return the central directory data */ @Override - public ZipShort getLocalFileDataLength() { - return new ZipShort(4 /* reserved */ - + 2 /* Tag#1 */ - + 2 /* Size#1 */ - + 3 * 8 /* time values */); + public byte[] getCentralDirectoryData() { + return getLocalFileDataData(); } /** @@ -115,6 +172,46 @@ public class X000A_NTFS implements ZipExtraField { return getLocalFileDataLength(); } + /** + * Gets the create time as a {@link FileTime} + * of this zip entry, or null if no such timestamp exists in the zip entry. + * + * @return create time as a {@link FileTime} or null. + * @since 1.23 + */ + public FileTime getCreateFileTime() { + return zipToFileTime(createTime); + } + + /** + * Returns the create time as a a java.util.Date of this zip + * entry, or null if no such timestamp exists in the zip entry. + * + * @return create time as java.util.Date or null. + */ + public Date getCreateJavaTime() { + return zipToDate(createTime); + } + + /** + * Returns the "File creation time" of this zip entry as a + * ZipEightByteInteger object, or {@link ZipEightByteInteger#ZERO} + * if no such timestamp exists in the zip entry. + * + * @return File creation time + */ + public ZipEightByteInteger getCreateTime() { return createTime; } + + /** + * The Header-ID. + * + * @return the value for the header id for this extrafield + */ + @Override + public ZipShort getHeaderId() { + return HEADER_ID; + } + /** * The actual data to put into local file data - without Header-ID * or length specifier. @@ -138,55 +235,38 @@ public class X000A_NTFS implements ZipExtraField { } /** - * The actual data to put into central directory data - without Header-ID - * or length specifier. + * Length of the extra field in the local file data - without + * Header-ID or length specifier. * - * @return the central directory data + * @return a {@code ZipShort} for the length of the data of this extra field */ @Override - public byte[] getCentralDirectoryData() { - return getLocalFileDataData(); + public ZipShort getLocalFileDataLength() { + return new ZipShort(4 /* reserved */ + + 2 /* Tag#1 */ + + 2 /* Size#1 */ + + 3 * 8 /* time values */); } /** - * Populate data from this array as if it was in local file data. + * Gets the modify time as as a {@link FileTime} + * of this zip entry, or null if no such timestamp exists in the zip entry. * - * @param data an array of bytes - * @param offset the start offset - * @param length the number of bytes in the array from offset - * @throws java.util.zip.ZipException on error + * @return modify time as a {@link FileTime} or null. + * @since 1.23 */ - @Override - public void parseFromLocalFileData( - final byte[] data, int offset, final int length - ) throws ZipException { - final int len = offset + length; - - // skip reserved - offset += 4; - - while (offset + 4 <= len) { - final ZipShort tag = new ZipShort(data, offset); - offset += 2; - if (tag.equals(TIME_ATTR_TAG)) { - readTimeAttr(data, offset, len - offset); - break; - } - final ZipShort size = new ZipShort(data, offset); - offset += 2 + size.getValue(); - } + public FileTime getModifyFileTime() { + return zipToFileTime(modifyTime); } /** - * Doesn't do anything special since this class always uses the - * same parsing logic for both central directory and local file data. + * Returns the modify time as a java.util.Date + * of this zip entry, or null if no such timestamp exists in the zip entry. + * + * @return modify time as java.util.Date or null. */ - @Override - public void parseFromCentralDirectoryData( - final byte[] buffer, final int offset, final int length - ) throws ZipException { - reset(); - parseFromLocalFileData(buffer, offset, length); + public Date getModifyJavaTime() { + return zipToDate(modifyTime); } /** @@ -199,96 +279,105 @@ public class X000A_NTFS implements ZipExtraField { */ public ZipEightByteInteger getModifyTime() { return modifyTime; } - /** - * Returns the "File last access time" of this zip entry as a - * ZipEightByteInteger object, or {@link ZipEightByteInteger#ZERO} - * if no such timestamp exists in the zip entry. - * - * @return File last access time - */ - public ZipEightByteInteger getAccessTime() { return accessTime; } - - /** - * Returns the "File creation time" of this zip entry as a - * ZipEightByteInteger object, or {@link ZipEightByteInteger#ZERO} - * if no such timestamp exists in the zip entry. - * - * @return File creation time - */ - public ZipEightByteInteger getCreateTime() { return createTime; } - - /** - * Returns the modify time as a java.util.Date - * of this zip entry, or null if no such timestamp exists in the zip entry. - * - * @return modify time as java.util.Date or null. - */ - public Date getModifyJavaTime() { - return zipToDate(modifyTime); + @Override + public int hashCode() { + int hc = -123; + if (modifyTime != null) { + hc ^= modifyTime.hashCode(); + } + if (accessTime != null) { + // Since accessTime is often same as modifyTime, + // this prevents them from XOR negating each other. + hc ^= Integer.rotateLeft(accessTime.hashCode(), 11); + } + if (createTime != null) { + hc ^= Integer.rotateLeft(createTime.hashCode(), 22); + } + return hc; } /** - * Returns the access time as a java.util.Date - * of this zip entry, or null if no such timestamp exists in the zip entry. - * - * @return access time as java.util.Date or null. + * Doesn't do anything special since this class always uses the + * same parsing logic for both central directory and local file data. */ - public Date getAccessJavaTime() { - return zipToDate(accessTime); + @Override + public void parseFromCentralDirectoryData( + final byte[] buffer, final int offset, final int length + ) throws ZipException { + reset(); + parseFromLocalFileData(buffer, offset, length); } /** - * Returns the create time as a a java.util.Date of this zip - * entry, or null if no such timestamp exists in the zip entry. + * Populate data from this array as if it was in local file data. * - * @return create time as java.util.Date or null. + * @param data an array of bytes + * @param offset the start offset + * @param length the number of bytes in the array from offset + * @throws java.util.zip.ZipException on error */ - public Date getCreateJavaTime() { - return zipToDate(createTime); + @Override + public void parseFromLocalFileData( + final byte[] data, int offset, final int length + ) throws ZipException { + final int len = offset + length; + + // skip reserved + offset += 4; + + while (offset + 4 <= len) { + final ZipShort tag = new ZipShort(data, offset); + offset += 2; + if (tag.equals(TIME_ATTR_TAG)) { + readTimeAttr(data, offset, len - offset); + break; + } + final ZipShort size = new ZipShort(data, offset); + offset += 2 + size.getValue(); + } } - /** - * Gets the modify time as as a {@link FileTime} - * of this zip entry, or null if no such timestamp exists in the zip entry. - * - * @return modify time as a {@link FileTime} or null. - * @since 1.23 - */ - public FileTime getModifyFileTime() { - return zipToFileTime(modifyTime); + private void readTimeAttr(final byte[] data, int offset, final int length) { + if (length >= 2 + 3 * 8) { + final ZipShort tagValueLength = new ZipShort(data, offset); + if (TIME_ATTR_SIZE.equals(tagValueLength)) { + offset += 2; + modifyTime = new ZipEightByteInteger(data, offset); + offset += 8; + accessTime = new ZipEightByteInteger(data, offset); + offset += 8; + createTime = new ZipEightByteInteger(data, offset); + } + } } /** - * Gets the access time as a {@link FileTime} - * of this zip entry, or null if no such timestamp exists in the zip entry. - * - * @return access time as a {@link FileTime} or null. - * @since 1.23 + * Reset state back to newly constructed state. Helps us make sure + * parse() calls always generate clean results. */ - public FileTime getAccessFileTime() { - return zipToFileTime(accessTime); + private void reset() { + this.modifyTime = ZipEightByteInteger.ZERO; + this.accessTime = ZipEightByteInteger.ZERO; + this.createTime = ZipEightByteInteger.ZERO; } /** - * Gets the create time as a {@link FileTime} - * of this zip entry, or null if no such timestamp exists in the zip entry. + * Sets the access time. * - * @return create time as a {@link FileTime} or null. + * @param time access time as a {@link FileTime} * @since 1.23 */ - public FileTime getCreateFileTime() { - return zipToFileTime(createTime); + public void setAccessFileTime(final FileTime time) { + setAccessTime(fileTimeToZip(time)); } /** - * Sets the File last modification time of this zip entry using a - * ZipEightByteInteger object. + * Sets the access time as a java.util.Date + * of this zip entry. * - * @param t ZipEightByteInteger of the modify time + * @param d access time as java.util.Date */ - public void setModifyTime(final ZipEightByteInteger t) { - modifyTime = t == null ? ZipEightByteInteger.ZERO : t; - } + public void setAccessJavaTime(final Date d) { setAccessTime(dateToZip(d)); } /** * Sets the File last access time of this zip entry using a @@ -301,30 +390,15 @@ public class X000A_NTFS implements ZipExtraField { } /** - * Sets the File creation time of this zip entry using a - * ZipEightByteInteger object. + * Sets the create time. * - * @param t ZipEightByteInteger of the create time + * @param time create time as a {@link FileTime} + * @since 1.23 */ - public void setCreateTime(final ZipEightByteInteger t) { - createTime = t == null ? ZipEightByteInteger.ZERO : t; + public void setCreateFileTime(final FileTime time) { + setCreateTime(fileTimeToZip(time)); } - /** - * Sets the modify time as a java.util.Date of this zip entry. - * - * @param d modify time as java.util.Date - */ - public void setModifyJavaTime(final Date d) { setModifyTime(dateToZip(d)); } - - /** - * Sets the access time as a java.util.Date - * of this zip entry. - * - * @param d access time as java.util.Date - */ - public void setAccessJavaTime(final Date d) { setAccessTime(dateToZip(d)); } - /** * <p> * Sets the create time as a java.util.Date @@ -340,6 +414,16 @@ public class X000A_NTFS implements ZipExtraField { */ public void setCreateJavaTime(final Date d) { setCreateTime(dateToZip(d)); } + /** + * Sets the File creation time of this zip entry using a + * ZipEightByteInteger object. + * + * @param t ZipEightByteInteger of the create time + */ + public void setCreateTime(final ZipEightByteInteger t) { + createTime = t == null ? ZipEightByteInteger.ZERO : t; + } + /** * Sets the modify time. * @@ -351,23 +435,20 @@ public class X000A_NTFS implements ZipExtraField { } /** - * Sets the access time. + * Sets the modify time as a java.util.Date of this zip entry. * - * @param time access time as a {@link FileTime} - * @since 1.23 + * @param d modify time as java.util.Date */ - public void setAccessFileTime(final FileTime time) { - setAccessTime(fileTimeToZip(time)); - } + public void setModifyJavaTime(final Date d) { setModifyTime(dateToZip(d)); } /** - * Sets the create time. + * Sets the File last modification time of this zip entry using a + * ZipEightByteInteger object. * - * @param time create time as a {@link FileTime} - * @since 1.23 + * @param t ZipEightByteInteger of the modify time */ - public void setCreateFileTime(final FileTime time) { - setCreateTime(fileTimeToZip(time)); + public void setModifyTime(final ZipEightByteInteger t) { + modifyTime = t == null ? ZipEightByteInteger.ZERO : t; } /** @@ -386,85 +467,4 @@ public class X000A_NTFS implements ZipExtraField { .append(" Create:[").append(getCreateFileTime()).append("] "); return buf.toString(); } - - @Override - public boolean equals(final Object o) { - if (o instanceof X000A_NTFS) { - final X000A_NTFS xf = (X000A_NTFS) o; - - return Objects.equals(modifyTime, xf.modifyTime) && - Objects.equals(accessTime, xf.accessTime) && - Objects.equals(createTime, xf.createTime); - } - return false; - } - - @Override - public int hashCode() { - int hc = -123; - if (modifyTime != null) { - hc ^= modifyTime.hashCode(); - } - if (accessTime != null) { - // Since accessTime is often same as modifyTime, - // this prevents them from XOR negating each other. - hc ^= Integer.rotateLeft(accessTime.hashCode(), 11); - } - if (createTime != null) { - hc ^= Integer.rotateLeft(createTime.hashCode(), 22); - } - return hc; - } - - /** - * Reset state back to newly constructed state. Helps us make sure - * parse() calls always generate clean results. - */ - private void reset() { - this.modifyTime = ZipEightByteInteger.ZERO; - this.accessTime = ZipEightByteInteger.ZERO; - this.createTime = ZipEightByteInteger.ZERO; - } - - private void readTimeAttr(final byte[] data, int offset, final int length) { - if (length >= 2 + 3 * 8) { - final ZipShort tagValueLength = new ZipShort(data, offset); - if (TIME_ATTR_SIZE.equals(tagValueLength)) { - offset += 2; - modifyTime = new ZipEightByteInteger(data, offset); - offset += 8; - accessTime = new ZipEightByteInteger(data, offset); - offset += 8; - createTime = new ZipEightByteInteger(data, offset); - } - } - } - - private static ZipEightByteInteger dateToZip(final Date d) { - if (d == null) { - return null; - } - return new ZipEightByteInteger(TimeUtils.toNtfsTime(d)); - } - - private static ZipEightByteInteger fileTimeToZip(final FileTime time) { - if (time == null) { - return null; - } - return new ZipEightByteInteger(TimeUtils.toNtfsTime(time)); - } - - private static Date zipToDate(final ZipEightByteInteger z) { - if (z == null || ZipEightByteInteger.ZERO.equals(z)) { - return null; - } - return TimeUtils.ntfsTimeToDate(z.getLongValue()); - } - - private static FileTime zipToFileTime(final ZipEightByteInteger z) { - if (z == null || ZipEightByteInteger.ZERO.equals(z)) { - return null; - } - return TimeUtils.ntfsTimeToFileTime(z.getLongValue()); - } }