本文整理了Java中java.util.zip.ZipInputStream.<init>()
方法的一些代码示例,展示了ZipInputStream.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipInputStream.<init>()
方法的具体详情如下:
包路径:java.util.zip.ZipInputStream
类名称:ZipInputStream
方法名:<init>
[英]Constructs a new ZipInputStream to read zip entries from the given input stream.
[中]构造一个新的ZipInputStream,从给定的输入流中读取zip条目。
代码示例来源:origin: nutzam/nutz
public static ZipInputStream makeZipInputStream(String jarPath) throws MalformedURLException,
IOException {
ZipInputStream zis = null;
try {
zis = new ZipInputStream(new FileInputStream(jarPath));
}
catch (IOException e) {
zis = new ZipInputStream(new URL(jarPath).openStream());
}
return zis;
}
代码示例来源:origin: stackoverflow.com
boolean isZipped = new ZipInputStream(yourInputStream).getNextEntry() != 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: airbnb/lottie-android
extension = FileExtension.Zip;
file = networkCache.writeTempCacheFile(connection.getInputStream(), extension);
result = LottieCompositionFactory.fromZipStreamSync(new ZipInputStream(new FileInputStream(file)), url);
break;
case "application/json":
extension = FileExtension.Json;
file = networkCache.writeTempCacheFile(connection.getInputStream(), extension);
result = LottieCompositionFactory.fromJsonInputStreamSync(new FileInputStream(new File(file.getAbsolutePath())), url);
break;
代码示例来源:origin: apache/ignite
/**
* @param zip Compressed file.
*/
public UnzipFileIO(File zip) throws IOException {
zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zip)));
ZipEntry entry = zis.getNextEntry();
size = entry.getSize();
}
代码示例来源:origin: geoserver/geoserver
public static void decompress(InputStream input, File destDir) throws IOException {
ZipInputStream zin = new ZipInputStream(input);
ZipEntry entry = null;
byte[] buffer = new byte[1024];
while ((entry = zin.getNextEntry()) != null) {
File f = getZipOutputFile(destDir, entry);
if (entry.isDirectory()) {
f.mkdirs();
continue;
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
int n = -1;
while ((n = zin.read(buffer)) != -1) {
out.write(buffer, 0, n);
}
out.flush();
out.close();
}
}
代码示例来源: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: apache/incubator-druid
} else if (fileName.endsWith(ZIP_SUFFIX)) {
final ZipInputStream zipIn = new ZipInputStream(in, StandardCharsets.UTF_8);
try {
final ZipEntry nextEntry = zipIn.getNextEntry();
if (nextEntry == null) {
zipIn.close();
zipIn.close();
代码示例来源: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: 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: gocd/gocd
@Test
public void shouldReturnNullIfTheFileByTheNameDoesNotExistInsideZip() throws IOException, URISyntaxException {
String contents = zipUtil.getFileContentInsideZip(new ZipInputStream(new FileInputStream(new File(getClass().getResource("/dummy-plugins.zip").toURI()))), "does_not_exist.txt");
assertThat(contents, is(nullValue()));
}
代码示例来源:origin: spotbugs/spotbugs
MyIterator() {
try {
zis = new ZipInputStream(new FileInputStream(file));
ze = zis.getNextEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: gocd/gocd
public void unzip(File zip, File destDir) throws IOException {
unzip(new ZipInputStream(new BufferedInputStream(new FileInputStream(zip))), destDir);
}
代码示例来源:origin: stackoverflow.com
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
List<String> list = new ArrayList<String>();
if( src != null ) {
URL jar = src.getLocation();
ZipInputStream zip = new ZipInputStream( jar.openStream());
ZipEntry ze = null;
while( ( ze = zip.getNextEntry() ) != null ) {
String entryName = ze.getName();
if( entryName.startsWith("images") && entryName.endsWith(".png") ) {
list.add( entryName );
}
}
}
webimages = list.toArray( new String[ list.size() ] );
代码示例来源:origin: h2oai/h2o-2
return bs;
case ZIP: {
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bs));
ZipEntry ze = zis.getNextEntry(); // Get the *FIRST* entry
break;
zis.close();
return bs; // Don't crash, ignore file if cannot unzip
代码示例来源:origin: SonarSource/sonarqube
/**
* Unzip a file to a directory.
*
* @param stream the zip input file
* @param toDir the target directory. It is created if needed.
* @param filter filter zip entries so that only a subset of directories/files can be
* extracted to target directory.
* @return the parameter {@code toDir}
* @since 6.2
*/
public static File unzip(InputStream stream, File toDir, Predicate<ZipEntry> filter) throws IOException {
if (!toDir.exists()) {
FileUtils.forceMkdir(toDir);
}
Path targetDirNormalizedPath = toDir.toPath().normalize();
try (ZipInputStream zipStream = new ZipInputStream(stream)) {
ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
if (filter.test(entry)) {
unzipEntry(entry, zipStream, targetDirNormalizedPath);
}
}
return toDir;
}
}
代码示例来源: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: gocd/gocd
@Test
public void shouldReadContentFromFileInsideZip() throws IOException, URISyntaxException {
String contents = zipUtil.getFileContentInsideZip(new ZipInputStream(new FileInputStream(new File(getClass().getResource("/dummy-plugins.zip").toURI()))), "version.txt");
assertThat(contents, is("13.3.0(17222-4c7fabcb9c9e9c)"));
}
代码示例来源:origin: graphhopper/graphhopper
@Override
byte[] readFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
ZipInputStream zis = new ZipInputStream(is);
zis.getNextEntry();
BufferedInputStream buff = new BufferedInputStream(zis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[0xFFFF];
int len;
while ((len = buff.read(buffer)) > 0) {
os.write(buffer, 0, len);
}
os.flush();
Helper.close(buff);
return os.toByteArray();
}
代码示例来源:origin: com.h2database/h2
in = new GZIPInputStream(in);
} else if ("ZIP".equals(compressionAlgorithm)) {
ZipInputStream z = new ZipInputStream(in);
while (true) {
ZipEntry entry = z.getNextEntry();
if (entry == null) {
return null;
if (entryName.equals(entry.getName())) {
break;
内容来源于网络,如有侵权,请联系作者删除!