use of java.util.zip.ZipInputStream in project robovm by robovm.
the class ZipInputStreamTest method unzip.
public static byte[] unzip(String name, byte[] bytes) throws IOException {
ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(bytes));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipEntry entry = in.getNextEntry();
assertEquals(name, entry.getName());
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
// There's only one entry in the Zip files we create.
assertNull(in.getNextEntry());
in.close();
return out.toByteArray();
}
use of java.util.zip.ZipInputStream in project robovm by robovm.
the class ZipFileTest method testInflatingStreamsRequiringZipRefill.
public void testInflatingStreamsRequiringZipRefill() throws IOException {
int originalSize = 1024 * 1024;
byte[] readBuffer = new byte[8192];
ZipInputStream in = new ZipInputStream(new FileInputStream(createZipFile(1, originalSize)));
while (in.getNextEntry() != null) {
while (in.read(readBuffer, 0, readBuffer.length) != -1) {
}
}
in.close();
}
use of java.util.zip.ZipInputStream in project jadx by skylot.
the class ClsSet method load.
public void load(File input) throws IOException, DecodeException {
String name = input.getName();
InputStream inputStream = new FileInputStream(input);
try {
if (name.endsWith(CLST_EXTENSION)) {
load(inputStream);
} else if (name.endsWith(".jar")) {
ZipInputStream in = new ZipInputStream(inputStream);
try {
ZipEntry entry = in.getNextEntry();
while (entry != null) {
if (entry.getName().endsWith(CLST_EXTENSION)) {
load(in);
}
entry = in.getNextEntry();
}
} finally {
close(in);
}
} else {
throw new JadxRuntimeException("Unknown file format: " + name);
}
} finally {
close(inputStream);
}
}
use of java.util.zip.ZipInputStream in project platform_frameworks_base by android.
the class BugreportReceiverTest method assertZipContent.
private void assertZipContent(Uri uri, String entryName, String expectedContent) throws IOException, IOException {
Log.v(TAG, "assertZipEntry(uri=" + uri + ", entryName=" + entryName);
try (ZipInputStream zis = new ZipInputStream(mContext.getContentResolver().openInputStream(uri))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
Log.v(TAG, "Zip entry: " + entry.getName());
if (entry.getName().equals(entryName)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Streams.copy(zis, bos);
String actualContent = new String(bos.toByteArray(), "UTF-8");
bos.close();
assertEquals("wrong content for zip entry'" + entryName + "' on '" + uri + "'", expectedContent, actualContent);
return;
}
}
}
fail("Did not find entry '" + entryName + "' on file '" + uri + "'");
}
use of java.util.zip.ZipInputStream in project camel by apache.
the class ZipAggregationStrategyEmptyFileTest method testEmptyFile.
@Test
public void testEmptyFile() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:aggregateToZipEntry");
mock.expectedMessageCount(1);
template.sendBody("file:target/foo", "Hello");
// empty file which is not aggregated
template.sendBody("file:target/foo", "");
template.sendBody("file:target/foo", "Bye");
template.sendBody("file:target/foo", "Howdy");
assertMockEndpointsSatisfied();
Thread.sleep(500);
File[] files = new File("target/out").listFiles();
assertTrue(files != null);
assertTrue("Should be a file in target/out directory", files.length > 0);
File resultFile = files[0];
ZipInputStream zin = new ZipInputStream(new FileInputStream(resultFile));
try {
int fileCount = 0;
for (ZipEntry ze = zin.getNextEntry(); ze != null; ze = zin.getNextEntry()) {
fileCount = fileCount + 1;
}
assertEquals("Zip file should contains " + ZipAggregationStrategyEmptyFileTest.EXPECTED_NO_FILES + " files", ZipAggregationStrategyEmptyFileTest.EXPECTED_NO_FILES, fileCount);
} finally {
IOHelper.close(zin);
}
}
Aggregations