use of java.util.zip.InflaterInputStream in project pravega by pravega.
the class TagRecord method decompressArrayOption.
private static Collection<String> decompressArrayOption(final byte[] compressed) throws IOException {
InputStream in = new InflaterInputStream(new ByteArrayInputStream(compressed));
@Cleanup DataInputStream din = new DataInputStream(in);
List<String> tags = new ArrayList<>();
while (true) {
try {
tags.add(din.readUTF());
} catch (EOFException e) {
break;
}
}
return tags;
}
use of java.util.zip.InflaterInputStream in project cxf by apache.
the class DeflateEncoderDecoderTest method testInflateDeflateWithTokenDuplication.
@Test
public void testInflateDeflateWithTokenDuplication() throws Exception {
String token = "valid_grant valid_grant valid_grant valid_grant valid_grant valid_grant";
DeflateEncoderDecoder deflateEncoderDecoder = new DeflateEncoderDecoder();
byte[] deflatedToken = deflateEncoderDecoder.deflateToken(token.getBytes());
String cxfInflatedToken = IOUtils.toString(deflateEncoderDecoder.inflateToken(deflatedToken));
String streamInflatedToken = IOUtils.toString(new InflaterInputStream(new ByteArrayInputStream(deflatedToken), new Inflater(true)));
assertEquals(streamInflatedToken, token);
assertEquals(cxfInflatedToken, token);
}
use of java.util.zip.InflaterInputStream in project vcell by virtualcell.
the class MicroscopyXmlReader method getUShortImage.
/**
* This method returns a VCIMage object from a XML representation.
* Creation date: (3/16/2001 3:41:24 PM)
* @param param org.jdom.Element
* @return VCImage
* @throws XmlParseException
*/
private UShortImage getUShortImage(Element param) throws XmlParseException {
// get the attributes
Element tempelement = param.getChild(XMLTags.ImageDataTag);
int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
final int BYTES_PER_SHORT = 2;
int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
// getpixels
String hexEncodedBytes = tempelement.getText();
byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
InputStream rawInputStream = rawByteArrayInputStream;
if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
}
byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
int readCount = 0;
try {
while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
}
} catch (Exception e) {
e.printStackTrace();
throw new XmlParseException("error reading image pixels: ", e);
} finally {
if (rawInputStream != null) {
try {
rawInputStream.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
short[] shortPixels = new short[aNumX * aNumY * aNumZ];
for (int i = 0; i < shortPixels.length; i++) {
shortPixels[i] = byteBuffer.getShort();
}
Element extentElement = param.getChild(XMLTags.ExtentTag);
Extent extent = null;
if (extentElement != null) {
extent = vcellXMLReader.getExtent(extentElement);
}
Element originElement = param.getChild(XMLTags.OriginTag);
Origin origin = null;
if (originElement != null) {
origin = vcellXMLReader.getOrigin(originElement);
}
// //set attributes
// String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
// String annotation = param.getChildText(XMLTags.AnnotationTag);
UShortImage newimage;
try {
newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
} catch (ImageException e) {
e.printStackTrace();
throw new XmlParseException("error reading image: ", e);
}
return newimage;
}
use of java.util.zip.InflaterInputStream in project vcell by virtualcell.
the class VCImageCompressed method getPixels.
/**
* getPixels method comment.
*/
public byte[] getPixels() throws ImageException {
try {
if (uncompressed == null) {
lg.debug("VCImageCompressed.getPixels() <<<<<<UNCOMPRESSING>>>>>>");
ByteArrayInputStream bis = new ByteArrayInputStream(compressedPixels);
InflaterInputStream iis = new InflaterInputStream(bis);
int temp;
byte[] buf = new byte[65536];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((temp = iis.read(buf, 0, buf.length)) != -1) {
bos.write(buf, 0, temp);
}
// byte uncompressed[] = new byte[getSizeX()*getSizeY()*getSizeZ()];
// int result = iis.read(uncompressed,0,getSizeX()*getSizeY()*getSizeZ());
// return uncompressed;
uncompressed = bos.toByteArray();
}
return uncompressed;
} catch (IOException e) {
lg.debug("getPixels( )", e);
throw new ImageException(e.getMessage());
}
}
use of java.util.zip.InflaterInputStream in project vcell by virtualcell.
the class BeanUtils method fromCompressedSerialized.
public static Serializable fromCompressedSerialized(byte[] objData) throws ClassNotFoundException, java.io.IOException {
long before = 0;
if (lg.isTraceEnabled()) {
before = System.currentTimeMillis();
}
java.io.ByteArrayInputStream bis = new java.io.ByteArrayInputStream(objData);
InflaterInputStream iis = new InflaterInputStream(bis);
java.io.ObjectInputStream ois = new java.io.ObjectInputStream(iis);
Serializable cacheClone = (Serializable) ois.readObject();
ois.close();
bis.close();
if (lg.isTraceEnabled()) {
long after = System.currentTimeMillis();
lg.trace("fromCompressedSerialized(): t=" + (after - before) + " ms, (" + cacheClone + ")");
}
return cacheClone;
}
Aggregations