use of java.io.FilterOutputStream in project javaee7-samples by javaee-samples.
the class MyServerWriterInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext wic) throws IOException, WebApplicationException {
System.out.println("MyServerWriterInterceptor");
wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@Override
public void write(int b) throws IOException {
baos.write(b);
super.write(b);
}
@Override
public void close() throws IOException {
System.out.println("MyServerWriterInterceptor --> " + baos.toString());
super.close();
}
});
wic.proceed();
}
use of java.io.FilterOutputStream in project javaee7-samples by javaee-samples.
the class MyClientWriterInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext wic) throws IOException, WebApplicationException {
System.out.println("MyClientWriterInterceptor");
wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@Override
public void write(int b) throws IOException {
baos.write(b);
super.write(b);
}
@Override
public void close() throws IOException {
System.out.println("MyClientWriterInterceptor --> " + baos.toString());
super.close();
}
});
// wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {
//
// @Override
// public void write(int b) throws IOException {
// System.out.println("**** " + (char)b);
// super.write(b);
// }
//
// });
wic.proceed();
}
use of java.io.FilterOutputStream in project druid by druid-io.
the class CompressionUtilsTest method testGoodGzipWithException.
@Test
public void testGoodGzipWithException() throws Exception {
final AtomicLong flushes = new AtomicLong(0);
final File tmpDir = temporaryFolder.newFolder("testGoodGzipByteSource");
final File gzFile = new File(tmpDir, testFile.getName() + ".gz");
Assert.assertFalse(gzFile.exists());
CompressionUtils.gzip(Files.asByteSource(testFile), new ByteSink() {
@Override
public OutputStream openStream() throws IOException {
return new FilterOutputStream(new FileOutputStream(gzFile)) {
@Override
public void flush() throws IOException {
if (flushes.getAndIncrement() > 0) {
super.flush();
} else {
throw new IOException("Haven't flushed enough");
}
}
};
}
}, Predicates.<Throwable>alwaysTrue());
Assert.assertTrue(gzFile.exists());
try (final InputStream inputStream = CompressionUtils.gzipInputStream(new FileInputStream(gzFile))) {
assertGoodDataStream(inputStream);
}
if (!testFile.delete()) {
throw new IOException(String.format("Unable to delete file [%s]", testFile.getAbsolutePath()));
}
Assert.assertFalse(testFile.exists());
CompressionUtils.gunzip(Files.asByteSource(gzFile), testFile);
Assert.assertTrue(testFile.exists());
try (final InputStream inputStream = new FileInputStream(testFile)) {
assertGoodDataStream(inputStream);
}
// 2 for suppressed closes, 2 for manual calls to shake out errors
Assert.assertEquals(4, flushes.get());
}
use of java.io.FilterOutputStream in project j2objc by google.
the class OldFilterOutputStreamTest method test_writeI.
public void test_writeI() throws IOException {
Support_OutputStream sos = new Support_OutputStream(1);
os = new FilterOutputStream(sos);
os.write(42);
bis = new ByteArrayInputStream(sos.toByteArray());
assertTrue("Test 1: Byte has not been written.", bis.available() == 1);
assertEquals("Test 2: Incorrect byte written or read;", 42, bis.read());
try {
// Support_OutputStream throws an IOException if the internal
// buffer is full, which it should be now.
os.write(42);
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.FilterOutputStream in project j2objc by google.
the class OldFilterOutputStreamTest method test_write$BII_Exception.
public void test_write$BII_Exception() throws IOException {
Support_OutputStream sos = new Support_OutputStream(testLength);
os = new FilterOutputStream(sos);
byte[] buf = new byte[10];
try {
os.write(buf, -1, 1);
fail("IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
os.write(buf, 0, -1);
fail("IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
os.write(buf, 10, 1);
fail("IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected.
}
}
Aggregations