本文整理了Java中java.util.zip.ZipEntry.getExtra()
方法的一些代码示例,展示了ZipEntry.getExtra()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.getExtra()
方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:getExtra
[英]Gets the extra information for this ZipEntry.
[中]获取此ZipEntry的额外信息。
代码示例来源:origin: robolectric/robolectric
long guessOffsetFor(ZipFile zipFile, ZipEntry zipEntry) {
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
long offset = 0;
while (zipEntries.hasMoreElements())
{
ZipEntry entry = zipEntries.nextElement();
long fileSize = 0;
long extra = entry.getExtra() == null ? 0 : entry.getExtra().length;
offset += 30 + entry.getName().length() + extra;
if (entry.getName().equals(zipEntry.getName())) {
return offset;
}
if(!entry.isDirectory())
{
fileSize = entry.getCompressedSize();
// Do stuff here with fileSize & offset
}
offset += fileSize;
}
throw new IllegalStateException("'" + zipEntry.getName() + "' not found");
}
/*
代码示例来源:origin: spotbugs/spotbugs
public ZipEntry newZipEntry(ZipEntry ze) {
ZipEntry ze2 = new ZipEntry(ze.getName());
ze2.setComment(ze.getComment());
ze2.setTime(ze.getTime());
ze2.setExtra(ze.getExtra());
return ze2;
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* Copy entry with another name.
*
* @param original - zipEntry to copy
* @param newName - new entry name, optional, if null, ogirinal's entry
* @return copy of the original entry, but with the given name
*/
static ZipEntry copy(ZipEntry original, String newName) {
ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName);
if (original.getCrc() != -1) {
copy.setCrc(original.getCrc());
}
if (original.getMethod() != -1) {
copy.setMethod(original.getMethod());
}
if (original.getSize() >= 0) {
copy.setSize(original.getSize());
}
if (original.getExtra() != null) {
copy.setExtra(original.getExtra());
}
copy.setComment(original.getComment());
copy.setTime(original.getTime());
return copy;
}
代码示例来源:origin: org.apache.ant/ant
outputEntry.setExtra(inputEntry.getExtra());
outputEntry.setComment(inputEntry.getComment());
outputEntry.setTime(inputEntry.getTime());
代码示例来源:origin: org.apache.ant/ant
/**
* Creates a new zip entry with fields taken from the specified zip entry.
*
* <p>Assumes the entry represents a directory if and only if the
* name ends with a forward slash "/".</p>
*
* @param entry the entry to get fields from
* @since 1.1
* @throws ZipException on error
*/
public ZipEntry(final java.util.zip.ZipEntry entry) throws ZipException {
super(entry);
setName(entry.getName());
final byte[] extra = entry.getExtra();
if (extra != null) {
setExtraFields(ExtraFieldUtils.parse(extra, true,
ExtraFieldUtils.UnparseableExtraField.READ));
} else {
// initializes extra data to an empty byte array
setExtra();
}
setMethod(entry.getMethod());
this.size = entry.getSize();
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Creates a new zip entry with fields taken from the specified zip entry.
*
* <p>Assumes the entry represents a directory if and only if the
* name ends with a forward slash "/".</p>
*
* @param entry the entry to get fields from
* @throws ZipException on error
*/
public ZipArchiveEntry(final java.util.zip.ZipEntry entry) throws ZipException {
super(entry);
setName(entry.getName());
final byte[] extra = entry.getExtra();
if (extra != null) {
setExtraFields(ExtraFieldUtils.parse(extra, true,
ExtraFieldUtils
.UnparseableExtraField.READ));
} else {
// initializes extra data to an empty byte array
setExtra();
}
setMethod(entry.getMethod());
this.size = entry.getSize();
}
代码示例来源:origin: alibaba/mdrill
/**
* Creates a new zip entry with fields taken from the specified zip entry.
*
* <p>Assumes the entry represents a directory if and only if the
* name ends with a forward slash "/".</p>
*
* @param entry the entry to get fields from
* @since 1.1
* @throws ZipException on error
*/
public ZipEntry(java.util.zip.ZipEntry entry) throws ZipException {
super(entry);
setName(entry.getName());
byte[] extra = entry.getExtra();
if (extra != null) {
setExtraFields(ExtraFieldUtils.parse(extra, true,
ExtraFieldUtils
.UnparseableExtraField.READ));
} else {
// initializes extra data to an empty byte array
setExtra();
}
setMethod(entry.getMethod());
this.size = entry.getSize();
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* Add file permissions info to ZIP entry.
* Current implementation adds "ASi Unix" (tag 0x756e) extra block to entry.
*
* @param zipEntry ZIP entry
* @param permissions permissions to assign
*/
static boolean setZTFilePermissions(ZipEntry zipEntry, ZTFilePermissions permissions) {
try {
List<ZipExtraField> fields = ExtraFieldUtils.parse(zipEntry.getExtra());
AsiExtraField asiExtraField = getFirstAsiExtraField(fields);
if (asiExtraField == null) {
asiExtraField = new AsiExtraField();
fields.add(asiExtraField);
}
asiExtraField.setDirectory(zipEntry.isDirectory());
asiExtraField.setMode(ZTFilePermissionsUtil.toPosixFileMode(permissions));
zipEntry.setExtra(ExtraFieldUtils.mergeLocalFileDataData(fields));
return true;
}
catch (java.util.zip.ZipException ze) {
return false;
}
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* Get assigned to ZIP entry file permissions info. Current implementation tries to read "ASi Unix" (tag 0x756e) extra tag.
* "ASi Unix"
*
* @param zipEntry
* @return file permissions info or <code>null</code> if ZIP entry does not have "ASi Unix" extra field.
*/
static ZTFilePermissions getZTFilePermissions(ZipEntry zipEntry) {
try {
ZTFilePermissions permissions = null;
List<ZipExtraField> fields = ExtraFieldUtils.parse(zipEntry.getExtra());
AsiExtraField asiExtraField = getFirstAsiExtraField(fields);
if (asiExtraField != null) {
int mode = asiExtraField.getMode() & 0777;
permissions = ZTFilePermissionsUtil.fromPosixFileMode(mode);
}
return permissions;
}
catch (java.util.zip.ZipException ze) {
throw new ZipException(ze);
}
}
代码示例来源:origin: org.gosu-lang.aardvark/aardvark-core
@Override
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
return new ByteArrayInputStream(ze.getExtra());
}
}
代码示例来源:origin: biz.aQute/bndlib
ZipResource(ZipFile zip, ZipEntry entry, long lastModified) throws UnsupportedEncodingException {
this.zip = zip;
this.entry = entry;
this.lastModified = lastModified;
byte[] data = entry.getExtra();
if (data != null)
this.extra = new String(data, "UTF-8");
}
代码示例来源:origin: biz.aQute.bnd/bndlib
ZipResource(ZipFile zip, ZipEntry entry) throws UnsupportedEncodingException {
this.zip = zip;
this.entry = entry;
this.lastModified = -11L;
byte[] data = entry.getExtra();
if (data != null)
this.extra = new String(data, "UTF-8");
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
private ZipResource(ZipFile zip, ZipEntry entry, boolean closeZipFile) {
this.zip = zip;
this.entry = entry;
this.closeZipFile = closeZipFile;
lastModified = -11L;
size = entry.getSize();
byte[] data = entry.getExtra();
if (data != null) {
extra = new String(data, UTF_8);
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bnd
private ZipResource(ZipFile zip, ZipEntry entry, boolean closeZipFile) {
this.zip = zip;
this.entry = entry;
this.closeZipFile = closeZipFile;
lastModified = -11L;
size = entry.getSize();
byte[] data = entry.getExtra();
if (data != null) {
extra = new String(data, UTF_8);
}
}
代码示例来源:origin: redfish64/TinyTravelTracker
protected void writeExtraBytes(ZipEntry entry) throws IOException {
byte[] extraBytes = entry.getExtra();
if (extraBytes != null) {
writeBytes(extraBytes);
}
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-io
private static int getFilesCount(ZipEntry entry) throws IOException {
byte[] bytes = entry.getExtra();
if (bytes == null) {
return 0;
} else if (bytes.length != 4) {
throw new IOException("Invalid Nuxeo Archive");
} else {
return new DWord(bytes).getInt();
}
}
代码示例来源:origin: org.glassfish.main.common/common-util
@Override
public Payload.Part next() {
final Extra extra = new Extra(nextEntry.getExtra());
final Payload.Part part = new ZipPayloadImpl.Part(
nextEntry.getName(),
extra.getContentType(),
extra.getProperties(),
Inbound.this);
isNextEntryPrefetched = false;
return part;
}
代码示例来源:origin: com.google.code.findbugs/findbugs
public ZipEntry newZipEntry(ZipEntry ze) {
ZipEntry ze2 = new ZipEntry(ze.getName());
ze2.setComment(ze.getComment());
ze2.setTime(ze.getTime());
ze2.setExtra(ze.getExtra());
return ze2;
}
代码示例来源:origin: org.odftoolkit/odfdom-java
private void validateMimeTypeEntry(ZipEntry mimetypeEntry, String firstEntryName) {
if (mimetypeEntry.getMethod() != ZipEntry.STORED) {
logValidationError(OdfPackageConstraint.MIMETYPE_IS_COMPRESSED, getBaseURI());
}
if (mimetypeEntry.getExtra() != null) {
logValidationError(OdfPackageConstraint.MIMETYPE_HAS_EXTRA_FIELD, getBaseURI());
}
if (!OdfFile.MEDIA_TYPE.getPath().equals(firstEntryName)) {
logValidationError(OdfPackageConstraint.MIMETYPE_NOT_FIRST_IN_PACKAGE, getBaseURI());
}
}
代码示例来源:origin: org.apache.odftoolkit/odfdom-java
private void validateMimeTypeEntry(ZipEntry mimetypeEntry, String firstEntryName) throws SAXException {
if (mimetypeEntry.getMethod() != ZipEntry.STORED) {
logValidationError(OdfPackageConstraint.MIMETYPE_IS_COMPRESSED, getBaseURI());
}
if (mimetypeEntry.getExtra() != null) {
logValidationError(OdfPackageConstraint.MIMETYPE_HAS_EXTRA_FIELD, getBaseURI());
}
if (!OdfFile.MEDIA_TYPE.getPath().equals(firstEntryName)) {
logValidationError(OdfPackageConstraint.MIMETYPE_NOT_FIRST_IN_PACKAGE, getBaseURI());
}
}
内容来源于网络,如有侵权,请联系作者删除!