use of java.util.zip.ZipException in project intellij-plugins by JetBrains.
the class SwfTranscoder method readSource.
// in will be closed
protected void readSource(InputStream in, long inputLength) throws IOException {
final int uncompressedBodyLength;
final boolean compressed;
byte[] data;
try {
int n = in.read(partialHeader);
assert n == PARTIAL_HEADER_LENGTH;
uncompressedBodyLength = (partialHeader[4] & 0xFF | (partialHeader[5] & 0xFF) << 8 | (partialHeader[6] & 0xFF) << 16 | partialHeader[7] << 24) - PARTIAL_HEADER_LENGTH;
compressed = partialHeader[0] == 0x43;
data = FileUtil.loadBytes(in, compressed ? (int) inputLength - PARTIAL_HEADER_LENGTH : uncompressedBodyLength);
} finally {
in.close();
}
if (compressed) {
final Inflater inflater = INFLATER.get();
try {
inflater.setInput(data);
byte[] uncompressedData = new byte[uncompressedBodyLength];
try {
inflater.inflate(uncompressedData);
} catch (DataFormatException e) {
throw new ZipException(e.getMessage() != null ? e.getMessage() : "Invalid ZLIB data format");
}
data = uncompressedData;
} finally {
inflater.reset();
}
}
buffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
readFrameSizeFrameRateAndFrameCount(data[0]);
}
use of java.util.zip.ZipException in project bnd by bndtools.
the class bnd method getJar.
/**
* Central routine to get a JAR with error checking
*
* @param s
*/
Jar getJar(String s) {
File f = getFile(s);
if (f.isFile()) {
try {
return new Jar(f);
} catch (ZipException e) {
exception(e, "Not a jar/zip file: %s", f);
} catch (Exception e) {
exception(e, "Opening file: %s", f);
}
return null;
}
try {
URL url = new URL(s);
return new Jar(s, url.openStream());
} catch (Exception e) {
// Ignore
}
error("Not a file or proper url: %s", f);
return null;
}
use of java.util.zip.ZipException in project weex-example by KalicyZhou.
the class WXSoInstallMgrSdk method unZipSelectedFiles.
static boolean unZipSelectedFiles(String libName, int version, IWXUserTrackAdapter utAdapter) throws ZipException, IOException {
String sourcePath = "lib/armeabi/lib" + libName + ".so";
String zipPath = "";
Context context = mContext;
if (context == null) {
return false;
}
ApplicationInfo aInfo = context.getApplicationInfo();
if (null != aInfo) {
zipPath = aInfo.sourceDir;
}
ZipFile zf;
zf = new ZipFile(zipPath);
try {
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
if (entry.getName().startsWith(sourcePath)) {
InputStream in = null;
FileOutputStream os = null;
FileChannel channel = null;
int total = 0;
try {
//Make sure the old library is deleted.
removeSoIfExit(libName, version);
//Copy file
in = zf.getInputStream(entry);
os = context.openFileOutput("lib" + libName + "bk" + version + ".so", Context.MODE_PRIVATE);
channel = os.getChannel();
byte[] buffers = new byte[1024];
int realLength;
while ((realLength = in.read(buffers)) > 0) {
//os.write(buffers);
channel.write(ByteBuffer.wrap(buffers, 0, realLength));
total += realLength;
}
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (channel != null) {
try {
channel.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (os != null) {
try {
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (zf != null) {
zf.close();
zf = null;
}
}
if (total > 0) {
return _loadUnzipSo(libName, version, utAdapter);
} else {
return false;
}
}
}
} catch (java.io.IOException e) {
e.printStackTrace();
} finally {
if (zf != null) {
zf.close();
zf = null;
}
}
return false;
}
use of java.util.zip.ZipException in project bytecode-viewer by Konloch.
the class ProcyonDecompiler method doSaveJarDecompiled.
/**
* @author DeathMarine
*/
private void doSaveJarDecompiled(File inFile, File outFile) throws Exception {
try (JarFile jfile = new JarFile(inFile);
FileOutputStream dest = new FileOutputStream(outFile);
BufferedOutputStream buffDest = new BufferedOutputStream(dest);
ZipOutputStream out = new ZipOutputStream(buffDest)) {
byte[] data = new byte[1024];
DecompilerSettings settings = getDecompilerSettings();
MetadataSystem metadataSystem = new MetadataSystem(new JarTypeLoader(jfile));
DecompilationOptions decompilationOptions = new DecompilationOptions();
decompilationOptions.setSettings(settings);
decompilationOptions.setFullDecompilation(true);
Enumeration<JarEntry> ent = jfile.entries();
Set<JarEntry> history = new HashSet<JarEntry>();
while (ent.hasMoreElements()) {
JarEntry entry = ent.nextElement();
if (entry.getName().endsWith(".class")) {
JarEntry etn = new JarEntry(entry.getName().replace(".class", ".java"));
if (history.add(etn)) {
out.putNextEntry(etn);
try {
String internalName = StringUtilities.removeRight(entry.getName(), ".class");
TypeReference type = metadataSystem.lookupType(internalName);
TypeDefinition resolvedType = null;
if ((type == null) || ((resolvedType = type.resolve()) == null)) {
throw new Exception("Unable to resolve type.");
}
Writer writer = new OutputStreamWriter(out);
settings.getLanguage().decompileType(resolvedType, new PlainTextOutput(writer), decompilationOptions);
writer.flush();
} finally {
out.closeEntry();
}
}
} else {
try {
JarEntry etn = new JarEntry(entry.getName());
if (history.add(etn))
continue;
history.add(etn);
out.putNextEntry(etn);
try {
InputStream in = jfile.getInputStream(entry);
if (in != null) {
try {
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
out.write(data, 0, count);
}
} finally {
in.close();
}
}
} finally {
out.closeEntry();
}
} catch (ZipException ze) {
// it
if (!ze.getMessage().contains("duplicate")) {
throw ze;
}
}
}
}
}
}
use of java.util.zip.ZipException in project knime-core by knime.
the class Buffer method isZLIBSupportsLevelSwitchAP8083.
/**
* See {@link #ZLIB_SUPPORTS_LEVEL_SWITCH_AP8083} for details.
* @return hopefully mostly true but false in case we are on a broken zlib
*/
private static boolean isZLIBSupportsLevelSwitchAP8083() {
ByteArrayOutputStream byteArrayOut;
byte[] nullBytes = new byte[1024 * 1024];
try (ZipOutputStream zipOut = new ZipOutputStream(byteArrayOut = new ByteArrayOutputStream())) {
zipOut.setLevel(Deflater.BEST_SPEED);
zipOut.putNextEntry(new ZipEntry("deflated.bin"));
zipOut.write(nullBytes);
zipOut.closeEntry();
zipOut.putNextEntry(new ZipEntry("stored.bin"));
zipOut.setLevel(Deflater.BEST_COMPRESSION);
zipOut.write(nullBytes);
zipOut.closeEntry();
} catch (IOException e) {
LOGGER.error("Unexpected error creating test zipped output", e);
return false;
}
try (ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(byteArrayOut.toByteArray()))) {
for (int i = 0; i < 2; i++) {
zipIn.getNextEntry();
while (zipIn.read(nullBytes) >= 0) {
}
}
} catch (ZipException e) {
return false;
} catch (IOException e) {
LOGGER.error("Unexpected error creating test zipped output", e);
return false;
}
return true;
}
Aggregations