本文整理了Java中org.apache.tools.zip.ZipEntry.getName()
方法的一些代码示例,展示了ZipEntry.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.getName()
方法的具体详情如下:
包路径:org.apache.tools.zip.ZipEntry
类名称:ZipEntry
方法名:getName
[英]Get the name of the entry.
[中]获取条目的名称。
代码示例来源:origin: org.apache.ant/ant
/**
* Creates an exception.
* @param reason the feature that is not supported
* @param entry the entry using the feature
*/
public UnsupportedZipFeatureException(Feature reason,
ZipEntry entry) {
super("unsupported feature " + reason + " used in entry "
+ entry.getName());
this.reason = reason;
this.entry = entry;
}
代码示例来源:origin: org.apache.ant/ant
/**
* Helper to format "entry too big" messages.
*/
static String getEntryTooBigMessage(ZipEntry ze) {
return ze.getName() + "'s size exceeds the limit of 4GByte.";
}
代码示例来源:origin: org.apache.ant/ant
/**
* Is this entry a directory?
*
* @return true if the entry is a directory
* @since 1.10
*/
@Override
public boolean isDirectory() {
return getName().endsWith("/");
}
代码示例来源:origin: org.apache.ant/ant
/**
* Get the hashCode of the entry.
* This uses the name as the hashcode.
*
* @return a hashcode.
* @since Ant 1.7
*/
@Override
public int hashCode() {
// this method has severe consequences on performance. We cannot rely
// on the super.hashCode() method since super.getName() always return
// the empty string in the current implementation (there's no setter)
// so it is basically draining the performance of a hashmap lookup
return getName().hashCode();
}
代码示例来源:origin: org.apache.ant/ant
private ZipEncoding getEntryEncoding(ZipEntry ze) {
boolean encodable = zipEncoding.canEncode(ze.getName());
return !encodable && fallbackToUTF8
? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
}
代码示例来源:origin: org.apache.ant/ant
private ByteBuffer getName(ZipEntry ze) throws IOException {
return getEntryEncoding(ze).encode(ze.getName());
}
代码示例来源:origin: jenkinsci/jenkins
while (entries.hasMoreElements()) {
ZipEntry e = entries.nextElement();
File f = new File(dir, e.getName());
if (!f.toPath().normalize().startsWith(dir.toPath())) {
throw new IOException(
"Zip " + zipFile.getPath() + " contains illegal file name that breaks out of the target directory: " + e.getName());
代码示例来源:origin: org.apache.ant/ant
Set<String> dirSet = new HashSet<>();
StreamUtils.enumerationAsStream(zf.getEntries()).forEach(ze -> {
String name = ze.getName();
if (ze.isDirectory()) {
dirSet.add(name);
代码示例来源:origin: org.apache.ant/ant
/**
* Returns <code>true</code> if the file exists and is signed with
* the signature specified, or, if <code>name</code> wasn't
* specified, if the file contains a signature.
* @param zipFile the zipfile to check
* @param name the signature to check (may be killed)
* @return true if the file is signed.
* @throws IOException on error
*/
public static boolean isSigned(File zipFile, String name)
throws IOException {
try (ZipFile jarFile = new ZipFile(zipFile)) {
if (null == name) {
return StreamUtils.enumerationAsStream(jarFile.getEntries())
.anyMatch(e -> e.getName().startsWith(SIG_START) && e.getName().endsWith(SIG_END));
}
name = replaceInvalidChars(name);
boolean shortSig = jarFile.getEntry(SIG_START
+ name.toUpperCase()
+ SIG_END) != null;
boolean longSig = false;
if (name.length() > SHORT_SIG_LIMIT) {
longSig = jarFile.getEntry(
SIG_START
+ name.substring(0, SHORT_SIG_LIMIT).toUpperCase()
+ SIG_END) != null;
}
return shortSig || longSig;
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* Parses the given bytes as extra field data and consumes any
* unparseable data as an {@link UnparseableExtraFieldData}
* instance.
*
* @param extra an array of bytes to be parsed into extra fields
* @throws RuntimeException if the bytes cannot be parsed
* @throws RuntimeException on error
* @since 1.1
*/
@Override
public void setExtra(final byte[] extra) throws RuntimeException {
try {
final ZipExtraField[] local = ExtraFieldUtils.parse(extra, true,
ExtraFieldUtils.UnparseableExtraField.READ);
mergeExtraFields(local, true);
} catch (final ZipException e) {
// actually this is not be possible as of Ant 1.8.1
throw new RuntimeException("Error parsing extra fields for entry: " //NOSONAR
+ getName() + " - " + e.getMessage(), e);
}
}
代码示例来源:origin: org.apache.ant/ant
if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
|| !encodable) {
ze.addExtraField(new UnicodePathExtraField(ze.getName(),
name.array(),
name.arrayOffset(),
代码示例来源:origin: org.apache.ant/ant
StreamUtils.enumerationAsStream(zf.getEntries()).forEach(entry -> {
Resource r = new ZipResource(srcFile, encoding, entry);
String name = entry.getName();
if (entry.isDirectory()) {
name = trimSeparator(name);
代码示例来源:origin: org.apache.ant/ant
/**
* Writes the local file header entry
*
* @param ze the entry to write
* @throws IOException on error
* @since 1.1
*/
protected void writeLocalFileHeader(ZipEntry ze) throws IOException {
boolean encodable = zipEncoding.canEncode(ze.getName());
ByteBuffer name = getName(ze);
if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) {
addUnicodeExtraFields(ze, encodable, name);
}
final byte[] localHeader = createLocalFileHeader(ze, name, encodable);
final long localHeaderStart = written;
offsets.put(ze, localHeaderStart);
entry.localDataStart = localHeaderStart + LFH_CRC_OFFSET; // At crc offset
writeCounted(localHeader);
entry.dataStart = written;
}
代码示例来源:origin: org.apache.ant/ant
empty = false;
InputStream is = null;
log("extracting " + ze.getName(), Project.MSG_DEBUG);
try {
extractFile(fileUtils, srcF, dir,
ze.getName(), new Date(ze.getTime()),
ze.isDirectory(), mapper);
} finally {
代码示例来源:origin: org.apache.ant/ant
/**
* 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.
*
* @param ze ZipEntry
* @param originalNameBytes byte[]
* @param commentBytes byte[]
*/
static void setNameAndCommentFromExtraFields(ZipEntry ze,
byte[] originalNameBytes,
byte[] commentBytes) {
UnicodePathExtraField name = (UnicodePathExtraField)
ze.getExtraField(UnicodePathExtraField.UPATH_ID);
String originalName = ze.getName();
String newName = getUnicodeStringIfOriginalMatches(name,
originalNameBytes);
if (newName != null && !originalName.equals(newName)) {
ze.setName(newName);
}
if (commentBytes != null && commentBytes.length > 0) {
UnicodeCommentExtraField cmt = (UnicodeCommentExtraField)
ze.getExtraField(UnicodeCommentExtraField.UCOM_ID);
String newComment =
getUnicodeStringIfOriginalMatches(cmt, commentBytes);
if (newComment != null) {
ze.setComment(newComment);
}
}
}
代码示例来源:origin: org.apache.ant/ant
if (entry.entry.getCrc() != crc) {
throw new ZipException("bad CRC checksum for entry "
+ entry.entry.getName() + ": "
+ Long.toHexString(entry.entry.getCrc())
+ " instead of "
+ entry.entry.getName() + ": "
+ entry.entry.getSize()
+ " instead of "
代码示例来源:origin: org.apache.ant/ant
final String myName = getName();
final String otherName = other.getName();
if (myName == null) {
if (otherName != null) {
代码示例来源:origin: org.apache.ant/ant
final boolean encodable = zipEncoding.canEncode(ze.getName());
putShort(versionNeededToExtract(zipMethod, needsZip64Extra), buf, CFH_VERSION_NEEDED_OFFSET);
getGeneralPurposeBits(zipMethod, !encodable && fallbackToUTF8).encode(buf, CFH_GPB_OFFSET);
代码示例来源:origin: org.apache.ant/ant
private void setEntry(ZipEntry e) {
if (e == null) {
setExists(false);
return;
}
setName(e.getName());
setExists(true);
setLastModified(e.getTime());
setDirectory(e.isDirectory());
setSize(e.getSize());
setMode(e.getUnixMode());
extras = e.getExtraFields(true);
method = e.getMethod();
}
代码示例来源:origin: sanluan/PublicCMS
while (entryEnum.hasMoreElements()) {
ZipEntry zipEntry = entryEnum.nextElement();
String filePath = zipEntry.getName();
if (filePath.contains("..")) {
filePath = filePath.replace("..", Constants.BLANK);
内容来源于网络,如有侵权,请联系作者删除!