当前位置: 首页>>代码示例>>Java>>正文


Java ZipInputStream.read方法代码示例

本文整理汇总了Java中java.util.zip.ZipInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java ZipInputStream.read方法的具体用法?Java ZipInputStream.read怎么用?Java ZipInputStream.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.ZipInputStream的用法示例。


在下文中一共展示了ZipInputStream.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ZipFullEntry

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public ZipFullEntry(ZipInputStream stream, ZipEntry e, boolean isParentJarFile) {
    insideJar = isParentJarFile;
    entry = e;
    contentsGetter = () -> {
        try {
            long size = e.getSize();
            // Note: This will fail to properly read 2gb+ files, but we have other problems if that's in this JAR file.
            if (size <= 0) {
                return Optional.empty();
            }
            byte[] buffer = new byte[(int) size];
            stream.read(buffer);
            return Optional.of(new ByteInputStream(new byte[(int) e.getSize()], buffer.length));
        } catch (IOException ex) {
            Logger.getLogger(ZipFullEntry.class.getName()).log(Level.SEVERE, null, ex);
            return Optional.empty();
        }
    };
}
 
开发者ID:Adobe-Consulting-Services,项目名称:aem-epic-tool,代码行数:20,代码来源:ZipFullEntry.java

示例2: saveZippedProgramTraceFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Test
public void saveZippedProgramTraceFile() throws Exception {
    Path traceFilePath = tempRule.newFolder().toPath();
    ProgramTrace mockTrace = new ProgramTrace(ConfigHelper.CONFIG);
    String mockTxHash = "1234";

    VMUtils.saveProgramTraceFile(
            traceFilePath,
            mockTxHash,
            true,
            mockTrace
    );

    ZipInputStream zipIn = new ZipInputStream(Files.newInputStream(traceFilePath.resolve(mockTxHash + ".zip")));
    ZipEntry zippedTrace = zipIn.getNextEntry();
    Assert.assertThat(zippedTrace.getName(), is(mockTxHash + ".json"));
    ByteArrayOutputStream unzippedTrace = new ByteArrayOutputStream();
    byte[] traceBuffer = new byte[2048];
    int len;
    while ((len = zipIn.read(traceBuffer)) > 0) {
        unzippedTrace.write(traceBuffer, 0, len);
    }
    Assert.assertThat(new String(unzippedTrace.toByteArray()), is(Serializers.serializeFieldsOnly(mockTrace, true)));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:VMUtilsTest.java

示例3: getZipLength

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private static long getZipLength(final File zipFile) {
    int count;
    long totalSize = 0;
    byte[] buffer = new byte[BUFFER_SIZE];
    try {
        final ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));

        ZipEntry ze;
        while ((ze = in.getNextEntry()) != null) {
            if (!ze.isDirectory()) {
                if (ze.getSize() == -1) {
                    while ((count = in.read(buffer)) != -1)
                        totalSize += count;
                } else {
                    totalSize += ze.getSize();
                }
            }
        }

        in.close();
        return totalSize;
    } catch (IOException ignored) {
        return -1;
    }
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:26,代码来源:ZipUtils.java

示例4: unzipRemoteFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unzipRemoteFile(String localFileName, String directoryPath){
    try  {
        FileInputStream fin = new FileInputStream(localFileName);
        ZipInputStream zin = new ZipInputStream(fin);
        ZipEntry ze = null;
        while ((ze = zin.getNextEntry()) != null) {
            Log.v("Decompress", "Unzipping " + ze.getName());

            if(ze.isDirectory()) {
                Common.dirChecker(directoryPath + File.separator + ze.getName());
            } else {
                FileOutputStream fout = new FileOutputStream(directoryPath + File.separator + ze.getName());
                for (int c = zin.read(); c != -1; c = zin.read()) {
                    fout.write(c);
                }

                zin.closeEntry();
                fout.close();
            }

        }
        zin.close();
    } catch(Exception e) {
        Log.e("Decompress", "unzip", e);
    }
}
 
开发者ID:csarron,项目名称:renderscript_examples,代码行数:27,代码来源:Unzip.java

