use of java.util.zip.DataFormatException in project eiger by wlloyd.
the class DeflateCompressor method uncompress.
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IOException {
Inflater inf = inflater.get();
inf.reset();
inf.setInput(input, inputOffset, inputLength);
if (inf.needsInput())
return 0;
// We assume output is big enough
try {
return inf.inflate(output, outputOffset, output.length - outputOffset);
} catch (DataFormatException e) {
throw new IOException(e);
}
}
use of java.util.zip.DataFormatException in project eiger by wlloyd.
the class CassandraServer method uncompress.
private static String uncompress(ByteBuffer query, Compression compression) throws InvalidRequestException {
String queryString = null;
// Decompress the query string.
try {
switch(compression) {
case GZIP:
FastByteArrayOutputStream byteArray = new FastByteArrayOutputStream();
byte[] outBuffer = new byte[1024], inBuffer = new byte[1024];
Inflater decompressor = new Inflater();
int lenRead = 0;
while (true) {
if (decompressor.needsInput())
lenRead = query.remaining() < 1024 ? query.remaining() : 1024;
query.get(inBuffer, 0, lenRead);
decompressor.setInput(inBuffer, 0, lenRead);
int lenWrite = 0;
while ((lenWrite = decompressor.inflate(outBuffer)) != 0) byteArray.write(outBuffer, 0, lenWrite);
if (decompressor.finished())
break;
}
decompressor.end();
queryString = new String(byteArray.toByteArray(), 0, byteArray.size(), "UTF-8");
break;
case NONE:
try {
queryString = ByteBufferUtil.string(query);
} catch (CharacterCodingException ex) {
throw new InvalidRequestException(ex.getMessage());
}
break;
}
} catch (DataFormatException e) {
throw new InvalidRequestException("Error deflating query string.");
} catch (UnsupportedEncodingException e) {
throw new InvalidRequestException("Unknown query string encoding.");
}
return queryString;
}
use of java.util.zip.DataFormatException in project pulsar by yahoo.
the class CompressionCodecZLib method decode.
@Override
public ByteBuf decode(ByteBuf encoded, int uncompressedLength) throws IOException {
ByteBuf uncompressed = PooledByteBufAllocator.DEFAULT.heapBuffer(uncompressedLength, uncompressedLength);
int len = encoded.readableBytes();
byte[] array;
int offset;
if (encoded.hasArray()) {
array = encoded.array();
offset = encoded.arrayOffset() + encoded.readerIndex();
} else {
array = new byte[len];
encoded.getBytes(encoded.readerIndex(), array);
offset = 0;
}
int resultLength;
synchronized (inflater) {
inflater.setInput(array, offset, len);
try {
resultLength = inflater.inflate(uncompressed.array(), uncompressed.arrayOffset(), uncompressedLength);
} catch (DataFormatException e) {
throw new IOException(e);
}
inflater.reset();
}
checkArgument(resultLength == uncompressedLength);
uncompressed.writerIndex(uncompressedLength);
return uncompressed;
}
use of java.util.zip.DataFormatException in project ABPlayer by winkstu.
the class CompressionTools method decompressXML.
public static byte[] decompressXML(byte[] data) throws DataFormatException {
byte[] dest = new byte[data.length + 2];
System.arraycopy(data, 0, dest, 2, data.length);
dest[0] = 0x78;
dest[1] = 0x01;
data = dest;
Inflater decompresser = new Inflater();
decompresser.setInput(data);
byte[] bufferArray = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
try {
int i = 1;
while (i != 0) {
i = decompresser.inflate(bufferArray);
baos.write(bufferArray, 0, i);
}
data = baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
decompresser.end();
return data;
}
use of java.util.zip.DataFormatException in project geode by apache.
the class CommandResult method saveIncomingFiles.
public void saveIncomingFiles(String directory) throws IOException {
// dump file data if any
try {
GfJsonObject content = getContent();
if (content != null) {
GfJsonArray bytesArray = content.getJSONArray(CompositeResultData.BYTE_DATA_ACCESSOR);
AbstractResultData.readFileDataAndDump(bytesArray, directory);
} else {
// TODO Abhishek - add i18n
throw new RuntimeException("No associated files to save .. ");
// string
}
numTimesSaved = numTimesSaved + 1;
} catch (DataFormatException e) {
throw new RuntimeException(e);
} catch (GfJsonException e) {
throw new RuntimeException(e);
}
}
Aggregations