gpt4 book ai didi

org.apache.commons.compress.archivers.zip.ZipArchiveEntry.getExtraField()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 07:52:40 26 4
gpt4 key购买 nike

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

ZipArchiveEntry.getExtraField介绍

[英]Looks up an extra field by its header id.
[中]通过标题id查找额外字段。

代码示例

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

/**
 * Is there a ZIP64 extended information extra field for the
 * entry?
 *
 * @since 1.3
 */
private boolean hasZip64Extra(final ZipArchiveEntry ze) {
  return ze.getExtraField(Zip64ExtendedInformationExtraField
              .HEADER_ID)
    != null;
}

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

/**
 * Get the existing ZIP64 extended information extra field or
 * create a new one and add it to the entry.
 *
 * @since 1.3
 */
private Zip64ExtendedInformationExtraField
  getZip64Extra(final ZipArchiveEntry ze) {
  if (entry != null) {
    entry.causedUseOfZip64 = !hasUsedZip64;
  }
  hasUsedZip64 = true;
  Zip64ExtendedInformationExtraField z64 =
    (Zip64ExtendedInformationExtraField)
    ze.getExtraField(Zip64ExtendedInformationExtraField
             .HEADER_ID);
  if (z64 == null) {
    /*
     System.err.println("Adding z64 for " + ze.getName()
     + ", method: " + ze.getMethod()
     + " (" + (ze.getMethod() == STORED) + ")"
     + ", channel: " + (channel != null));
    */
    z64 = new Zip64ExtendedInformationExtraField();
  }
  // even if the field is there already, make sure it is the first one
  ze.addAsFirstExtraField(z64);
  return z64;
}

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

/**
 * Adds an extra field - replacing an already present extra field
 * of the same type.
 *
 * <p>The new extra field will be the first one.</p>
 * @param ze an extra field
 */
public void addAsFirstExtraField(final ZipExtraField ze) {
  if (ze instanceof UnparseableExtraFieldData) {
    unparseableExtra = (UnparseableExtraFieldData) ze;
  } else {
    if (getExtraField(ze.getHeaderId()) != null){
      removeExtraField(ze.getHeaderId());
    }
    final ZipExtraField[] copy = extraFields;
    final int newLen = extraFields != null ? extraFields.length + 1: 1;
    extraFields = new ZipExtraField[newLen];
    extraFields[0] = ze;
    if (copy != null){
      System.arraycopy(copy, 0, extraFields, 1, extraFields.length - 1);
    }
  }
  setExtra();
}

代码示例来源: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

/**
 * Adds an extra field - replacing an already present extra field
 * of the same type.
 *
 * <p>If no extra field of the same type exists, the field will be
 * added as last field.</p>
 * @param ze an extra field
 */
public void addExtraField(final ZipExtraField ze) {
  if (ze instanceof UnparseableExtraFieldData) {
    unparseableExtra = (UnparseableExtraFieldData) ze;
  } else {
    if (extraFields == null) {
      extraFields = new ZipExtraField[]{ ze};
    } else {
      if (getExtraField(ze.getHeaderId())!= null){
        removeExtraField(ze.getHeaderId());
      }
      final ZipExtraField[] zipExtraFields = copyOf(extraFields, extraFields.length + 1);
      zipExtraFields[zipExtraFields.length -1] = ze;
      extraFields = zipExtraFields;
    }
  }
  setExtra();
}

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

