org.apache.commons.compress.archivers.zip.ZipUtil类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中org.apache.commons.compress.archivers.zip.ZipUtil类的一些代码示例,展示了ZipUtil类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipUtil类的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipUtil
类名称:ZipUtil

ZipUtil介绍

[英]Utility class for handling DOS and Java time conversions.
[中]用于处理DOS和Java时间转换的实用程序类。

代码示例

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * <p>
  3. * Converts a long into a BigInteger. Negative numbers between -1 and
  4. * -2^31 are treated as unsigned 32 bit (e.g., positive) integers.
  5. * Negative numbers below -2^31 cause an IllegalArgumentException
  6. * to be thrown.
  7. * </p>
  8. *
  9. * @param l long to convert to BigInteger.
  10. * @return BigInteger representation of the provided long.
  11. */
  12. static BigInteger longToBig(long l) {
  13. if (l < Integer.MIN_VALUE) {
  14. throw new IllegalArgumentException("Negative longs < -2^31 not permitted: [" + l + "]");
  15. } else if (l < 0 && l >= Integer.MIN_VALUE) {
  16. // If someone passes in a -2, they probably mean 4294967294
  17. // (For example, Unix UID/GID's are 32 bit unsigned.)
  18. l = ZipUtil.adjustToLong((int) l);
  19. }
  20. return BigInteger.valueOf(l);
  21. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Gets the GID as a long. GID is typically a 32 bit unsigned
  3. * value on most UNIX systems, so we return a long to avoid
  4. * integer overflow into the negatives in case values above
  5. * and including 2^31 are being used.
  6. *
  7. * @return the GID value.
  8. */
  9. public long getGID() { return ZipUtil.bigToLong(gid); }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Whether this class is able to read the given entry.
  3. *
  4. * <p>May return false if it is set up to use encryption or a
  5. * compression method that hasn't been implemented yet.</p>
  6. * @since 1.1
  7. * @param ze the entry
  8. * @return whether this class is able to read the given entry.
  9. */
  10. public boolean canReadEntryData(final ZipArchiveEntry ze) {
  11. return ZipUtil.canHandleEntryData(ze);
  12. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Populate data from this array as if it was in local file data.
  3. *
  4. * @param data an array of bytes
  5. * @param offset the start offset
  6. * @param length the number of bytes in the array from offset
  7. * @throws java.util.zip.ZipException on error
  8. */
  9. @Override
  10. public void parseFromLocalFileData(
  11. final byte[] data, int offset, final int length
  12. ) throws ZipException {
  13. reset();
  14. this.version = signedByteToUnsignedInt(data[offset++]);
  15. final int uidSize = signedByteToUnsignedInt(data[offset++]);
  16. final byte[] uidBytes = new byte[uidSize];
  17. System.arraycopy(data, offset, uidBytes, 0, uidSize);
  18. offset += uidSize;
  19. this.uid = new BigInteger(1, reverse(uidBytes)); // sign-bit forced positive
  20. final int gidSize = signedByteToUnsignedInt(data[offset++]);
  21. final byte[] gidBytes = new byte[gidSize];
  22. System.arraycopy(data, offset, gidBytes, 0, gidSize);
  23. this.gid = new BigInteger(1, reverse(gidBytes)); // sign-bit forced positive
  24. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. reverse(uidBytes);
  2. reverse(gidBytes);
  3. data[pos++] = unsignedIntToSignedByte(version);
  4. data[pos++] = unsignedIntToSignedByte(uidBytesLen);
  5. if (uidBytes != null) {
  6. System.arraycopy(uidBytes, 0, data, pos, uidBytesLen);
  7. data[pos++] = unsignedIntToSignedByte(gidBytesLen);
  8. if (gidBytes != null) {
  9. System.arraycopy(gidBytes, 0, data, pos, gidBytesLen);

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * The actual data to put into local file data.
  3. *
  4. * @return The LocalFileDataData value
  5. */
  6. @Override
  7. public byte[] getLocalFileDataData() {
  8. return ZipUtil.copy(localFileData);
  9. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. off += SHORT;
  2. final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(lfhBuf, off));
  3. current.entry.setTime(time);
  4. off += WORD;
  5. ZipUtil.setNameAndCommentFromExtraFields(current.entry, fileName, null);
  6. if (ZipUtil.canHandleEntryData(current.entry) && m != ZipMethod.STORED && m != ZipMethod.DEFLATED) {
  7. InputStream bis = new BoundedInputStream(in, current.entry.getCompressedSize());
  8. switch (m) {

代码示例来源:origin: org.apache.commons/commons-compress

  1. private void copyFromZipInputStream(final InputStream src) throws IOException {
  2. if (entry == null) {
  3. throw new IllegalStateException("No current entry");
  4. }
  5. ZipUtil.checkRequestedFeatures(entry.entry);
  6. entry.hasWritten = true;
  7. int length;
  8. while ((length = src.read(copyBuffer)) >= 0 )
  9. {
  10. streamCompressor.writeCounted(copyBuffer, 0, length);
  11. count( length );
  12. }
  13. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Convert a DOS date/time field to a Date object.
  3. *
  4. * @param zipDosTime contains the stored DOS time.
  5. * @return a Date instance corresponding to the given time.
  6. */
  7. public static Date fromDosTime(final ZipLong zipDosTime) {
  8. final long dosTime = zipDosTime.getValue();
  9. return new Date(dosToJavaTime(dosTime));
  10. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Sets the UID.
  3. *
  4. * @param l UID value to set on this extra field.
  5. */
  6. public void setUID(final long l) {
  7. this.uid = ZipUtil.longToBig(l);
  8. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * If the entry has Unicode*ExtraFields and the CRCs of the
  3. * names/comments match those of the extra fields, transfer the
  4. * known Unicode values from the extra field.
  5. */
  6. static void setNameAndCommentFromExtraFields(final ZipArchiveEntry ze,
  7. final byte[] originalNameBytes,
  8. final byte[] commentBytes) {
  9. final UnicodePathExtraField name = (UnicodePathExtraField)
  10. ze.getExtraField(UnicodePathExtraField.UPATH_ID);
  11. final String newName = getUnicodeStringIfOriginalMatches(name,
  12. originalNameBytes);
  13. if (newName != null) {
  14. ze.setName(newName);
  15. ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
  16. }
  17. if (commentBytes != null && commentBytes.length > 0) {
  18. final UnicodeCommentExtraField cmt = (UnicodeCommentExtraField)
  19. ze.getExtraField(UnicodeCommentExtraField.UCOM_ID);
  20. final String newComment =
  21. getUnicodeStringIfOriginalMatches(cmt, commentBytes);
  22. if (newComment != null) {
  23. ze.setComment(newComment);
  24. ze.setCommentSource(ZipArchiveEntry.CommentSource.UNICODE_EXTRA_FIELD);
  25. }
  26. }
  27. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name,
  2. nc.comment);

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Set the extra field data in central directory.
  3. * @param data the data to use
  4. */
  5. public void setCentralDirectoryData(final byte[] data) {
  6. centralData = ZipUtil.copy(data);
  7. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. off += SHORT;
  2. final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(lfhBuf, off));
  3. current.entry.setTime(time);
  4. off += WORD;
  5. ZipUtil.setNameAndCommentFromExtraFields(current.entry, fileName, null);
  6. if (ZipUtil.canHandleEntryData(current.entry) && m != ZipMethod.STORED && m != ZipMethod.DEFLATED) {
  7. InputStream bis = new BoundedInputStream(in, current.entry.getCompressedSize());
  8. switch (m) {

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Writes bytes to ZIP entry.
  3. * @param b the byte array to write
  4. * @param offset the start position to write from
  5. * @param length the number of bytes to write
  6. * @throws IOException on error
  7. */
  8. @Override
  9. public void write(final byte[] b, final int offset, final int length) throws IOException {
  10. if (entry == null) {
  11. throw new IllegalStateException("No current entry");
  12. }
  13. ZipUtil.checkRequestedFeatures(entry.entry);
  14. final long writtenThisTime = streamCompressor.write(b, offset, length, entry.entry.getMethod());
  15. count(writtenThisTime);
  16. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. /**
  2. * Populate data from this array as if it was in local file data.
  3. *
  4. * @param data an array of bytes
  5. * @param offset the start offset
  6. * @param length the number of bytes in the array from offset
  7. * @throws java.util.zip.ZipException on error
  8. */
  9. @Override
  10. public void parseFromLocalFileData(
  11. final byte[] data, int offset, final int length
  12. ) throws ZipException {
  13. reset();
  14. this.version = signedByteToUnsignedInt(data[offset++]);
  15. final int uidSize = signedByteToUnsignedInt(data[offset++]);
  16. final byte[] uidBytes = new byte[uidSize];
  17. System.arraycopy(data, offset, uidBytes, 0, uidSize);
  18. offset += uidSize;
  19. this.uid = new BigInteger(1, reverse(uidBytes)); // sign-bit forced positive
  20. final int gidSize = signedByteToUnsignedInt(data[offset++]);
  21. final byte[] gidBytes = new byte[gidSize];
  22. System.arraycopy(data, offset, gidBytes, 0, gidSize);
  23. this.gid = new BigInteger(1, reverse(gidBytes)); // sign-bit forced positive
  24. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. reverse(uidBytes);
  2. reverse(gidBytes);
  3. data[pos++] = unsignedIntToSignedByte(version);
  4. data[pos++] = unsignedIntToSignedByte(uidBytesLen);
  5. if (uidBytes != null) {
  6. System.arraycopy(uidBytes, 0, data, pos, uidBytesLen);
  7. data[pos++] = unsignedIntToSignedByte(gidBytesLen);
  8. if (gidBytes != null) {
  9. System.arraycopy(gidBytes, 0, data, pos, gidBytesLen);

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * The last modified date of the entry.
  3. *
  4. * <p>Note the interpretation of time is different depending on
  5. * the HostOS that has created the archive. While an OS that is
  6. * {@link #isHostOsUnix considered to be Unix} stores time in a
  7. * timezone independent manner, other platforms only use the local
  8. * time. I.e. if an archive has been created at midnight UTC on a
  9. * machine in timezone UTC this method will return midnight
  10. * regardless of timezone if the archive has been created on a
  11. * non-Unix system and a time taking the current timezone into
  12. * account if the archive has beeen created on Unix.</p>
  13. *
  14. * @return the last modified date
  15. */
  16. @Override
  17. public Date getLastModifiedDate() {
  18. final long ts = isHostOsUnix() ? localFileHeader.dateTimeModified * 1000L
  19. : ZipUtil.dosToJavaTime(0xFFFFFFFFL & localFileHeader.dateTimeModified);
  20. return new Date(ts);
  21. }

代码示例来源:origin: org.apache.commons/commons-compress

  1. /**
  2. * Sets the GID.
  3. *
  4. * @param l GID value to set on this extra field.
  5. */
  6. public void setGID(final long l) {
  7. this.gid = ZipUtil.longToBig(l);
  8. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. /**
  2. * If the entry has Unicode*ExtraFields and the CRCs of the
  3. * names/comments match those of the extra fields, transfer the
  4. * known Unicode values from the extra field.
  5. */
  6. static void setNameAndCommentFromExtraFields(final ZipArchiveEntry ze,
  7. final byte[] originalNameBytes,
  8. final byte[] commentBytes) {
  9. final UnicodePathExtraField name = (UnicodePathExtraField)
  10. ze.getExtraField(UnicodePathExtraField.UPATH_ID);
  11. final String newName = getUnicodeStringIfOriginalMatches(name,
  12. originalNameBytes);
  13. if (newName != null) {
  14. ze.setName(newName);
  15. ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
  16. }
  17. if (commentBytes != null && commentBytes.length > 0) {
  18. final UnicodeCommentExtraField cmt = (UnicodeCommentExtraField)
  19. ze.getExtraField(UnicodeCommentExtraField.UCOM_ID);
  20. final String newComment =
  21. getUnicodeStringIfOriginalMatches(cmt, commentBytes);
  22. if (newComment != null) {
  23. ze.setComment(newComment);
  24. ze.setCommentSource(ZipArchiveEntry.CommentSource.UNICODE_EXTRA_FIELD);
  25. }
  26. }
  27. }

相关文章