本文整理了Java中java.util.zip.ZipEntry.getName()
方法的一些代码示例,展示了ZipEntry.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.getName()
方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:getName
[英]Gets the name of this ZipEntry.
[中]获取这个ZipEntry的名称。
代码示例来源:origin: skylot/jadx
private static List<String> getZipFileList(File file) {
List<String> filesList = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(file)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
filesList.add(entry.getName());
}
} catch (Exception e) {
LOG.error("Error read zip file '{}'", file.getAbsolutePath(), e);
}
return filesList;
}
代码示例来源:origin: Activiti/Activiti
@Override
public Predicate<ZipEntry> filter(ZipEntry entry) {
return zipEntry -> !zipEntry.isDirectory() && zipEntry.getName().contains(PROCESSES);
}
代码示例来源:origin: gocd/gocd
public String getFileContentInsideZip(ZipInputStream zipInputStream, String file) throws IOException {
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
if (new File(zipEntry.getName()).getName().equals(file)) {
return IOUtils.toString(zipInputStream, UTF_8);
}
zipEntry = zipInputStream.getNextEntry();
}
return null;
}
代码示例来源:origin: stackoverflow.com
List<String> classNames = new ArrayList<String>();
ZipInputStream zip = new ZipInputStream(new FileInputStream("/path/to/jar/file.jar"));
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
// This ZipEntry represents a class. Now, what class does it represent?
String className = entry.getName().replace('/', '.'); // including ".class"
classNames.add(className.substring(0, className.length() - ".class".length()));
}
}
代码示例来源:origin: marytts/marytts
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
if (entry.isDirectory()) {
createDir(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
IOUtils.copy(inputStream, outputStream);
} finally {
outputStream.close();
inputStream.close();
}
}
代码示例来源:origin: cucumber/cucumber-jvm
private void moveToNext() {
next = null;
while (entries.hasMoreElements()) {
ZipEntry jarEntry = entries.nextElement();
String entryName = jarEntry.getName();
if (entryName.startsWith(path) && Helpers.hasSuffix(suffix, entryName)) {
next = new ZipResource(jarFile, jarEntry);
break;
}
}
}
}
代码示例来源:origin: stackoverflow.com
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
if (src != null) {
URL jar = src.getLocation();
ZipInputStream zip = new ZipInputStream(jar.openStream());
while(true) {
ZipEntry e = zip.getNextEntry();
if (e == null)
break;
String name = e.getName();
if (name.startsWith("path/to/your/dir/")) {
/* Do something with this entry. */
...
}
}
}
else {
/* Fail... */
}
代码示例来源:origin: nutzam/nutz
public static NutResource makeJarNutResource(String filePath) {
JarEntryInfo jeInfo = new JarEntryInfo(filePath);
try {
ZipInputStream zis = makeZipInputStream(jeInfo.getJarPath());
ZipEntry ens = null;
while (null != (ens = zis.getNextEntry())) {
if (ens.isDirectory())
continue;
if (jeInfo.getEntryName().equals(ens.getName())) {
return makeJarNutResource(jeInfo.getJarPath(), ens.getName(), "");
}
}
}
catch (IOException e) {}
return null;
}
代码示例来源:origin: syncany/syncany
@Override
public Chunk read() throws IOException {
ZipEntry entry = zipIn.getNextEntry();
if (entry == null) {
return null;
}
int read;
ByteArrayOutputStream contentByteArray = new ByteArrayOutputStream();
while (-1 != (read = zipIn.read())) {
contentByteArray.write(read);
}
return new Chunk(StringUtil.fromHex(entry.getName()), contentByteArray.toByteArray(), contentByteArray.size(), null);
}
代码示例来源:origin: gocd/gocd
public void handle(InputStream stream) throws IOException {
ZipInputStream zipInputStream = new ZipInputStream(stream);
LOG.info("[Agent Fetch Artifact] Downloading from '{}' to '{}'. Will read from Socket stream to compute MD5 and write to file", srcFile, destOnAgent.getAbsolutePath());
long before = System.currentTimeMillis();
new ZipUtil((entry, stream1) -> {
LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Handling the entry: '{}'", srcFile, destOnAgent.getAbsolutePath(), entry.getName());
new ChecksumValidator(artifactMd5Checksums).validate(getSrcFilePath(entry), md5Hex(stream1), checksumValidationPublisher);
}).unzip(zipInputStream, destOnAgent);
LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Took: {}ms", srcFile, destOnAgent.getAbsolutePath(), System.currentTimeMillis() - before);
}
代码示例来源:origin: Blankj/AndroidUtilCode
/**
* Return the files' path in ZIP file.
*
* @param zipFile The ZIP file.
* @return the files' path in ZIP file
* @throws IOException if an I/O error has occurred
*/
public static List<String> getFilesPath(final File zipFile)
throws IOException {
if (zipFile == null) return null;
List<String> paths = new ArrayList<>();
ZipFile zip = new ZipFile(zipFile);
Enumeration<?> entries = zip.entries();
while (entries.hasMoreElements()) {
String entryName = ((ZipEntry) entries.nextElement()).getName();
if (entryName.contains("../")) {
System.out.println("entryName: " + entryName + " is dangerous!");
paths.add(entryName);
} else {
paths.add(entryName);
}
}
zip.close();
return paths;
}
代码示例来源:origin: plantuml/plantuml
private InputStream getDataFromZip(InputStream is, String name) throws IOException {
final ZipInputStream zis = new ZipInputStream(is);
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
final String fileName = ze.getName();
if (ze.isDirectory()) {
} else if (fileName.equals(name)) {
return zis;
}
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
return null;
}
代码示例来源:origin: marytts/marytts
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
if (entry.isDirectory()) {
createDir(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
IOUtils.copy(inputStream, outputStream);
} finally {
outputStream.close();
inputStream.close();
}
}
代码示例来源:origin: skylot/jadx
public void load(File input) throws IOException, DecodeException {
String name = input.getName();
try (InputStream inputStream = new FileInputStream(input)) {
if (name.endsWith(CLST_EXTENSION)) {
load(inputStream);
} else if (name.endsWith(".jar")) {
try (ZipInputStream in = new ZipInputStream(inputStream)) {
ZipEntry entry = in.getNextEntry();
while (entry != null) {
if (entry.getName().endsWith(CLST_EXTENSION) && ZipSecurity.isValidZipEntry(entry)) {
load(in);
}
entry = in.getNextEntry();
}
}
} else {
throw new JadxRuntimeException("Unknown file format: " + name);
}
}
}
代码示例来源:origin: Atmosphere/atmosphere
private boolean accept(final ZipEntry entry) {
if (entry.isDirectory()) {
return false;
}
if (entryNameFilter == null) {
return true;
}
for (final String filter : entryNameFilter) {
if (entry.getName().startsWith(filter)) {
return true;
}
}
return false;
}
代码示例来源:origin: Activiti/Activiti
public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) {
try {
ZipEntry entry = zipInputStream.getNextEntry();
while (entry != null) {
if (!entry.isDirectory()) {
String entryName = entry.getName();
byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName);
ResourceEntity resource = resourceEntityManager.create();
resource.setName(entryName);
resource.setBytes(bytes);
deployment.addResource(resource);
}
entry = zipInputStream.getNextEntry();
}
} catch (Exception e) {
throw new ActivitiException("problem reading zip input stream", e);
}
return this;
}
代码示例来源:origin: nutzam/nutz
public InputStream getInputStream() throws IOException {
ZipInputStream zis = Scans.makeZipInputStream(jarPath);
ZipEntry ens = null;
while (null != (ens = zis.getNextEntry())) {
if (ens.getName().equals(entryName))
return zis;
}
throw Lang.impossible();
}
代码示例来源:origin: EngineHub/WorldEdit
@Override
public boolean isValid() {
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
ZipEntry testEntry = e.nextElement();
if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { // TODO: does this need a separate class?
return true;
}
}
return false;
}
}
代码示例来源:origin: plantuml/plantuml
public InputStream open() throws IOException {
final ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
final String fileName = ze.getName();
if (ze.isDirectory()) {
} else if (fileName.trim().equalsIgnoreCase(entry.trim())) {
return zis;
}
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
throw new IOException();
}
代码示例来源:origin: plantuml/plantuml
private void loadZipFile(File file) throws IOException {
this.entries.clear();
final PrintWriter pw = new PrintWriter("tmp.txt");
final ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
final String fileName = ze.getName();
this.entries.add(fileName);
if (fileName.endsWith("/") == false) {
pw.println("<file name=\"" + fileName + "\" />");
}
ze = zis.getNextEntry();
}
pw.close();
zis.close();
}
内容来源于网络,如有侵权,请联系作者删除!