use of java.util.zip.Inflater in project undertow by undertow-io.
the class CompressionUtilsTest method setup.
@Before
public void setup() throws Exception {
compress = new Deflater(Deflater.BEST_SPEED, true);
decompress = new Inflater(true);
}
use of java.util.zip.Inflater 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.Inflater in project teaTime by ancfdy.
the class AppZLibMgr method decompressEx.
/**
* 解压缩
*
* @param data
* 待压缩的数据
* @return byte[] 解压缩后的数据
*/
public static byte[] decompressEx(byte[] data, int offset, int len) {
byte[] output = new byte[0];
Inflater decompresser = new Inflater();
decompresser.reset();
decompresser.setInput(data, offset, len);
ByteArrayOutputStream o = new ByteArrayOutputStream(data.length);
try {
byte[] buf = new byte[1024];
while (!decompresser.finished()) {
int i = decompresser.inflate(buf);
o.write(buf, 0, i);
}
output = o.toByteArray();
} catch (Exception e) {
output = data;
e.printStackTrace();
} finally {
try {
o.close();
} catch (IOException e) {
e.printStackTrace();
}
}
decompresser.end();
return output;
}
use of java.util.zip.Inflater 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.Inflater in project teaTime by ancfdy.
the class AppZLibMgr method decompress.
/**
* 解压缩
*
* @param data
* 待压缩的数据
* @return byte[] 解压缩后的数据
*/
public static byte[] decompress(byte[] data) {
byte[] output = new byte[0];
Inflater decompresser = new Inflater();
decompresser.reset();
decompresser.setInput(data);
ByteArrayOutputStream o = new ByteArrayOutputStream(data.length);
try {
byte[] buf = new byte[1024];
while (!decompresser.finished()) {
int i = decompresser.inflate(buf);
o.write(buf, 0, i);
}
output = o.toByteArray();
} catch (Exception e) {
output = data;
e.printStackTrace();
} finally {
try {
o.close();
} catch (IOException e) {
e.printStackTrace();
}
}
decompresser.end();
return output;
}
Aggregations