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();
}
}
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;
}
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;
}
}
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();
}
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
}
}
Aggregations