Search in sources :

Example 91 with InflaterInputStream

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) DataInputStream(java.io.DataInputStream) Cleanup(lombok.Cleanup)

Example 92 with InflaterInputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) Test(org.junit.Test)

Example 93 with InflaterInputStream

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;
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) XmlParseException(cbit.vcell.xml.XmlParseException) ByteBuffer(java.nio.ByteBuffer) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 94 with InflaterInputStream

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());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 95 with InflaterInputStream

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;
}
Also used : Serializable(java.io.Serializable) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ObjectInputStream(java.io.ObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

InflaterInputStream (java.util.zip.InflaterInputStream)200 ByteArrayInputStream (java.io.ByteArrayInputStream)113 InputStream (java.io.InputStream)100 IOException (java.io.IOException)74 Inflater (java.util.zip.Inflater)66 ByteArrayOutputStream (java.io.ByteArrayOutputStream)50 GZIPInputStream (java.util.zip.GZIPInputStream)39 DataInputStream (java.io.DataInputStream)33 FileInputStream (java.io.FileInputStream)27 BufferedInputStream (java.io.BufferedInputStream)24 InputStreamReader (java.io.InputStreamReader)13 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)13 HttpURLConnection (java.net.HttpURLConnection)12 URL (java.net.URL)11 File (java.io.File)10 BufferedReader (java.io.BufferedReader)9 OutputStream (java.io.OutputStream)9 Point (java.awt.Point)7 EOFException (java.io.EOFException)7 URLConnection (java.net.URLConnection)7