import java.io.FileInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("c:/inas400.zip"); // this is where you start, with an InputStream containing the bytes from the zip file ZipInputStream zis = new ZipInputStream(fis); ZipEntry entry; // while there are entries I process them while ((entry = zis.getNextEntry()) != null) { System.out.println("entry: " + entry.getName() + ", " + entry.getSize()); // consume all the data from this entry while (zis.available() > 0) zis.read(); // I could close the entry, but getNextEntry does it automatically // zis.closeEntry() } } }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { ZIPCompressedMessage result = new ZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(byteArray)); in.getNextEntry(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } in.closeEntry(); out.flush(); in.close(); result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
@Override public int available() throws IOException { return source.available(); }
@Override public int available() throws IOException { return zis.available(); }
@Override public int available() throws IOException { return zipped.available(); }
@Override public int available() throws IOException { return zipped.available(); }
public int available() throws IOException { return _stream.available(); }
@Override public int available() throws IOException { return source.available(); }
public int available() throws IOException { return _stream.available(); }
public int available() throws IOException { return _stream.available(); }
public int available() throws IOException { return _stream.available(); }
public static List<String> getEntryNames(InputStream stream) throws IOException { List<String> result = new ArrayList<>(); try (ZipInputStream zip = new ZipInputStream(stream)) { while (zip.available() == 1) { ZipEntry entry = zip.getNextEntry(); if (entry != null) { result.add(entry.getName()); } } } return result; }
/** * @param zipInputStream zipInputStream * @return return zipetry map * @throws IOException IOException */ private static List<ZipEntry> populateList(ZipInputStream zipInputStream) throws IOException { List<ZipEntry> listEntry = new ArrayList<ZipEntry>(); while (zipInputStream.available() == 1) { ZipEntry entry = zipInputStream.getNextEntry(); if (entry == null) { break; } listEntry.add(entry); } return listEntry; }
ZipInputStream zip = null; try { zip = new ZipInputStream(url.openStream()); ZipEntry entry; do{ entry = zip.getNextEntry(); } while(!yourExpectedFileName.equals(entry.getName()) while(zip.available()){ //read your data } zip.closeEntry(); } finally { if (zip != null) zip.close(); }
private void writeZipIntoFile(ZipInputStream zipInputStream, File file) throws IOException { BufferedWriter configOutput = null; try { int read; configOutput = new BufferedWriter(new FileWriter(file)); while (zipInputStream.available() > 0) { if ((read = zipInputStream.read()) != -1) { configOutput.write(read); } } } finally { if (configOutput != null) { configOutput.close(); } } }
/** Search Archive for classes. * @param the archive file location * @return array of class names found * @throws IOException */ static String [] searchArchiveForClasses( URL url ) throws IOException { List<String> list = new ArrayList<>(); ZipInputStream zip = new ZipInputStream(url.openStream()); ZipEntry ze; while( zip.available() == 1 ) if ( (ze = zip.getNextEntry()) != null && isClassFileName( ze.getName() ) ) list.add( canonicalizeClassName( ze.getName() ) ); zip.close(); return list.toArray( new String[list.size()] ); }
/** * Returns the input stream for the zip entry, or the original input stream, as appropriate. */ private InputStream getUnderlyingInputStream(InputStream inputStream, Map<?, ?> options) throws IOException { if (useZip() || (options != null && Boolean.TRUE.equals(options.get(Resource.OPTION_ZIP)))) { ZipInputStream zipInputStream = new ZipInputStream(inputStream); while (zipInputStream.available() != 0) { ZipEntry zipEntry = zipInputStream.getNextEntry(); if (isContentZipEntry(zipEntry)) { return zipInputStream; } } } return inputStream; }
/** * Returns the input stream for the zip entry, or the original input stream, as appropriate. */ private InputStream getUnderlyingInputStream(InputStream inputStream, Map<?, ?> options) throws IOException { if (useZip() || (options != null && Boolean.TRUE.equals(options.get(Resource.OPTION_ZIP)))) { ZipInputStream zipInputStream = new ZipInputStream(inputStream); while (zipInputStream.available() != 0) { ZipEntry zipEntry = zipInputStream.getNextEntry(); if (isContentZipEntry(zipEntry)) { return zipInputStream; } } } return inputStream; }
public static void loadAndAnalyzeZip(String filename) throws Exception { InputStream is = new FileInputStream (filename); ZipInputStream zis = new ZipInputStream(is); AutomataAnalyzerData.printHeader(); ZipEntry ze = zis.getNextEntry(); while(zis.available()!= 0) { if(!ze.isDirectory() ) { Automata a = AutomataIO.loadXML(zis); if(a != null) { AutomataAnalyzerData dat = analyze(a, ze.getName() ); dat.print(); } } zis.closeEntry(); ze = zis.getNextEntry(); } zis.close(); is.close(); }
private void importMindmanagerFile(final File file) { ZipInputStream in = null; try { in = new ZipInputStream(new FileInputStream(file)); while (in.available() != 0) { final ZipEntry entry = in.getNextEntry(); if (entry == null) { break; } if (!entry.getName().equals("Document.xml")) { continue; } final String xsltFileName = "/xslt/mindmanager2mm.xsl"; final File outputFile = new File (file.getParent(), file.getName() + org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION); new XmlImporter(xsltFileName).importXml(in, outputFile); break; } } catch (final Exception e) { LogUtils.severe(e); } finally { FileUtils.silentlyClose(in); } }