Search in sources :

Example 1 with InflaterReader

use of org.apache.activemq.artemis.utils.InflaterReader in project activemq-artemis by apache.

the class CompressedLargeMessageControllerImpl method getStream.

private DataInputStream getStream() {
    if (dataInput == null) {
        try {
            InputStream input = new ActiveMQBufferInputStream(bufferDelegate);
            dataInput = new DataInputStream(new InflaterReader(input));
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return dataInput;
}
Also used : InflaterReader(org.apache.activemq.artemis.utils.InflaterReader) DataInputStream(java.io.DataInputStream) ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) InputStream(java.io.InputStream) DataInputStream(java.io.DataInputStream) ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) IOException(java.io.IOException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 2 with InflaterReader

use of org.apache.activemq.artemis.utils.InflaterReader in project activemq-artemis by apache.

the class CompressionUtilTest method testInflaterReader.

@Test
public void testInflaterReader() throws Exception {
    String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
    byte[] input = inputString.getBytes(StandardCharsets.UTF_8);
    byte[] output = new byte[30];
    Deflater compressor = new Deflater();
    compressor.setInput(input);
    compressor.finish();
    int compressedDataLength = compressor.deflate(output);
    byte[] zipBytes = new byte[compressedDataLength];
    System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
    ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
    ArrayList<Integer> holder = new ArrayList<>();
    try (InflaterReader inflater = new InflaterReader(byteInput)) {
        int read = inflater.read();
        while (read != -1) {
            holder.add(read);
            read = inflater.read();
        }
    }
    byte[] result = new byte[holder.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = holder.get(i).byteValue();
    }
    String txt = new String(result);
    assertEquals(inputString, txt);
}
Also used : InflaterReader(org.apache.activemq.artemis.utils.InflaterReader) Deflater(java.util.zip.Deflater) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

InflaterReader (org.apache.activemq.artemis.utils.InflaterReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Deflater (java.util.zip.Deflater)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQBufferInputStream (org.apache.activemq.artemis.utils.ActiveMQBufferInputStream)1 Test (org.junit.Test)1