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 proxyee-down by monkeyWie.
the class FileUtil method unzip.
public static void unzip(String zipPath, String toPath, String... unzipFile) throws IOException {
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipPath))) {
toPath = toPath == null ? new File(zipPath).getParent() : toPath;
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
final String entryName = entry.getName();
if (entry.isDirectory() || (unzipFile != null && unzipFile.length > 0 && Arrays.stream(unzipFile).noneMatch((file) -> entryName.equalsIgnoreCase(file)))) {
zipInputStream.closeEntry();
continue;
}
File file = createFileSmart(toPath + File.separator + entryName);
try (FileOutputStream outputStream = new FileOutputStream(file)) {
byte[] bts = new byte[8192];
int len;
while ((len = zipInputStream.read(bts)) != -1) {
outputStream.write(bts, 0, len);
}
}
}
}
}
use of java.util.zip.ZipInputStream in project gocd by gocd.
the class CommandRepositoryInitializerIntegrationTest method shouldNotDeleteCustomCommandRepositoryWhenUpdatingDefaultCommandRepository.
@Test
public void shouldNotDeleteCustomCommandRepositoryWhenUpdatingDefaultCommandRepository() throws Exception {
File versionFile = TestFileUtil.writeStringToTempFileInFolder("default", "version.txt", "10.1=10");
File randomFile = TestFileUtil.createTestFile(versionFile.getParentFile(), "random");
File defaultCommandRepoDir = versionFile.getParentFile();
File customCommandRepoDir = TestFileUtil.createTestFolder(new File(defaultCommandRepoDir.getParent()), "customDir");
File userFile = TestFileUtil.createTestFile(customCommandRepoDir, "userFile");
initializer.usePackagedCommandRepository(new ZipInputStream(new FileInputStream(getZippedCommandRepo("12.4=12"))), defaultCommandRepoDir);
assertThat(defaultCommandRepoDir.exists(), is(true));
assertThat(FileUtils.readFileToString(new File(defaultCommandRepoDir, "version.txt"), UTF_8), is("12.4=12"));
assertThat(new File(defaultCommandRepoDir, "snippet.xml").exists(), is(true));
assertThat(new File(defaultCommandRepoDir, randomFile.getName()).exists(), is(false));
assertThat(customCommandRepoDir.exists(), is(true));
assertThat(new File(customCommandRepoDir, userFile.getName()).exists(), is(true));
}
use of java.util.zip.ZipInputStream in project gocd by gocd.
the class CommandRepositoryInitializerIntegrationTest method shouldReplaceWithPackagedCommandRepositoryWhenOlderRepoExists.
@Test
public void shouldReplaceWithPackagedCommandRepositoryWhenOlderRepoExists() throws Exception {
File versionFile = TestFileUtil.writeStringToTempFileInFolder("default", "version.txt", "10.1=10");
File randomFile = TestFileUtil.createTestFile(versionFile.getParentFile(), "random");
File defaultCommandRepoDir = versionFile.getParentFile();
initializer.usePackagedCommandRepository(new ZipInputStream(new FileInputStream(getZippedCommandRepo("12.4=12"))), defaultCommandRepoDir);
assertThat(defaultCommandRepoDir.exists(), is(true));
assertThat(FileUtils.readFileToString(new File(defaultCommandRepoDir, "version.txt"), UTF_8), is("12.4=12"));
assertThat(new File(defaultCommandRepoDir, "snippet.xml").exists(), is(true));
assertThat(new File(defaultCommandRepoDir, randomFile.getName()).exists(), is(false));
}
Aggregations