use of java.io.FilterOutputStream in project nutz by nutzam.
the class Sender method getOutputStream.
protected OutputStream getOutputStream() throws IOException {
OutputStream out = conn.getOutputStream();
if (progressListener == null) {
return out;
}
return new FilterOutputStream(out) {
int count;
@Override
public void write(byte[] b, int off, int len) throws IOException {
super.write(b, off, len);
count += len;
progressListener.invoke(count);
}
};
}
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 ceylon by eclipse.
the class JarEntryManifestFileObject method openOutputStream.
@Override
public OutputStream openOutputStream() throws IOException {
this.baos = new ByteArrayOutputStream();
return new FilterOutputStream(this.baos) {
@Override
public void close() throws IOException {
// If the last line of a MANIFEST.MF lacks a newline
// then it gets ignored, so let's add one here
// to avoid that trap
super.write('\n');
super.close();
}
};
}
use of java.io.FilterOutputStream in project druid by druid-io.
the class StreamUtilsTest method testRetryExceptionOnFlush.
@Test
public void testRetryExceptionOnFlush() {
final byte[] bytes = new byte[1 << 10];
Random random = new Random(47831947819L);
random.nextBytes(bytes);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final AtomicLong outputFlushes = new AtomicLong(0);
Assert.assertEquals(bytes.length, StreamUtils.retryCopy(new ByteSource() {
@Override
public InputStream openStream() {
return new ByteArrayInputStream(bytes);
}
}, new ByteSink() {
@Override
public OutputStream openStream() {
byteArrayOutputStream.reset();
return new FilterOutputStream(byteArrayOutputStream) {
@Override
public void flush() throws IOException {
if (outputFlushes.getAndIncrement() > 0) {
out.flush();
} else {
throw new IOException("Test exception");
}
}
};
}
}, FileUtils.IS_EXCEPTION, 10));
// 2 closes and 2 manual flushes
Assert.assertEquals(4, outputFlushes.get());
Assert.assertArrayEquals(bytes, byteArrayOutputStream.toByteArray());
}
Aggregations