use of java.util.zip.DataFormatException in project intellij-community by JetBrains.
the class BinaryEncoder method decode.
public static void decode(@NotNull ListIterator<String> input, long size, @NotNull ByteArrayOutputStream output) throws BinaryPatchException {
Inflater inflater = new Inflater();
byte[] inflated = new byte[1024];
try {
String line = input.next();
while (line != null && line.length() > 0) {
int len = getLineSizeFromChar(line.charAt(0));
byte[] toInflate = Base85x.decode(line.substring(1));
inflater.setInput(toInflate, 0, len);
int resultLength;
while (!inflater.needsInput()) {
try {
resultLength = inflater.inflate(inflated);
} catch (DataFormatException e) {
throw new BinaryPatchException("Can't decode binary file patch: can't decompress data");
}
output.write(inflated, 0, resultLength);
}
if (!input.hasNext())
break;
line = input.next();
}
int count = output.size();
if (count != size) {
throw new BinaryPatchException(String.format("Length of decoded binary patch mismatches: expected %d, received %d", size, count));
}
} catch (Base85x.Base85FormatException e) {
throw new BinaryPatchException(e);
} finally {
inflater.end();
}
}
use of java.util.zip.DataFormatException in project WordPress-Android by wordpress-mobile.
the class Note method buildFromBase64EncodedData.
public static synchronized Note buildFromBase64EncodedData(String noteId, String base64FullNoteData) {
Note note = null;
if (base64FullNoteData == null)
return null;
byte[] b64DecodedPayload = Base64.decode(base64FullNoteData, Base64.DEFAULT);
// Decompress the payload
Inflater decompresser = new Inflater();
decompresser.setInput(b64DecodedPayload, 0, b64DecodedPayload.length);
//max length an Android PN payload can have
byte[] result = new byte[4096];
int resultLength = 0;
try {
resultLength = decompresser.inflate(result);
decompresser.end();
} catch (DataFormatException e) {
AppLog.e(AppLog.T.NOTIFS, "Can't decompress the PN Payload. It could be > 4K", e);
}
String out = null;
try {
out = new String(result, 0, resultLength, "UTF8");
} catch (UnsupportedEncodingException e) {
AppLog.e(AppLog.T.NOTIFS, "Notification data contains non UTF8 characters.", e);
}
if (out != null) {
try {
JSONObject jsonObject = new JSONObject(out);
if (jsonObject.has("notes")) {
JSONArray jsonArray = jsonObject.getJSONArray("notes");
if (jsonArray != null && jsonArray.length() == 1) {
jsonObject = jsonArray.getJSONObject(0);
}
}
note = new Note(noteId, jsonObject);
} catch (JSONException e) {
AppLog.e(AppLog.T.NOTIFS, "Can't parse the Note JSON received in the PN", e);
}
}
return note;
}
use of java.util.zip.DataFormatException 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.DataFormatException in project ceylon-compiler by ceylon.
the class ZipFileIndex method inflate.
private int inflate(byte[] src, byte[] dest) {
Inflater inflater = (inflaterRef == null ? null : inflaterRef.get());
// construct the inflater object or reuse an existing one
if (inflater == null)
inflaterRef = new SoftReference<Inflater>(inflater = new Inflater(true));
inflater.reset();
inflater.setInput(src);
try {
return inflater.inflate(dest);
} catch (DataFormatException ex) {
return -1;
}
}
use of java.util.zip.DataFormatException in project cassandra by apache.
the class DeflateCompressor method uncompressBuffer.
public void uncompressBuffer(ByteBuffer input, ByteBuffer output) throws IOException {
try {
Inflater inf = inflater.get();
inf.reset();
byte[] buffer = getThreadLocalScratchBuffer();
// Use half the buffer for input, half for output.
int chunkLen = buffer.length / 2;
while (input.remaining() > chunkLen) {
input.get(buffer, 0, chunkLen);
inf.setInput(buffer, 0, chunkLen);
while (!inf.needsInput()) {
int len = inf.inflate(buffer, chunkLen, chunkLen);
output.put(buffer, chunkLen, len);
}
}
int inputLength = input.remaining();
input.get(buffer, 0, inputLength);
inf.setInput(buffer, 0, inputLength);
while (!inf.needsInput()) {
int len = inf.inflate(buffer, chunkLen, chunkLen);
output.put(buffer, chunkLen, len);
}
} catch (DataFormatException e) {
throw new IOException(e);
}
}
Aggregations