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

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

本文整理了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

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

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

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

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

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

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

/**
 * Populate data from this array as if it was in local file data.
 *
 * @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
 */
@Override
public void parseFromLocalFileData(
    final byte[] data, int offset, final int length
) throws ZipException {
  reset();
  this.version = signedByteToUnsignedInt(data[offset++]);
  final int uidSize = signedByteToUnsignedInt(data[offset++]);
  final byte[] uidBytes = new byte[uidSize];
  System.arraycopy(data, offset, uidBytes, 0, uidSize);
  offset += uidSize;
  this.uid = new BigInteger(1, reverse(uidBytes)); // sign-bit forced positive
  final int gidSize = signedByteToUnsignedInt(data[offset++]);
  final byte[] gidBytes = new byte[gidSize];
  System.arraycopy(data, offset, gidBytes, 0, gidSize);
  this.gid = new BigInteger(1, reverse(gidBytes)); // sign-bit forced positive
}

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

reverse(uidBytes);
  reverse(gidBytes);
data[pos++] = unsignedIntToSignedByte(version);
data[pos++] = unsignedIntToSignedByte(uidBytesLen);
if (uidBytes != null) {
  System.arraycopy(uidBytes, 0, data, pos, uidBytesLen);
data[pos++] = unsignedIntToSignedByte(gidBytesLen);
if (gidBytes != null) {
  System.arraycopy(gidBytes, 0, data, pos, gidBytesLen);

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

/**
 * The actual data to put into local file data.
 *
 * @return The LocalFileDataData value
 */
@Override
public byte[] getLocalFileDataData() {
  return ZipUtil.copy(localFileData);
}

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

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

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

private void copyFromZipInputStream(final InputStream src) throws IOException {
  if (entry == null) {
    throw new IllegalStateException("No current entry");
  }
  ZipUtil.checkRequestedFeatures(entry.entry);
  entry.hasWritten = true;
  int length;
  while ((length = src.read(copyBuffer)) >= 0 )
  {
    streamCompressor.writeCounted(copyBuffer, 0, length);
    count( length );
  }
}

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

/**
 * Convert a DOS date/time field to a Date object.
 *
 * @param zipDosTime contains the stored DOS time.
 * @return a Date instance corresponding to the given time.
 */
public static Date fromDosTime(final ZipLong zipDosTime) {
  final long dosTime = zipDosTime.getValue();
  return new Date(dosToJavaTime(dosTime));
}

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

/**
 * Sets the UID.
 *
 * @param l UID value to set on this extra field.
 */
public void setUID(final long l) {
  this.uid = ZipUtil.longToBig(l);
}

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

/**
 * If the entry has Unicode*ExtraFields and the CRCs of the
 * names/comments match those of the extra fields, transfer the
 * known Unicode values from the extra field.
 */
static void setNameAndCommentFromExtraFields(final ZipArchiveEntry ze,
                       final byte[] originalNameBytes,
                       final byte[] commentBytes) {
  final UnicodePathExtraField name = (UnicodePathExtraField)
    ze.getExtraField(UnicodePathExtraField.UPATH_ID);
  final String newName = getUnicodeStringIfOriginalMatches(name,
                            originalNameBytes);
  if (newName != null) {
    ze.setName(newName);
    ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
  }
  if (commentBytes != null && commentBytes.length > 0) {
    final UnicodeCommentExtraField cmt = (UnicodeCommentExtraField)
      ze.getExtraField(UnicodeCommentExtraField.UCOM_ID);
    final String newComment =
      getUnicodeStringIfOriginalMatches(cmt, commentBytes);
    if (newComment != null) {
      ze.setComment(newComment);
      ze.setCommentSource(ZipArchiveEntry.CommentSource.UNICODE_EXTRA_FIELD);
    }
  }
}

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

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

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

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

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

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

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

/**
 * Writes bytes to ZIP entry.
 * @param b the byte array to write
 * @param offset the start position to write from
 * @param length the number of bytes to write
 * @throws IOException on error
 */
@Override
public void write(final byte[] b, final int offset, final int length) throws IOException {
  if (entry == null) {
    throw new IllegalStateException("No current entry");
  }
  ZipUtil.checkRequestedFeatures(entry.entry);
  final long writtenThisTime = streamCompressor.write(b, offset, length, entry.entry.getMethod());
  count(writtenThisTime);
}

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

/**
 * Populate data from this array as if it was in local file data.
 *
 * @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
 */
@Override
public void parseFromLocalFileData(
    final byte[] data, int offset, final int length
) throws ZipException {
  reset();
  this.version = signedByteToUnsignedInt(data[offset++]);
  final int uidSize = signedByteToUnsignedInt(data[offset++]);
  final byte[] uidBytes = new byte[uidSize];
  System.arraycopy(data, offset, uidBytes, 0, uidSize);
  offset += uidSize;
  this.uid = new BigInteger(1, reverse(uidBytes)); // sign-bit forced positive
  final int gidSize = signedByteToUnsignedInt(data[offset++]);
  final byte[] gidBytes = new byte[gidSize];
  System.arraycopy(data, offset, gidBytes, 0, gidSize);
  this.gid = new BigInteger(1, reverse(gidBytes)); // sign-bit forced positive
}

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

reverse(uidBytes);
  reverse(gidBytes);
data[pos++] = unsignedIntToSignedByte(version);
data[pos++] = unsignedIntToSignedByte(uidBytesLen);
if (uidBytes != null) {
  System.arraycopy(uidBytes, 0, data, pos, uidBytesLen);
data[pos++] = unsignedIntToSignedByte(gidBytesLen);
if (gidBytes != null) {
  System.arraycopy(gidBytes, 0, data, pos, gidBytesLen);

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

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

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

/**
 * Sets the GID.
 *
 * @param l GID value to set on this extra field.
 */
public void setGID(final long l) {
  this.gid = ZipUtil.longToBig(l);
}

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

/**
 * If the entry has Unicode*ExtraFields and the CRCs of the
 * names/comments match those of the extra fields, transfer the
 * known Unicode values from the extra field.
 */
static void setNameAndCommentFromExtraFields(final ZipArchiveEntry ze,
                       final byte[] originalNameBytes,
                       final byte[] commentBytes) {
  final UnicodePathExtraField name = (UnicodePathExtraField)
    ze.getExtraField(UnicodePathExtraField.UPATH_ID);
  final String newName = getUnicodeStringIfOriginalMatches(name,
                            originalNameBytes);
  if (newName != null) {
    ze.setName(newName);
    ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
  }
  if (commentBytes != null && commentBytes.length > 0) {
    final UnicodeCommentExtraField cmt = (UnicodeCommentExtraField)
      ze.getExtraField(UnicodeCommentExtraField.UCOM_ID);
    final String newComment =
      getUnicodeStringIfOriginalMatches(cmt, commentBytes);
    if (newComment != null) {
      ze.setComment(newComment);
      ze.setCommentSource(ZipArchiveEntry.CommentSource.UNICODE_EXTRA_FIELD);
    }
  }
}

相关文章