use of com.github.davidmoten.rx2.Bytes in project navajo by Dexels.
the class TestRx method testGzip.
@Test
public void testGzip() throws FileNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] original = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml")).reduce(baos, (byteout, bytes) -> {
try {
byteout.write(bytes);
} catch (Exception e) {
}
return byteout;
}).blockingGet().toByteArray();
ByteArrayOutputStream baos_compressed = new ByteArrayOutputStream();
byte[] compressed = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml")).compose(StreamCompress.gzip()).doOnError(e -> e.printStackTrace()).reduce(baos_compressed, (byteout, bytes) -> {
byteout.write(bytes);
return byteout;
}).blockingGet().toByteArray();
ByteArrayOutputStream baos_reinflate = new ByteArrayOutputStream();
byte[] reflated = Flowable.<byte[]>just(compressed).compose(StreamCompress.gunzip()).reduce(baos_reinflate, (byteout, bytes) -> {
try {
System.err.println("Bytes decompressed: " + bytes.length);
byteout.write(bytes);
} catch (Exception e) {
}
return byteout;
}).blockingGet().toByteArray();
System.err.println("original: " + original.length);
System.err.println("gzipped: " + compressed.length);
System.err.println("reinflated: " + reflated.length);
Assert.assertArrayEquals(original, reflated);
}
use of com.github.davidmoten.rx2.Bytes in project navajo by Dexels.
the class TestRx method testGzipBig.
// TODO, reinstate this test. randomfile has been excluded from the build (it's 10M), create some random generation, I'd like
// to remove the randomdile from git as well
@Test
@Ignore
public void testGzipBig() throws IOException {
ByteArrayOutputStream baos_compressed = new ByteArrayOutputStream();
AtomicInteger size = new AtomicInteger();
byte[] compressed = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("randomfile")).doOnNext(e -> size.addAndGet(e.length)).compose(StreamCompress.gzip()).doOnError(e -> e.printStackTrace()).reduce(baos_compressed, (byteout, bytes) -> {
byteout.write(bytes);
return byteout;
}).blockingGet().toByteArray();
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed));
ByteArrayOutputStream baos_decompressed = new ByteArrayOutputStream();
copyResource(baos_decompressed, gis);
Assert.assertEquals(size.get(), baos_decompressed.size());
}
use of com.github.davidmoten.rx2.Bytes in project navajo by Dexels.
the class TestRx method repro.
@Test
public void repro() throws IOException {
File compressed = File.createTempFile("dump", ".xml.deflated");
File uncompressed = File.createTempFile("dump", ".xml");
InputStream resourceAsStream = TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml");
Bytes.from(resourceAsStream, 8192).doOnSubscribe(e -> System.err.println("Ataaaa")).doOnNext(b -> System.err.println("Bytes: " + b.length)).subscribe(StreamDocument.dumpToFile(uncompressed.getAbsolutePath()));
System.err.println("Uncompressed file at: " + uncompressed.getAbsolutePath());
Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml"), 8192).compose(StreamCompress.deflate()).subscribe(StreamDocument.dumpToFile(compressed.getAbsolutePath()));
System.err.println("Compressed file at: " + compressed.getAbsolutePath());
// 1,560
Assert.assertTrue(uncompressed.exists());
System.err.println("Compressed: " + compressed.length());
System.err.println("Uncompressed: " + uncompressed.length());
Assert.assertTrue(uncompressed.length() == 5258);
Assert.assertTrue(compressed.length() < uncompressed.length());
// compressed.delete();
// uncompressed.delete();
}
use of com.github.davidmoten.rx2.Bytes in project navajo by Dexels.
the class TestRx method testGzipOnly.
@Test
public void testGzipOnly() throws IOException {
ByteArrayOutputStream baos_compressed = new ByteArrayOutputStream();
byte[] compressed = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("TestBinaries.class")).compose(StreamCompress.gzip()).doOnError(e -> e.printStackTrace()).reduce(baos_compressed, (byteout, bytes) -> {
byteout.write(bytes);
return byteout;
}).blockingGet().toByteArray();
System.err.println("Compressed: " + compressed.length);
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed));
ByteArrayOutputStream baos_decompressed = new ByteArrayOutputStream();
copyResource(baos_decompressed, gis);
Assert.assertArrayEquals(Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("TestBinaries.class")).blockingFirst(), baos_decompressed.toByteArray());
}
use of com.github.davidmoten.rx2.Bytes in project navajo by Dexels.
the class TestRx method testDeflate.
@Test
public void testDeflate() throws FileNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] original = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("TestBinaries.class")).reduce(baos, (byteout, bytes) -> {
try {
byteout.write(bytes);
} catch (Exception e) {
}
return byteout;
}).blockingGet().toByteArray();
ByteArrayOutputStream baos_compressed = new ByteArrayOutputStream();
byte[] compressed = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("TestBinaries.class")).compose(StreamCompress.deflate()).doOnError(e -> e.printStackTrace()).reduce(baos_compressed, (byteout, bytes) -> {
byteout.write(bytes);
return byteout;
}).blockingGet().toByteArray();
ByteArrayOutputStream baos_reinflate = new ByteArrayOutputStream();
byte[] reflated = Flowable.<byte[]>just(compressed).compose(StreamCompress.inflate()).reduce(baos_reinflate, (byteout, bytes) -> {
try {
System.err.println("Bytes decompressed: " + bytes.length);
byteout.write(bytes);
} catch (Exception e) {
}
return byteout;
}).blockingGet().toByteArray();
System.err.println("original: " + original.length);
System.err.println("deflated: " + compressed.length);
System.err.println("reinflated: " + reflated.length);
Assert.assertArrayEquals(original, reflated);
}
Aggregations