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 presto by prestodb.
the class OrcInputStream method decompressZip.
// This comes from the Apache Hive ORC code
private int decompressZip(Slice in) throws IOException {
Inflater inflater = new Inflater(true);
try {
inflater.setInput((byte[]) in.getBase(), (int) (in.getAddress() - ARRAY_BYTE_BASE_OFFSET), in.length());
allocateOrGrowBuffer(in.length() * EXPECTED_COMPRESSION_RATIO, false);
int uncompressedLength = 0;
while (true) {
uncompressedLength += inflater.inflate(buffer, uncompressedLength, buffer.length - uncompressedLength);
if (inflater.finished() || buffer.length >= maxBufferSize) {
break;
}
int oldBufferSize = buffer.length;
allocateOrGrowBuffer(buffer.length * 2, true);
if (buffer.length <= oldBufferSize) {
throw new IllegalStateException(String.format("Buffer failed to grow. Old size %d, current size %d", oldBufferSize, buffer.length));
}
}
if (!inflater.finished()) {
throw new OrcCorruptionException("Could not decompress all input (output buffer too small?)");
}
return uncompressedLength;
} catch (DataFormatException e) {
throw new OrcCorruptionException(e, "Invalid compressed stream");
} finally {
inflater.end();
}
}
use of java.util.zip.DataFormatException in project robovm by robovm.
the class OldDataFormatExceptionTest method testDataFormatExceptionString.
public void testDataFormatExceptionString() {
DataFormatException dfe = new DataFormatException("Test");
assertEquals(dfe.getMessage(), "Test");
}
use of java.util.zip.DataFormatException in project robovm by robovm.
the class OldDataFormatExceptionTest method testDataFormatException.
public void testDataFormatException() {
DataFormatException dfe = new DataFormatException();
assertEquals(dfe.getMessage(), null);
}
Aggregations