本文整理了Java中java.util.zip.ZipFile.stream()
方法的一些代码示例,展示了ZipFile.stream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipFile.stream()
方法的具体详情如下:
包路径:java.util.zip.ZipFile
类名称:ZipFile
方法名:stream
暂无
代码示例来源:origin: apache/geode
private static Set<String> getZipEntries(String zipFilePath) throws IOException {
return new ZipFile(zipFilePath).stream().map(ZipEntry::getName)
.filter(x -> !x.endsWith("views.log")).collect(Collectors.toSet());
}
}
代码示例来源:origin: graphhopper/graphhopper
checksum = zip.stream().mapToLong(ZipEntry::getCrc).reduce((l1, l2) -> l1 ^ l2).getAsLong();
代码示例来源:origin: google/bundletool
public static Stream<? extends ZipEntry> allFileEntries(ZipFile zipFile) {
return zipFile.stream().filter(not(ZipEntry::isDirectory));
}
代码示例来源:origin: google/bundletool
/** Extracts paths of all files having the given path prefix. */
public static ImmutableList<String> filesUnderPath(ZipFile zipFile, ZipPath pathPrefix) {
return zipFile.stream()
.map(ZipEntry::getName)
.filter(entryName -> ZipPath.create(entryName).startsWith(pathPrefix))
.collect(toImmutableList());
}
代码示例来源:origin: google/bundletool
private BundleModule toBundleModule(ZipFile moduleZipFile) {
BundleModule bundleModule;
try {
bundleModule =
BundleModule.builder()
// Assigning a temporary name because the real one will be extracted from the
// manifest, but this requires the BundleModule to be built.
.setName(BundleModuleName.create("TEMPORARY_MODULE_NAME"))
.setBundleConfig(EMPTY_CONFIG_WITH_CURRENT_VERSION)
.addEntries(
moduleZipFile.stream()
.filter(not(ZipEntry::isDirectory))
.map(zipEntry -> ModuleZipEntry.fromModuleZipEntry(zipEntry, moduleZipFile))
.collect(toImmutableList()))
.build();
} catch (IOException e) {
throw new UncheckedIOException(
String.format("Error reading module zip file '%s'.", moduleZipFile.getName()), e);
}
BundleModuleName actualModuleName =
BundleModuleName.create(
bundleModule
.getAndroidManifest()
.getSplitId()
.orElse(BundleModuleName.BASE_MODULE_NAME));
return bundleModule.toBuilder().setName(actualModuleName).build();
}
}
代码示例来源:origin: opendaylight/yangtools
private static Collection<ScannedDependency> scanZipFile(final File zipFile) throws IOException {
final Collection<String> entryNames;
try (ZipFile zip = new ZipFile(zipFile)) {
entryNames = zip.stream().filter(entry -> {
final String entryName = entry.getName();
return entryName.startsWith(META_INF_YANG_STRING_JAR) && !entry.isDirectory()
&& entryName.endsWith(RFC6020_YANG_FILE_EXTENSION);
}).map(ZipEntry::getName).collect(ImmutableList.toImmutableList());
}
return entryNames.isEmpty() ? ImmutableList.of() : ImmutableList.of(new Zip(zipFile, entryNames));
}
代码示例来源:origin: jbosstm/narayana
/**
* Traversing jar file and loading all '.class' files by provided classloader.
*
* @param pathToJar where jar file resides
* @param classLoader class loader used for loading classes
* @return list of loaded classes
*/
public static List<Class<?>> loadFromJar(final File pathToJar, final ClassLoader classLoader) throws MojoFailureException {
try (ZipFile zipFile = new ZipFile(pathToJar)) {
Stream<String> stream = zipFile.stream()
.filter(zipEntry -> !zipEntry.isDirectory())
.map(zipEntry -> zipEntry.getName());
return processStream(stream, classLoader, pathToJar);
} catch (IOException ioe) {
throw new MojoFailureException("Can't read from jar file '" + pathToJar + "'", ioe);
}
}
代码示例来源:origin: com.github.redhatqe.byzantine/byzantine
/**
* Given the path to a jar file, get all the .class files
* @param jarPath
* @param pkg
*/
static List<String> getClasses(String jarPath, String pkg) throws IOException {
try(ZipFile zf = new ZipFile(jarPath)) {
return zf.stream()
.filter(e -> !e.isDirectory() && e.getName().endsWith(".class") && !e.getName().contains("$"))
.map(e -> {
String className = e.getName().replace('/', '.');
String test = className.substring(0, className.length() - ".class".length());
return test;
})
.filter(e -> e.contains(pkg))
.collect(Collectors.toList());
}
}
代码示例来源:origin: angular/clutz
/**
* Helper function helps read the entries in a zipfile and returns a list of only the javascript
* files (i.e files ending in .js).
*
* <p>Closure supports loading source files as {@code foo.zip!/path/in/zip.js}.
*/
static List<Path> getJsEntryPathsFromZip(String source) {
try (ZipFile zipFile = new ZipFile(source)) {
return zipFile
.stream()
.filter(e -> !e.isDirectory())
.filter(e -> e.getName().endsWith(".js"))
.map(e -> source + "!/" + e.getName())
.map(Paths::get)
.collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException("failed to read zip file " + source, e);
}
}
代码示例来源:origin: senbox-org/s1tbx
private boolean isDirectory(final String path) throws IOException {
if (productDir.isCompressed()) {
if (path.contains(".")) {
int sepIndex = path.lastIndexOf('/');
int dotIndex = path.lastIndexOf('.');
return dotIndex < sepIndex;
} else {
final ZipFile productZip = new ZipFile(baseDir, ZipFile.OPEN_READ);
final Optional result = productZip.stream()
.filter(ze -> ze.isDirectory()).filter(ze -> ze.getName().equals(path)).findFirst();
return result.isPresent();
}
} else {
return productDir.getFile(path).isDirectory();
}
}
代码示例来源:origin: fstab/promagent
/**
* List all Java classes found in the JAR files.
*
*/
private static Set<String> listAllJavaClasses(Set<Path> hookJars, Predicate<String> classNameFilter) throws IOException {
Set<String> result = new TreeSet<>();
for (Path hookJar : hookJars) {
// For convenient testing, hookJar may be a classes/ directory instead of a JAR file.
if (hookJar.toFile().isDirectory()) {
try (Stream<Path> dirEntries = Files.walk(hookJar)) {
addClassNames(dirEntries.map(hookJar::relativize).map(Path::toString), result, classNameFilter);
}
}
else if (hookJar.toFile().isFile()) {
try (ZipFile zipFile = new ZipFile(hookJar.toFile())) {
addClassNames(zipFile.stream().map(ZipEntry::getName), result, classNameFilter);
}
} else {
throw new IOException(hookJar + ": Failed to read file or directory.");
}
}
return result;
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-osgidistribution
protected boolean loadFromCatalog(String basePhysicalIRI, ZipFile z) throws IOException {
ZipEntry yaml = z.stream().filter(e -> CATALOG_PATTERN.matcher(e.getName()).matches())
.findFirst().orElse(null);
if (yaml == null) {
return false;
}
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(z.getInputStream(yaml));
NodeList uris = doc.getElementsByTagName("uri");
for (int i = 0; i < uris.getLength(); i++) {
// Catalogs do not have a way to indicate root ontologies; all ontologies will be
// considered root.
// Duplicate entries are unsupported; entries whose name starts with duplicate: will
// cause mismatches
Element e = (Element) uris.item(i);
IRI physicalIRI = IRI.create(basePhysicalIRI + e.getAttribute("uri"));
physicalRoots.add(physicalIRI);
String name = e.getAttribute("name");
if (name.startsWith("duplicate:")) {
name = name.replace("duplicate:", "");
}
logicalToPhysicalIRI.put(IRI.create(name), physicalIRI);
}
return true;
} catch (SAXException | ParserConfigurationException e1) {
throw new IOException(e1);
}
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-distribution
protected boolean loadFromCatalog(String basePhysicalIRI, ZipFile z) throws IOException {
ZipEntry yaml = z.stream().filter(e -> CATALOG_PATTERN.matcher(e.getName()).matches())
.findFirst().orElse(null);
if (yaml == null) {
return false;
}
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(z.getInputStream(yaml));
NodeList uris = doc.getElementsByTagName("uri");
for (int i = 0; i < uris.getLength(); i++) {
// Catalogs do not have a way to indicate root ontologies; all ontologies will be
// considered root.
// Duplicate entries are unsupported; entries whose name starts with duplicate: will
// cause mismatches
Element e = (Element) uris.item(i);
IRI physicalIRI = IRI.create(basePhysicalIRI + e.getAttribute("uri"));
physicalRoots.add(physicalIRI);
String name = e.getAttribute("name");
if (name.startsWith("duplicate:")) {
name = name.replace("duplicate:", "");
}
logicalToPhysicalIRI.put(IRI.create(name), physicalIRI);
}
return true;
} catch (SAXException | ParserConfigurationException e1) {
throw new IOException(e1);
}
}
代码示例来源:origin: owlcs/owlapi
protected boolean loadFromCatalog(String basePhysicalIRI, ZipFile z) throws IOException {
ZipEntry yaml = z.stream().filter(e -> CATALOG_PATTERN.matcher(e.getName()).matches())
.findFirst().orElse(null);
if (yaml == null) {
return false;
}
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(z.getInputStream(yaml));
NodeList uris = doc.getElementsByTagName("uri");
for (int i = 0; i < uris.getLength(); i++) {
// Catalogs do not have a way to indicate root ontologies; all ontologies will be
// considered root.
// Duplicate entries are unsupported; entries whose name starts with duplicate: will
// cause mismatches
Element e = (Element) uris.item(i);
IRI physicalIRI = IRI.create(basePhysicalIRI + e.getAttribute("uri"));
physicalRoots.add(physicalIRI);
String name = e.getAttribute("name");
if (name.startsWith("duplicate:")) {
name = name.replace("duplicate:", "");
}
logicalToPhysicalIRI.put(IRI.create(name), physicalIRI);
}
return true;
} catch (SAXException | ParserConfigurationException e1) {
throw new IOException(e1);
}
}
代码示例来源:origin: org.wso2.carbon.uuf/org.wso2.carbon.uuf.core
/**
* @param zipFile zip app
* @return app name
* @exception FileOperationException I/O error
*/
public static String getAppName(Path zipFile) {
ZipFile zip = null;
try {
zip = new ZipFile(zipFile.toFile());
ZipEntry firstEntry = zip.stream()
.findFirst()
.orElseThrow(() -> new FileOperationException("Cannot find app directory in zip artifact '" +
zipFile + "'."));
if (firstEntry.isDirectory()) {
return Paths.get(firstEntry.getName()).getFileName().toString();
} else {
throw new FileOperationException(
"Cannot find an app directory inside the zip artifact '" + zipFile + "'.");
}
} catch (IOException e) {
throw new FileOperationException(
"An error occurred when opening zip artifact '" + zipFile + "'.", e);
} finally {
IOUtils.closeQuietly(zip);
}
}
代码示例来源:origin: io.github.xfournet.jconfig/jconfig
@Override
public void merge(Path source) {
if (Files.isDirectory(source)) {
merge(walkDirectory(source).stream().map(path -> new PathFileEntry(source.resolve(path), path)));
} else {
try (ZipFile zipFile = new ZipFile(source.toFile())) {
Stream<? extends FileEntry> contentStream = zipFile.stream().
filter(e -> !e.isDirectory()).
map(e -> new ZipFileEntry(zipFile, e)).
filter(fe -> m_pathFilter.test(fe.path()));
merge(contentStream);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
代码示例来源:origin: itsallcode/openfasttrace
@Override
public void runImport()
{
if (!this.file.isRealFile())
{
throw new UnsupportedOperationException(
"Importing a zip file from a stream is not supported");
}
try (ZipFile zip = new ZipFile(this.file.toPath().toFile(), StandardCharsets.UTF_8))
{
zip.stream() //
.filter(entry -> !entry.isDirectory()) //
.map(entry -> createInput(zip, entry)) //
.forEach(this.delegateImporter::importFile);
}
catch (final IOException e)
{
throw new ImporterException("Error reading \"" + this.file + "\"", e);
}
}
代码示例来源:origin: itsallcode/openfasttrace
@Override
public void runImport()
{
if (!this.file.isRealFile())
{
throw new UnsupportedOperationException(
"Importing a zip file from a stream is not supported");
}
try (ZipFile zip = new ZipFile(this.file.toPath().toFile(), StandardCharsets.UTF_8))
{
zip.stream() //
.filter(entry -> !entry.isDirectory()) //
.map(entry -> createInput(zip, entry)) //
.forEach(this.delegateImporter::importFile);
}
catch (final IOException e)
{
throw new ImporterException("Error reading \"" + this.file + "\"", e);
}
}
代码示例来源:origin: fergarrui/custom-bytecode-analyzer
List<ReportItem> reportItems = new ArrayList<>();
ZipFile zipFile = new ZipFile(jarFile);
zipFile.stream().filter(ArchiveAnalyzerCallable::isClassFile)
.forEach(zipEntry -> {
try {
代码示例来源:origin: gradle.plugin.com.greensopinion.gradle-android-eclipse/gradle-android-eclipse
zipFile.stream().forEach(f -> {
if (f.getName().endsWith(".jar")) {
String targetName = jarId + ".jar";
内容来源于网络,如有侵权,请联系作者删除!