private byte[] createLocalFileHeader(final ZipArchiveEntry ze, final ByteBuffer name, final boolean encodable,
                   final boolean phased, long archiveOffset) {
  ResourceAlignmentExtraField oldAlignmentEx =
    (ResourceAlignmentExtraField) ze.getExtraField(ResourceAlignmentExtraField.ID);
  if (oldAlignmentEx != null) {
    ze.removeExtraField(ResourceAlignmentExtraField.ID);

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

existing = unparseableExtra;
} else {
  existing = getExtraField(element.getHeaderId());

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

/**
 * Records whether a Zip64 extra is present and sets the size
 * information from it if sizes are 0xFFFFFFFF and the entry
 * doesn't use a data descriptor.
 */
private void processZip64Extra(final ZipLong size, final ZipLong cSize) {
  final Zip64ExtendedInformationExtraField z64 =
    (Zip64ExtendedInformationExtraField)
    current.entry.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
  current.usesZip64 = z64 != null;
  if (!current.hasDataDescriptor) {
    if (z64 != null // same as current.usesZip64 but avoids NPE warning
        && (cSize.equals(ZipLong.ZIP64_MAGIC) || size.equals(ZipLong.ZIP64_MAGIC)) ) {
      current.entry.setCompressedSize(z64.getCompressedSize().getLongValue());
      current.entry.setSize(z64.getSize().getLongValue());
    } else {
      current.entry.setCompressedSize(cSize.getValue());
      current.entry.setSize(size.getValue());
    }
  }
}

代码示例来源:origin: org.codehaus.plexus/plexus-archiver

public String getName()
{
  try
  {
    final UnicodePathExtraField unicodePath =
      (UnicodePathExtraField) zipEntry.getExtraField( UnicodePathExtraField.UPATH_ID );
    return unicodePath != null
          ? new String( unicodePath.getUnicodeName(), "UTF-8" )
          : zipEntry.getName();
  }
  catch ( final UnsupportedEncodingException e )
  {
    throw new AssertionError( e );
  }
}

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

final Zip64ExtendedInformationExtraField z64 =
  (Zip64ExtendedInformationExtraField)
  ze.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
if (z64 != null) {
  final boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;

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

/**
 * Is there a ZIP64 extended information extra field for the
 * entry?
 *
 * @since 1.3
 */
private boolean hasZip64Extra(final ZipArchiveEntry ze) {
  return ze.getExtraField(Zip64ExtendedInformationExtraField
              .HEADER_ID)
    != null;
}

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

/**
 * Get the existing ZIP64 extended information extra field or
 * create a new one and add it to the entry.
 *
 * @since 1.3
 */
private Zip64ExtendedInformationExtraField
  getZip64Extra(final ZipArchiveEntry ze) {
  if (entry != null) {
    entry.causedUseOfZip64 = !hasUsedZip64;
  }
  hasUsedZip64 = true;
  Zip64ExtendedInformationExtraField z64 =
    (Zip64ExtendedInformationExtraField)
    ze.getExtraField(Zip64ExtendedInformationExtraField
             .HEADER_ID);
  if (z64 == null) {
    /*
     System.err.println("Adding z64 for " + ze.getName()
     + ", method: " + ze.getMethod()
     + " (" + (ze.getMethod() == STORED) + ")"
     + ", channel: " + (channel != null));
    */
    z64 = new Zip64ExtendedInformationExtraField();
  }
  // even if the field is there already, make sure it is the first one
  ze.addAsFirstExtraField(z64);
  return z64;
}

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

/**
 * Adds an extra field - replacing an already present extra field
 * of the same type.
 *
 * <p>The new extra field will be the first one.</p>
 * @param ze an extra field
 */
public void addAsFirstExtraField(final ZipExtraField ze) {
  if (ze instanceof UnparseableExtraFieldData) {
    unparseableExtra = (UnparseableExtraFieldData) ze;
  } else {
    if (getExtraField(ze.getHeaderId()) != null){
      removeExtraField(ze.getHeaderId());
    }
    final ZipExtraField[] copy = extraFields;
    final int newLen = extraFields != null ? extraFields.length + 1: 1;
    extraFields = new ZipExtraField[newLen];
    extraFields[0] = ze;
    if (copy != null){
      System.arraycopy(copy, 0, extraFields, 1, extraFields.length - 1);
    }
  }
  setExtra();
}

代码示例来源: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);
    }
  }
}

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

/**
 * Adds an extra field - replacing an already present extra field
 * of the same type.
 *
 * <p>If no extra field of the same type exists, the field will be
 * added as last field.</p>
 * @param ze an extra field
 */
public void addExtraField(final ZipExtraField ze) {
  if (ze instanceof UnparseableExtraFieldData) {
    unparseableExtra = (UnparseableExtraFieldData) ze;
  } else {
    if (extraFields == null) {
      extraFields = new ZipExtraField[]{ ze};
    } else {
      if (getExtraField(ze.getHeaderId())!= null){
        removeExtraField(ze.getHeaderId());
      }
      final ZipExtraField[] zipExtraFields = copyOf(extraFields, extraFields.length + 1);
      zipExtraFields[zipExtraFields.length -1] = ze;
      extraFields = zipExtraFields;
    }
  }
  setExtra();
}

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

private byte[] createLocalFileHeader(final ZipArchiveEntry ze, final ByteBuffer name, final boolean encodable,
                   final boolean phased, long archiveOffset) {
  ResourceAlignmentExtraField oldAlignmentEx =
    (ResourceAlignmentExtraField) ze.getExtraField(ResourceAlignmentExtraField.ID);
  if (oldAlignmentEx != null) {
    ze.removeExtraField(ResourceAlignmentExtraField.ID);

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

existing = unparseableExtra;
} else {
  existing = getExtraField(element.getHeaderId());

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

/**
 * Records whether a Zip64 extra is present and sets the size
 * information from it if sizes are 0xFFFFFFFF and the entry
 * doesn't use a data descriptor.
 */
private void processZip64Extra(final ZipLong size, final ZipLong cSize) {
  final Zip64ExtendedInformationExtraField z64 =
    (Zip64ExtendedInformationExtraField)
    current.entry.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
  current.usesZip64 = z64 != null;
  if (!current.hasDataDescriptor) {
    if (z64 != null // same as current.usesZip64 but avoids NPE warning
        && (cSize.equals(ZipLong.ZIP64_MAGIC) || size.equals(ZipLong.ZIP64_MAGIC)) ) {
      current.entry.setCompressedSize(z64.getCompressedSize().getLongValue());
      current.entry.setSize(z64.getSize().getLongValue());
    } else {
      current.entry.setCompressedSize(cSize.getValue());
      current.entry.setSize(size.getValue());
    }
  }
}

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

final Zip64ExtendedInformationExtraField z64 =
  (Zip64ExtendedInformationExtraField)
  ze.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
if (z64 != null) {
  final boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com