use of java.util.zip.Inflater 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.Inflater in project ddf by codice.
the class RestSecurity method inflateBase64.
public static String inflateBase64(String base64EncodedValue) throws IOException {
byte[] deflatedValue = Base64.getMimeDecoder().decode(base64EncodedValue);
InputStream is = new InflaterInputStream(new ByteArrayInputStream(deflatedValue), new Inflater(GZIP_COMPATIBLE));
return IOUtils.toString(is, StandardCharsets.UTF_8.name());
}
use of java.util.zip.Inflater in project graphhopper by graphhopper.
the class CompressedArray method decompress.
/**
* Decompress the byte array previously returned by compress
*/
public static byte[] decompress(byte[] value) throws DataFormatException {
// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);
Inflater decompressor = new Inflater();
try {
decompressor.setInput(value);
final byte[] buf = new byte[1024];
while (!decompressor.finished()) {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} finally {
decompressor.end();
}
return bos.toByteArray();
}
use of java.util.zip.Inflater in project inbot-utils by Inbot.
the class CompressionUtils method decompress.
public static byte[] decompress(byte[] compressed) {
Inflater inflater = new Inflater();
inflater.setInput(compressed);
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressed.length);
// Compress the data
byte[] buf = new byte[1024];
try {
while (!inflater.finished()) {
int count = inflater.inflate(buf);
bos.write(buf, 0, count);
}
bos.close();
} catch (IOException e) {
throw new IllegalArgumentException("could not decompress");
} catch (DataFormatException e) {
throw new IllegalArgumentException("could not decompress");
}
return bos.toByteArray();
}
use of java.util.zip.Inflater in project JGroups by belaban.
the class COMPRESS method uncompress.
/**
* Returns a new message as a result of uncompressing msg, or null if msg couldn't be uncompressed
*/
protected Message uncompress(Message msg, int original_size) {
byte[] compressed_payload = msg.getRawBuffer();
if (compressed_payload != null && compressed_payload.length > 0) {
byte[] uncompressed_payload = new byte[original_size];
Inflater inflater = null;
try {
inflater = inflater_pool.take();
inflater.reset();
inflater.setInput(compressed_payload, msg.getOffset(), msg.getLength());
try {
inflater.inflate(uncompressed_payload);
// we need to copy: https://jira.jboss.org/jira/browse/JGRP-867
return msg.copy(false).setBuffer(uncompressed_payload);
} catch (DataFormatException e) {
log.error(Util.getMessage("CompressionFailure"), e);
}
} catch (InterruptedException e) {
// set the interrupt bit again, so caller can handle it
Thread.currentThread().interrupt();
} finally {
if (inflater != null)
inflater_pool.offer(inflater);
}
}
return null;
}
Aggregations