use of java.util.zip.ZipInputStream in project Fairphone by Kwamecorp.
the class RSAUtils method unzip.
private static void unzip(String filePath, String targetPath) {
new File(targetPath).mkdirs();
try {
FileInputStream fin = new FileInputStream(filePath);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.d(TAG, "Unzipping " + ze.getName());
if (ze.isDirectory()) {
_dirChecker(ze.getName(), targetPath);
} else {
FileOutputStream fout = new FileOutputStream(targetPath + ze.getName());
byte[] buffer = new byte[2048];
int count = 0;
while ((count = zin.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
fin.close();
} catch (Exception e) {
Log.e("Decompress", "unzip", e);
}
}
use of java.util.zip.ZipInputStream in project MinecraftForge by MinecraftForge.
the class AccessTransformer method processJar.
private static void processJar(File inFile, File outFile, AccessTransformer[] transformers) throws IOException {
ZipInputStream inJar = null;
ZipOutputStream outJar = null;
try {
try {
inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open input file: " + e.getMessage());
}
try {
outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open output file: " + e.getMessage());
}
ZipEntry entry;
while ((entry = inJar.getNextEntry()) != null) {
if (entry.isDirectory()) {
outJar.putNextEntry(entry);
continue;
}
byte[] data = new byte[4096];
ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
int len;
do {
len = inJar.read(data);
if (len > 0) {
entryBuffer.write(data, 0, len);
}
} while (len != -1);
byte[] entryData = entryBuffer.toByteArray();
String entryName = entry.getName();
if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
ClassNode cls = new ClassNode();
ClassReader rdr = new ClassReader(entryData);
rdr.accept(cls, 0);
String name = cls.name.replace('/', '.').replace('\\', '.');
for (AccessTransformer trans : transformers) {
entryData = trans.transform(name, name, entryData);
}
}
ZipEntry newEntry = new ZipEntry(entryName);
outJar.putNextEntry(newEntry);
outJar.write(entryData);
}
} finally {
IOUtils.closeQuietly(outJar);
IOUtils.closeQuietly(inJar);
}
}
use of java.util.zip.ZipInputStream in project MinecraftForge by MinecraftForge.
the class MarkerTransformer method processJar.
private static void processJar(File inFile, File outFile, MarkerTransformer[] transformers) throws IOException {
ZipInputStream inJar = null;
ZipOutputStream outJar = null;
try {
try {
inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open input file: " + e.getMessage());
}
try {
outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open output file: " + e.getMessage());
}
ZipEntry entry;
while ((entry = inJar.getNextEntry()) != null) {
if (entry.isDirectory()) {
outJar.putNextEntry(entry);
continue;
}
byte[] data = new byte[4096];
ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
int len;
do {
len = inJar.read(data);
if (len > 0) {
entryBuffer.write(data, 0, len);
}
} while (len != -1);
byte[] entryData = entryBuffer.toByteArray();
String entryName = entry.getName();
if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
ClassNode cls = new ClassNode();
ClassReader rdr = new ClassReader(entryData);
rdr.accept(cls, 0);
String name = cls.name.replace('/', '.').replace('\\', '.');
for (MarkerTransformer trans : transformers) {
entryData = trans.transform(name, name, entryData);
}
}
ZipEntry newEntry = new ZipEntry(entryName);
outJar.putNextEntry(newEntry);
outJar.write(entryData);
}
} finally {
IOUtils.closeQuietly(outJar);
IOUtils.closeQuietly(inJar);
}
}
use of java.util.zip.ZipInputStream in project OpenGrok by OpenGrok.
the class JarAnalyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
try (ZipInputStream zis = new ZipInputStream(src.getStream())) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String ename = entry.getName();
if (xrefOut != null) {
xrefOut.append("<br/><b>");
Util.htmlize(ename, xrefOut);
xrefOut.append("</b>");
}
doc.add(new TextField("full", ename, Store.NO));
FileAnalyzerFactory fac = AnalyzerGuru.find(ename);
if (fac instanceof JavaClassAnalyzerFactory) {
if (xrefOut != null) {
xrefOut.append("<br/>");
}
JavaClassAnalyzer jca = (JavaClassAnalyzer) fac.getAnalyzer();
jca.analyze(doc, new BufferedInputStream(zis), xrefOut);
}
}
}
}
use of java.util.zip.ZipInputStream in project OpenGrok by OpenGrok.
the class SCCSgetTest method getRevision.
/**
* Test of getRevision method, of class SCCSget.
*/
@Test
public void getRevision() throws Exception {
if (!haveSccs) {
System.out.println("sccs not available. Skipping test");
return;
}
ZipInputStream zstream = new ZipInputStream(getClass().getResourceAsStream("sccs-revisions.zip"));
ZipEntry entry;
while ((entry = zstream.getNextEntry()) != null) {
String expected = readInput(zstream);
InputStream sccs = SCCSget.getRevision("sccs", sccsfile, entry.getName());
String got = readInput(sccs);
sccs.close();
zstream.closeEntry();
assertEquals(expected, got);
}
zstream.close();
}
Aggregations