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


Java ZipInputStream.getNextEntry方法代码示例

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


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

示例1: 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

示例2: saveEntries

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void saveEntries(Path tempDirectory, String rootEntryName, long maxZipEntrySize) throws IOException, FileNotFoundException {
    ZipInputStream zis = (ZipInputStream) inputStream;
    for (ZipEntry e; (e = zis.getNextEntry()) != null;) {
        String currentEntryName = e.getName();
        if (!e.getName().startsWith(rootEntryName)) {
            continue;
        }
        validateZipEntrySize(e, maxZipEntrySize);
        validateEntry(currentEntryName);
        Path filePath = resolveTempEntryPath(currentEntryName, rootEntryName, tempDirectory);
        if (e.getName().endsWith(ARCHIVE_ENTRY_SEPARATOR)) {
            Files.createDirectories(filePath);
        } else {
            createFile(filePath);
        }
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:18,代码来源:StreamUtil.java

示例3: unZipFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unZipFile(InputStream source, FileObject rootFolder) throws IOException {
    try {
        ZipInputStream str = new ZipInputStream(source);
        ZipEntry entry;
        while ((entry = str.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                FileUtil.createFolder(rootFolder, entry.getName());
                continue;
            }
            FileObject fo = FileUtil.createData(rootFolder, entry.getName());
            FileLock lock = fo.lock();
            try {
                OutputStream out = fo.getOutputStream(lock);
                try {
                    FileUtil.copy(str, out);
                } finally {
                    out.close();
                }
            } finally {
                lock.releaseLock();
            }
        }
    } finally {
        source.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TestUtils.java

示例4: zipAndUnzipWrongEncodedBytes

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void zipAndUnzipWrongEncodedBytes() throws IOException {
    
    ZipOutputOf<byte[]> zos = IoStream.bytes().zipOutputStream("UTF-16");
    try {
        zos.putNextEntry(new ZipEntry("ééé"));
        zos.write("aaaaaaa".getBytes());
    } finally {
        zos.close();
    }
    
    ZipInputStream zis = IoStream.bytes(zos.get()).zipInputStream("UTF-8");
    try {
        ZipEntry ze = zis.getNextEntry();
        assertThat(ze.getName()).isEqualTo("ééé");
    } finally {
        zis.close();
    }
}
 
开发者ID:fralalonde,项目名称:iostream,代码行数:20,代码来源:ZipStreamTest.java

示例5: saveEntries

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private static void saveEntries(Path tempDirectory, String rootEntryName, InputStream inputStream)
    throws IOException, FileNotFoundException {
    ZipInputStream zis = (ZipInputStream) inputStream;
    for (ZipEntry e; (e = zis.getNextEntry()) != null;) {
        String currentEntryName = e.getName();
        if (!e.getName().startsWith(rootEntryName)) {
            continue;
        }
        validateEntry(currentEntryName);
        Path filePath = resolveTempEntryPath(currentEntryName, rootEntryName, tempDirectory);
        if (e.getName().endsWith(ARCHIVE_ENTRY_SEPARATOR)) {
            Files.createDirectories(filePath);
        } else {
            createFile(filePath, inputStream);
        }
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:18,代码来源:StreamUtil.java

示例6: 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

示例7: loadMetaData

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private ImmutableList<String> loadMetaData() {
    final Optional<String> token = remoteTokenService.getToken();
    if (!token.isPresent()) {
        LOGGER.error("unable to obtain auth token. not trying to fetch the latest meta data");
        return null;
    }
    try {
        final InputStream body = downloadLatestMetadataZip(token.get());
        if (body == null) {
            return ImmutableList.of(); //no metadata loaded
        }
        final ZipInputStream zis = new ZipInputStream(body);
        ZipEntry entry;

        ImmutableList<String> ret = null;
        while ((entry = zis.getNextEntry()) != null) {
            final String entryName = entry.getName();

            if (entryName.equals("fileinfo")) {
                ret = readSiaPathsFromInfo(zis);
            } else {
                digestSiaFile(entry, zis);
            }
        }
        //one of those files must have been fileinfo...
        if (ret == null) {
            LOGGER.warn("fileinfo not found in metadata");
            return ImmutableList.of();
        } else {
            LOGGER.info("loaded backup from metadata service");
        }
        return ret;
    } catch (UnirestException | IOException e) {
        LOGGER.error("unable to load backup from metadata service");
        return null;
    }
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:38,代码来源:DownloadFactory.java

示例8: unzipSource

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private ByteSource unzipSource(ByteSource byteSource) {
    return new ByteSource() {
        @Override
        public InputStream openStream() throws IOException {
            ZipInputStream zipInputStream = new ZipInputStream(byteSource.openBufferedStream());
            zipInputStream.getNextEntry();//一个zip里面就一个文件
            return zipInputStream;
        }
    };
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:11,代码来源:URLMynlpResource.java

示例9: run

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Override
public void run() {
    super.run();
    try {
        listener.zipStart();
        long sumLength = 0;
        // 获取解压之后文件的大小,用来计算解压的进度
        long ziplength = getZipTrueSize(zipFileString);
        FileInputStream inputStream = new FileInputStream(zipFileString);
        ZipInputStream inZip = new ZipInputStream(inputStream);
        ZipEntry zipEntry;
        String szName = "";
        while ((zipEntry = inZip.getNextEntry()) != null) {
            szName = zipEntry.getName();
            if (zipEntry.isDirectory()) {
                szName = szName.substring(0, szName.length() - 1);
                File folder = new File(outPathString + File.separator + szName);
                folder.mkdirs();
            } else {
                File file = new File(outPathString + File.separator + szName);
                file.createNewFile();
                FileOutputStream out = new FileOutputStream(file);
                int len;
                byte[] buffer = new byte[1024];
                while ((len = inZip.read(buffer)) != -1) {
                    sumLength += len;
                    int progress = (int) ((sumLength * 100) / ziplength);
                    updateProgress(progress, listener);
                    out.write(buffer, 0, len);
                    out.flush();
                }
                out.close();
            }
        }
        listener.zipSuccess();
        inZip.close();
    } catch (Exception e) {
        listener.zipFail();
    }
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:41,代码来源:UnZipMainThread.java

示例10: unzipData

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private String unzipData(InputStream is, String extension,
        File writeDirectory) throws IOException {

    String baseFileName = UUID.randomUUID().toString();

    ZipInputStream zipInputStream = new ZipInputStream(is);
    ZipEntry entry;

    String returnFile = null;

    while ((entry = zipInputStream.getNextEntry()) != null) {

        String currentExtension = entry.getName();
        int beginIndex = currentExtension.lastIndexOf(".") + 1;
        currentExtension = currentExtension.substring(beginIndex);

        String fileName = baseFileName + "." + currentExtension;
        File currentFile = new File(writeDirectory, fileName);
        if (!writeDirectory.exists()) {
            writeDirectory.mkdir();
        }
        currentFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(currentFile);

        org.apache.commons.io.IOUtils.copy(zipInputStream, fos);

        if (currentExtension.equalsIgnoreCase(extension)) {
            returnFile = currentFile.getAbsolutePath();
        }

        fos.close();
    }
    zipInputStream.close();
    return returnFile;
}
 
开发者ID:52North,项目名称:javaps-geotools-backend,代码行数:36,代码来源:GenericFileDataWithGT.java

示例11: process

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public void process(File file) throws Exception {
	final ZipInputStream zip = new ZipInputStream( new FileInputStream( file ) );

	try {
		ZipEntry entry;
		while ( (entry = zip.getNextEntry()) != null ) {
			final byte[] bytes = ByteCodeHelper.readByteCode( zip );
			entryHandler.handleEntry( entry, bytes );
			zip.closeEntry();
		}
	}
	finally {
		zip.close();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:AbstractInstrumenter.java

示例12: extractBinFilesFromJar

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void extractBinFilesFromJar(File outFolder, File jarFile) throws IOException {
    File jarOutFolder = getOutFolderForJarFile(outFolder, jarFile);
    FileUtils.deleteQuietly(jarOutFolder);
    FileUtils.forceMkdir(jarOutFolder);

    try (Closer localCloser = Closer.create()) {
        FileInputStream fis = localCloser.register(new FileInputStream(jarFile));
        ZipInputStream zis = localCloser.register(new ZipInputStream(fis));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                continue;
            }

            String name = entry.getName();

            if (!isResource(name)) {
                continue;
            }
            // get rid of the path. We don't need it since the file name includes the domain
            name = new File(name).getName();
            File out = new File(jarOutFolder, name);
            //noinspection ResultOfMethodCallIgnored
            FileOutputStream fos = localCloser.register(new FileOutputStream(out));
            ByteStreams.copy(zis, fos);
            zis.closeEntry();
        }
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:30,代码来源:AwbDataBindingMergeArtifactsTask.java

示例13: read

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Override
public long read(InputStream in, String filename, long fileSize) throws DeserializeException {
	mode = Mode.HEADER;
	if (filename != null && (filename.toUpperCase().endsWith(".ZIP") || filename.toUpperCase().endsWith(".IFCZIP"))) {
		ZipInputStream zipInputStream = new ZipInputStream(in);
		try {
			ZipEntry nextEntry = zipInputStream.getNextEntry();
			if (nextEntry == null) {
				throw new DeserializeException("Zip files must contain exactly one IFC-file, this zip-file looks empty");
			}
			if (nextEntry.getName().toUpperCase().endsWith(".IFC")) {
				FakeClosingInputStream fakeClosingInputStream = new FakeClosingInputStream(zipInputStream);
				long size = read(fakeClosingInputStream, fileSize);
				if (size == 0) {
					throw new DeserializeException("Uploaded file does not seem to be a correct IFC file");
				}
				if (zipInputStream.getNextEntry() != null) {
					zipInputStream.close();
					throw new DeserializeException("Zip files may only contain one IFC-file, this zip-file contains more files");
				} else {
					zipInputStream.close();
				}
				return size;
			} else {
				throw new DeserializeException("Zip files must contain exactly one IFC-file, this zip-file seems to have one or more non-IFC files");
			}
		} catch (IOException e) {
			throw new DeserializeException(e);
		}
	} else {
		return read(in, fileSize);
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:34,代码来源:IfcStepStreamingDeserializer.java

示例14: 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

示例15: upZipFile

import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void upZipFile(Context context,String assetPath,String outputFolderPath){
    File desDir = new File(outputFolderPath);
    if (!desDir.isDirectory()) {
        desDir.mkdirs();
    }
    try {
        InputStream inputStream = context.getResources().getAssets().open(assetPath);
        ZipInputStream zipInputStream=new ZipInputStream(inputStream);
        ZipEntry zipEntry;
        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
            Log.d(TAG, "upZipFile: "+zipEntry.getName());
            if(zipEntry.isDirectory()) {
                File tmpFile=new File(outputFolderPath,zipEntry.getName());
                //Log.d(TAG, "upZipFile: folder "+tmpFile.getAbsolutePath());
                if(!tmpFile.isDirectory())
                    tmpFile.mkdirs();
            } else {
                File desFile = new File(outputFolderPath +"/"+ zipEntry.getName());
                if(desFile.exists()) continue;
                OutputStream out = new FileOutputStream(desFile);
                //Log.d(TAG, "upZipFile: "+desFile.getAbsolutePath());
                byte buffer[] = new byte[1024];
                int realLength;
                while ((realLength = zipInputStream.read(buffer)) > 0) {
                    out.write(buffer, 0, realLength);
                }
                zipInputStream.closeEntry();
                out.close();
            }
        }
        zipInputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:36,代码来源:FileUtils.java


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