Search in sources :

Example 36 with ZipInputStream

use of java.util.zip.ZipInputStream in project processing by processing.

the class AppBundlerTask method copyResources.

private void copyResources(File resourcesDirectory) throws IOException {
    // Unzip res.zip into resources directory
    InputStream inputStream = getClass().getResourceAsStream("res.zip");
    ZipInputStream zipInputStream = new ZipInputStream(inputStream);
    try {
        ZipEntry zipEntry = zipInputStream.getNextEntry();
        while (zipEntry != null) {
            File file = new File(resourcesDirectory, zipEntry.getName());
            if (zipEntry.isDirectory()) {
                file.mkdir();
            } else {
                OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE);
                try {
                    int b = zipInputStream.read();
                    while (b != -1) {
                        outputStream.write(b);
                        b = zipInputStream.read();
                    }
                    outputStream.flush();
                } finally {
                    outputStream.close();
                }
            }
            zipEntry = zipInputStream.getNextEntry();
        }
    } finally {
        zipInputStream.close();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 37 with ZipInputStream

use of java.util.zip.ZipInputStream in project processing by processing.

the class Table method odsFindContentXML.

/**
   * Returns the next comma (not inside a quote) in the specified array.
   * @param c array to search
   * @param index offset at which to start looking
   * @return index of the comma, or -1 if line ended inside an unclosed quote
   */
/*
  static protected int nextComma(char[] c, int index) {
    if (index == c.length) {  // we're already at the end
      return c.length;
    }
    boolean quoted = c[index] == '\"';
    if (quoted) {
      index++; // step over the quote
    }
    for (int i = index; i < c.length; i++) {
      if (c[i] == '\"') {
        // if this fella started with a quote
        if (quoted) {
          if (i == c.length-1) {
            //return -1;  // ran out of chars
            // closing quote for field; last field on the line
            return c.length;
          } else if (c[i+1] == '\"') {
            // an escaped quote inside a quoted field, step over it
            i++;
          } else if (c[i+1] == ',') {
            // that's our closing quote, get outta here
            return i+1;
          }

        } else {  // not a quoted line
          if (i == c.length-1) {
            // we're at the end of the line, can't have an unescaped quote
            //return -1;  // ran out of chars
            throw new RuntimeException("Unterminated quoted field at end of line");
          } else if (c[i+1] == '\"') {
            // step over this crummy quote escape
            ++i;
          } else {
            throw new RuntimeException("Unterminated quoted field mid-line");
          }
        }
      } else if (!quoted && c[i] == ',') {
        return i;
      }
      if (!quote && (c[i] == ',')) {
        // found a comma, return this location
        return i;
      } else if (c[i] == '\"') {
        // if it's a quote, then either the next char is another quote,
        // or if this is a quoted entry, it better be a comma
        quote = !quote;
      }
    }
    // if still inside a quote, indicate that another line should be read
    if (quote) {
      return -1;
    }
    // made it to the end of the array with no new comma
    return c.length;
  }
  */
/**
   * Read a .ods (OpenDoc spreadsheet) zip file from an InputStream, and
   * return the InputStream for content.xml contained inside.
   */
private InputStream odsFindContentXML(InputStream input) {
    ZipInputStream zis = new ZipInputStream(input);
    ZipEntry entry = null;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            if (entry.getName().equals("content.xml")) {
                return zis;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry)

Example 38 with ZipInputStream

use of java.util.zip.ZipInputStream in project javatari by ppeccin.

the class ROMLoader method getFirstROMFromZIP.

private static InputStream getFirstROMFromZIP(InputStream stream) throws IOException, ROMFormatUnsupportedException {
    ZipInputStream zipStream = new ZipInputStream(stream);
    while (true) {
        ZipEntry entry = zipStream.getNextEntry();
        if (entry == null)
            return null;
        String entryName = entry.getName().toUpperCase();
        for (int i = 0; i < VALID_LOAD_FILE_EXTENSIONS.length; i++) if (entryName.endsWith(VALID_LOAD_FILE_EXTENSIONS[i].toUpperCase()))
            return zipStream;
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry)

Example 39 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class OldZipInputStreamTest method setUp.

@Override
protected void setUp() throws IOException {
    InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
    if (is == null) {
        System.out.println("file hyts_ZipFile.zip can not be found");
    }
    zis = new ZipInputStream(is);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(bos);
    ZipEntry entry = new ZipEntry("myFile");
    zos.putNextEntry(entry);
    zos.write(dataBytes);
    zos.closeEntry();
    zos.close();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 40 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class OldZipInputStreamTest method test_closeEntry.

public void test_closeEntry() throws Exception {
    zis.getNextEntry();
    zis.closeEntry();
    zis.getNextEntry();
    zis.close();
    try {
        zis.closeEntry();
        fail("IOException expected");
    } catch (IOException ee) {
    // expected
    }
    File resources = Support_Resources.createTempFolder();
    Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
    FileInputStream fis = new FileInputStream(new File(resources, "Broken_manifest.jar"));
    ZipInputStream zis1 = new ZipInputStream(fis);
    try {
        for (int i = 0; i < 6; i++) {
            zis1.getNextEntry();
            zis1.closeEntry();
        }
        fail("ZipException expected");
    } catch (ZipException ee) {
    // expected
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)354 ZipEntry (java.util.zip.ZipEntry)259 FileInputStream (java.io.FileInputStream)120 File (java.io.File)115 IOException (java.io.IOException)103 ByteArrayInputStream (java.io.ByteArrayInputStream)63 FileOutputStream (java.io.FileOutputStream)63 ByteArrayOutputStream (java.io.ByteArrayOutputStream)62 Test (org.junit.Test)56 InputStream (java.io.InputStream)53 BufferedInputStream (java.io.BufferedInputStream)47 ZipOutputStream (java.util.zip.ZipOutputStream)31 FileNotFoundException (java.io.FileNotFoundException)21 Path (java.nio.file.Path)20 HashMap (java.util.HashMap)19 BufferedOutputStream (java.io.BufferedOutputStream)18 ArrayList (java.util.ArrayList)18 ZipFile (java.util.zip.ZipFile)18 OutputStream (java.io.OutputStream)17 GZIPInputStream (java.util.zip.GZIPInputStream)14