示例5: unZip

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static boolean unZip(File zipFile, File outDir) {
    try {
        if (!outDir.exists() && !outDir.mkdirs()) {
            return false;
        }
        ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
        while (true) {
            ZipEntry ze = zin.getNextEntry();
            if (ze != null) {
                Log.d("wlx", "Unzipping " + ze.getName());
                if (ze.isDirectory()) {
                    mkDir(ze.getName(), outDir.getAbsolutePath());
                } else {
                    FileOutputStream fout = new FileOutputStream(outDir + "/" + ze.getName());
                    byte[] data = new byte[2048];
                    while (true) {
                        int count = zin.read(data, 0, 2048);
                        if (count == -1) {
                            break;
                        }
                        fout.write(data, 0, count);
                    }
                    zin.closeEntry();
                    fout.close();
                }
            } else {
                zin.close();
                return true;
            }
        }
    } catch (Exception e) {
        Log.e("wlx", "unzip", e);
        return false;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:36,代码来源:PatchUtils.java

示例6: decompressForZip

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
 * Zip解压数据
 *
 * @param zipStr
 * @return
 */
public static String decompressForZip(String zipStr) {

    if (TextUtils.isEmpty(zipStr)) {
        return "0";
    }
    byte[] t = Base64.decode(zipStr, Base64.DEFAULT);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream in = new ByteArrayInputStream(t);
        ZipInputStream zip = new ZipInputStream(in);
        zip.getNextEntry();
        byte[] buffer = new byte[1024];
        int n = 0;
        while ((n = zip.read(buffer, 0, buffer.length)) > 0) {
            out.write(buffer, 0, n);
        }
        zip.close();
        in.close();
        out.close();
        return out.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "0";
}
 
开发者ID:SailFlorve,项目名称:RunHDU,代码行数:32,代码来源:ZipUtil.java

示例7: unzipFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@SuppressWarnings("TryFinallyCanBeTryWithResources")
public static void unzipFile(File zipFile, File targetDirectory) throws IOException {

    ZipInputStream zis = new ZipInputStream(
            new BufferedInputStream(new FileInputStream(zipFile)));
    try {
        ZipEntry ze;
        int count;
        byte[] buffer = new byte[8192];
        while ((ze = zis.getNextEntry()) != null) {
            File file = new File(targetDirectory, ze.getName());
            File dir = ze.isDirectory() ? file : file.getParentFile();
            if (!dir.isDirectory() && !dir.mkdirs()) {
                throw new FileNotFoundException("Failed to ensure directory: " +
                        dir.getAbsolutePath());
            }
            if (ze.isDirectory()) {
                continue;
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                while ((count = zis.read(buffer)) != -1) {
                    fileOutputStream.write(buffer, 0, count);
                }
            }
            finally {
                fileOutputStream.close();
            }
        }
    }
    finally {
        zis.close();
    }
}
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:35,代码来源:FileUtils.java

示例8: uncompress

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static boolean uncompress(File zipFile) {
    boolean success = false;
    try {
        FileInputStream fis = new FileInputStream(zipFile);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry;
        File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
        destFolder.mkdirs();
        while ((entry = zis.getNextEntry()) != null) {
            File dest = new File(destFolder, entry.getName());
            dest.getParentFile().mkdirs();

            if(entry.isDirectory()) {
                if (!dest.exists()) {
                    dest.mkdirs();
                }
            } else {
                int size;
                byte[] buffer = new byte[2048];
                FileOutputStream fos = new FileOutputStream(dest);
                BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
                while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
                IoUtils.flushQuietly(bos);
                IoUtils.closeQuietly(bos);
            }
            zis.closeEntry();
        }
        IoUtils.closeQuietly(zis);
        IoUtils.closeQuietly(fis);
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return success;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:40,代码来源:FileUtils.java

示例9: extractFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private static void extractFile(ZipInputStream zipIn, File file) throws IOException
{
   BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
   byte[] bytesIn = new byte[BUFFER_SIZE];
   int read;
   while ((read = zipIn.read(bytesIn)) != -1)
   {
      bos.write(bytesIn, 0, read);
   }
   bos.close();
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:12,代码来源:UnzipHelper.java

示例10: unpackZipFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
 * Unpacks a ZIP file to disk.
 * All entries are unpacked, even {@code META-INF/MANIFEST.MF} if present.
 * Parent directories are created as needed (even if not mentioned in the ZIP);
 * empty ZIP directories are created too.
 * Existing files are overwritten.
 * @param zip a ZIP file
 * @param dir the base directory in which to unpack (need not yet exist)
 * @throws IOException in case of problems
 */
public static void unpackZipFile(File zip, File dir) throws IOException {
    byte[] buf = new byte[8192];
    InputStream is = new FileInputStream(zip);
    try {
        ZipInputStream zis = new ZipInputStream(is);
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();
            int slash = name.lastIndexOf('/');
            File d = new File(dir, name.substring(0, slash).replace('/', File.separatorChar));
            if (!d.isDirectory() && !d.mkdirs()) {
                throw new IOException("could not make " + d);
            }
            if (slash != name.length() - 1) {
                File f = new File(dir, name.replace('/', File.separatorChar));
                OutputStream os = new FileOutputStream(f);
                try {
                    int read;
                    while ((read = zis.read(buf)) != -1) {
                        os.write(buf, 0, read);
                    }
                } finally {
                    os.close();
                }
            }
        }
    } finally {
        is.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:TestFileUtils.java

示例11: unzip

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unzip(ZipInputStream zis, File targetDirectory) throws IOException {
    try {
        ZipEntry ze;
        int count;
        byte[] buffer = new byte[BUFFER_SIZE];
        while ((ze = zis.getNextEntry()) != null) {
            File file = new File(targetDirectory, ze.getName());
            File dir = ze.isDirectory() ? file : file.getParentFile();
            if (!dir.isDirectory() && !dir.mkdirs())
                throw new FileNotFoundException("Failed to ensure directory: " +
                        dir.getAbsolutePath());
            if (ze.isDirectory())
                continue;
            FileOutputStream fout = new FileOutputStream(file);
            try {
                while ((count = zis.read(buffer)) != -1)
                    fout.write(buffer, 0, count);
            } finally {
                fout.close();
            }
        /* if time should be restored as well
        long time = ze.getTime();
        if (time > 0)
            file.setLastModified(time);
        */
        }
    } finally {
        zis.close();
    }
}
 
开发者ID:BloomBooks,项目名称:BloomReader,代码行数:31,代码来源:IOUtilities.java

示例12: unzipAll

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static List<File> unzipAll(File file) throws IOException {
    int bufferLength = 2048;
    byte buffer[] = new byte[bufferLength];
    List<File> foundFiles = new ArrayList<File>();
    ZipInputStream zipInputStream = new ZipInputStream(
            new BufferedInputStream(new FileInputStream(file)));
    ZipEntry entry;
    File tempDir = File.createTempFile("unzipped" + UUID.randomUUID(), "", new File(System
            .getProperty("java.io.tmpdir")));
    tempDir.delete();
    tempDir.mkdir();
    while ((entry = zipInputStream.getNextEntry()) != null) {
        int count;
        File entryFile = new File(tempDir, entry.getName());
        entryFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(entryFile);
        BufferedOutputStream dest = new BufferedOutputStream(fos,
                bufferLength);
        while ((count = zipInputStream.read(buffer, 0, bufferLength)) != -1) {
            dest.write(buffer, 0, count);
        }
        dest.flush();
        dest.close();

        foundFiles.add(entryFile);

    }

    zipInputStream.close();

    deleteResources(file);

    return foundFiles;
}
 
开发者ID:52North,项目名称:javaps-geotools-backend,代码行数:35,代码来源:IOUtils.java

示例13: unzip

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private byte[] unzip( byte[] input_data ) throws Exception
{
	ZipInputStream zipStream = new ZipInputStream( new ByteArrayInputStream( input_data ) );
	ZipEntry entry = null;

	byte[] result = null;

	while ( (entry = zipStream.getNextEntry()) != null )
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();

		byte[] buff = new byte[1024];

		int count = 0, loop = 0;

		while ( (count = zipStream.read( buff )) != -1 )
		{
			baos.write( buff, 0, count );
			// NLog.i("[OfflineFileParser] unzip read loop : " + loop);
			if ( loop++ > 1048567 )
			{
				throw new Exception();
			}
		}

		result = baos.toByteArray();

		zipStream.closeEntry();
	}

	zipStream.close();

	return result;
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:35,代码来源:OfflineFileParser.java

示例14: copyToByteArrayInputStream

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
protected ByteArrayInputStream copyToByteArrayInputStream(ZipInputStream warInputStream) throws IOException {

	ByteArrayOutputStream os = new ByteArrayOutputStream();
	byte[] data = new byte[BUFFER_SIZE];
	int count = -1;
	while ((count = warInputStream.read(data, 0, BUFFER_SIZE)) != -1) {
	    os.write(data, 0, count);
	}
	os.close();

	return new ByteArrayInputStream(os.toByteArray());
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:UpdateWarTask.java

示例15: getRemoteClasses

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private static List<RemoteClass> getRemoteClasses() throws IOException {
    InputStream in = RemoteServices.class.getResourceAsStream(REMOTE_CLASSES_ZIPFILE);
    try {
        ZipInputStream zin = new ZipInputStream(in);
        ZipEntry ze;
        List<RemoteClass> rcl = new ArrayList<RemoteClass>();
        while((ze = zin.getNextEntry()) != null) {
            String fileName = ze.getName();
            if (!fileName.endsWith(".class")) {
                continue;
            }
            String name = fileName.substring(0, fileName.length() - ".class".length());
            int baseStart = name.lastIndexOf('/');
            if (baseStart < 0) {
                continue;
            }
            /*baseStart++;
            int baseEnd = name.indexOf('$', baseStart);
            if (baseEnd < 0) {
                baseEnd = name.length();
            }*/
            RemoteClass rc = new RemoteClass();
            rc.name = name.replace('/', '.');
            int l = (int) ze.getSize();
            byte[] bytes = new byte[l];
            int num = 0;
            while (num < l) {
                int r = zin.read(bytes, num, l - num);
                if (r < 0) {
                    Exceptions.printStackTrace(new IllegalStateException("Can not read full content of "+name+" entry. Length = "+l+", read num = "+num));
                    break;
                }
                num += r;
            }
            rc.bytes = bytes;
            rcl.add(rc);
        }
        return rcl;
    } finally {
        in.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:RemoteServices.java


注:本文中的java.util.zip.ZipInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。