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;
}
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);
}
Aggregations