use of java.util.zip.Inflater 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.Inflater in project intellij-community by JetBrains.
the class JBZipEntry method getInputStream.
private InputStream getInputStream() throws IOException {
long start = calcDataOffset();
BoundedInputStream bis = new BoundedInputStream(start, getCompressedSize());
switch(getMethod()) {
case ZipEntry.STORED:
return bis;
case ZipEntry.DEFLATED:
bis.addDummy();
return new InflaterInputStream(bis, new Inflater(true));
default:
throw new ZipException("Found unsupported compression method " + getMethod());
}
}
use of java.util.zip.Inflater in project ABPlayer by winkstu.
the class CompressionTools method decompress.
public static byte[] decompress(byte[] value) throws DataFormatException {
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 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.Inflater in project OpenAM by OpenRock.
the class SAML2Utils method decodeFromRedirect.
/**
* Decodes the request message.
*
* @param str String to be decoded.
* @return String the decoded String.
*/
public static String decodeFromRedirect(final String str) {
final String classMethod = "SAML2Utils.decodeFromRedirect: ";
if (StringUtils.isEmpty(str)) {
debug.error(classMethod + "input is null.");
return null;
}
if (debug.messageEnabled()) {
debug.message(classMethod + "input string length : " + str.length());
debug.message(classMethod + "input string is ===>" + str + "<===");
}
byte[] input = Base64.decode(removeNewLineChars(str));
if (input == null || input.length == 0) {
debug.error(classMethod + "Base64 decoded result is null");
return null;
}
// From the Inflater JavaDoc:
// Note: When using the 'nowrap' option it is also necessary to provide an extra "dummy" byte as input.
// This is required by the ZLIB native library in order to support certain optimizations.
input = Arrays.copyOf(input, input.length + 1);
int bufferLength = 2048;
try {
if (bufferLen != null && !bufferLen.isEmpty()) {
bufferLength = Integer.parseInt(bufferLen);
}
} catch (NumberFormatException nfe) {
debug.error(classMethod + "Unable to parse buffer length.", nfe);
}
// Decompress the bytes
Inflater inflater = new Inflater(true);
InflaterInputStream inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(input), inflater);
ByteArrayOutputStream bout = new ByteArrayOutputStream(bufferLength);
try {
int b = inflaterInputStream.read();
while (b != -1) {
bout.write(b);
b = inflaterInputStream.read();
}
} catch (IOException e) {
debug.error(classMethod + "There was a problem reading the compressed input", e);
return null;
} finally {
IOUtils.closeIfNotNull(inflaterInputStream);
}
String result;
try {
result = bout.toString("UTF-8");
} catch (UnsupportedEncodingException uee) {
debug.error(classMethod + "cannot convert byte array to string.", uee);
return null;
}
if (debug.messageEnabled()) {
debug.message(classMethod + "Return value: \n" + result);
}
return result;
}
Aggregations