當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。