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


Java ZipInputStream类代码示例

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


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

示例1: getContent

import java.util.zip.ZipInputStream; //导入依赖的package包/类
private static String getContent(InputStream input, final String zipEntryName) {

		try (ZipInputStream zipin = new ZipInputStream(input)) {
			ZipEntry ze;
			while ((ze = zipin.getNextEntry()) != null) {
				String zeName = ze.getName();
				if (zipEntryName.equals(zeName)) {
					ByteArrayOutputStream baos = new ByteArrayOutputStream();
					int b = zipin.read();
					while (b >= 0) {
						baos.write(b);
						b = zipin.read();
					}
					zipin.close();
					return new String(baos.toByteArray());
				}
			}
			zipin.close();
			return null;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
 
开发者ID:dvbern,项目名称:doctemplate,代码行数:24,代码来源:DOCXMergeEngineTest.java

示例2: parse

import java.util.zip.ZipInputStream; //导入依赖的package包/类
@Override
public Element parse(InputStream in) {
	ZipInputStream zin = new ZipInputStream(in);
	ZipEntryPeer root;
	Map<String, Element> map = new HashMap<String, Element>();
	ZipEntry entry = null;
	entry = getNextEntrySilently(zin);
	while (entry != null) {
		Plugin<?> plugin = rechecker.getInputTypeMatcher().getPlugin(entry);
		if (!(plugin instanceof FilePlugin)) {
			Element child = plugin.parse(new ZippedFileInputStream(zin));
		} else {
			ZipEntryPeer next = new ZipEntryPeer(entry);
		}
		entry = getNextEntrySilently(zin);
	}
	// TODO implement
	// read all zip entries
	// map them such that we know the children
	return null;
}
 
开发者ID:retest,项目名称:recheck,代码行数:22,代码来源:ZipPlugin.java

示例3: ZipModInputStream

import java.util.zip.ZipInputStream; //导入依赖的package包/类
public ZipModInputStream(FileHandle file) {
  try {
    inputStream = new FileInputStream(file.file());
    zipInputStream = new ZipInputStream(inputStream);
    fileStream = new FilterInputStream(zipInputStream) {
      @Override
      public void close() throws IOException {
        // no close
      }
    };
  } catch (Exception e) {
    try {
      close();
    } catch (IOException ignored) {
    }
    throw new CubesException("Failed to create zip mod input stream", e);
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:19,代码来源:ModInputStream.java

示例4: expandZippedApplication

import java.util.zip.ZipInputStream; //导入依赖的package包/类
private void expandZippedApplication(InputStream stream, ApplicationDescription desc)
        throws IOException {
    ZipInputStream zis = new ZipInputStream(stream);
    ZipEntry entry;
    File appDir = new File(appsDir, desc.name());
    while ((entry = zis.getNextEntry()) != null) {
        if (!entry.isDirectory()) {
            byte[] data = ByteStreams.toByteArray(zis);
            zis.closeEntry();
            File file = new File(appDir, entry.getName());
            createParentDirs(file);
            write(data, file);
        }
    }
    zis.close();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:ApplicationArchive.java

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

示例6: determineTypesInZipFile

import java.util.zip.ZipInputStream; //导入依赖的package包/类
private void determineTypesInZipFile(ZipFullEntry entry) {
    InputStream in = entry.getInputStream();
    if (in == null) {
            Logger.getLogger(PackageContents.class.getName()).log(Level.SEVERE, "No file contents provided for {0}", entry.getName());
    } else {
        try (ZipInputStream bundle = new ZipInputStream(in)) {
            ZipEntry jarEntry;
            while ((jarEntry = bundle.getNextEntry()) != null) {
                ZipFullEntry jarFullEntry = new ZipFullEntry(bundle, jarEntry, entry.getName().endsWith(".jar"));
                observeFileEntry(jarFullEntry);
                subfiles.put(entry.getName() + "!" + jarFullEntry.getName(), new FileContents(jarFullEntry, this));
            }
        } catch (IOException ex) {
            Logger.getLogger(PackageContents.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:aem-epic-tool,代码行数:18,代码来源:PackageContents.java

示例7: getZipEntries

import java.util.zip.ZipInputStream; //导入依赖的package包/类
/**
 * 获取jar文件的entry列表
 *
 * @param jarFile
 * @return
 */
public static List<String> getZipEntries(File jarFile) throws IOException {
    List<String> entries = new ArrayList<String>();
    FileInputStream fis = new FileInputStream(jarFile);
    ZipInputStream zis = new ZipInputStream(fis);
    try {
        // loop on the entries of the jar file package and put them in the final jar
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            // do not take directories or anything inside a potential META-INF folder.
            if (entry.isDirectory()) {
                continue;
            }
            String name = entry.getName();
            entries.add(name);
        }
    } finally {
        zis.close();
    }
    return entries;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:27,代码来源:JarSplitUtils.java

示例8: create

import java.util.zip.ZipInputStream; //导入依赖的package包/类
@Override
public Csar create(String identifier, InputStream inputStream) {
    csarMap.remove(identifier);
    File csarDir = setupDir(identifier);
    File contentDir = new File(csarDir, CONTENT_DIR);
    File transformationDir = new File(csarDir, TRANSFORMATION_DIR);
    transformationDir.mkdir();
    try {
        ZipUtility.unzip(new ZipInputStream(inputStream), contentDir.getPath());
        logger.info("Extracted csar '{}' into '{}'", identifier, contentDir.getPath());
    } catch (IOException e) {
        logger.error("Failed to unzip csar with identifier '{}'", identifier, e);
    }
    Csar csar = new CsarImpl(identifier, getLog(identifier));
    csarMap.put(identifier, csar);
    return csar;
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:18,代码来源:CsarFilesystemDao.java

示例9: unzip

import java.util.zip.ZipInputStream; //导入依赖的package包/类
public static void unzip(final InputStream zipfile, final File directory) throws IOException {
  final ZipInputStream zfile = new ZipInputStream(zipfile);
  ZipEntry entry;
  while ((entry = zfile.getNextEntry()) != null) {
    final File file = new File(directory, entry.getName());
    if (entry.isDirectory()) {
      file.mkdirs();
    } else {
      file.getParentFile().mkdirs();
      try {
        StreamUtilities.copy(zfile, file);
      } catch (IOException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
      }
    }
  }

  zfile.close();
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:20,代码来源:CompressionUtilities.java

示例10: shouldCreateHashForFile

import java.util.zip.ZipInputStream; //导入依赖的package包/类
@Test
public void shouldCreateHashForFile() {
  //given
  PowerMockito.mockStatic(IoUtil.class);
  PowerMockito.mockStatic(DigestUtils.class);
  byte[] bytes = new byte[]{1,2,3};
  final String fileEntry = "fileEntry";
  final ZipInputStream zipInputStream = mock(ZipInputStream.class);
  when(IoUtil.readInputStream(zipInputStream, fileEntry)).thenReturn(bytes);
  final String hash = "hash";
  when(DigestUtils.md5DigestAsHex(bytes)).thenReturn(hash);

  //when
  final String result = zipResourceService.createHashForFile(zipInputStream, fileEntry);

  //then
  assertThat(result, equalTo(hash));
}
 
开发者ID:satspeedy,项目名称:camunda-migrator,代码行数:19,代码来源:ZipResourceServiceHashTest.java

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

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

示例13: unpack

import java.util.zip.ZipInputStream; //导入依赖的package包/类
private void unpack (String filename) throws IOException {
    File zipLarge = new File(getDataDir(), filename);
    ZipInputStream is = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipLarge)));
    ZipEntry entry;
    while ((entry = is.getNextEntry()) != null) {
        File unpacked = new File(workDir, entry.getName());
        FileChannel channel = new FileOutputStream(unpacked).getChannel();
        byte[] bytes = new byte[2048];
        try {
            int len;
            long size = entry.getSize();
            while (size > 0 && (len = is.read(bytes, 0, 2048)) > 0) {
                ByteBuffer buffer = ByteBuffer.wrap(bytes, 0, len);
                int j = channel.write(buffer);
                size -= len;
            }
        } finally {
            channel.close();
        }
    }
    ZipEntry e = is.getNextEntry();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CheckoutTest.java

示例14: getProjectName

import java.util.zip.ZipInputStream; //导入依赖的package包/类
/*** Added by julienda - 08/09/2012
 * Return the project name by reading the first directory into the archive (.car)
 * @param path: the archive path
 * @return filename: the project name
 * @throws IOException */
   public static String getProjectName(String path) throws IOException {
	Engine.logEngine.trace("PATH: "+path);
	
	ZipInputStream zis = new ZipInputStream(new FileInputStream(path));
    ZipEntry ze = null;	  
    String fileName = null;
    try {
        if((ze = zis.getNextEntry()) != null){
        	fileName = ze.getName().replaceAll("/.*","");
        	Engine.logEngine.trace("ZipUtils.getProjectName() - fileName: "+fileName);
        }
    }
    finally {
        zis.close();
    }
	return fileName;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:23,代码来源:ZipUtils.java

示例15: zip_single_file

import java.util.zip.ZipInputStream; //导入依赖的package包/类
@Test
public void zip_single_file() throws Exception {
    file.mkdirs();

    final File target = new File(file, "target.zip");
    final File f1 = new File(file, "f1.txt");
    FileUtil.write(TEST_TEXT, f1);
    FileUtil.zip(Collections.singletonList(f1), target);

    try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(target))) {
        final ZipEntry entry = zipInputStream.getNextEntry();
        Assert.assertEquals("f1.txt", entry.getName());

        final Scanner scanner = new Scanner(zipInputStream);
        final String line = scanner.nextLine();
        Assert.assertEquals(TEST_TEXT, line);
    }

}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:20,代码来源:FileUtilTest.java


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