use of okio.ForwardingSource in project okhttp by square.
the class InterceptorTest method uppercase.
private static Source uppercase(Source original) {
return new ForwardingSource(original) {
@Override
public long read(Buffer sink, long byteCount) throws IOException {
Buffer mixedCase = new Buffer();
long count = original.read(mixedCase, byteCount);
sink.writeUtf8(mixedCase.readUtf8().toUpperCase(Locale.US));
return count;
}
};
}
use of okio.ForwardingSource in project okhttp by square.
the class ResponseBodyTest method readerClosedAfterBomClosesUnderlyingSource.
@Test
public void readerClosedAfterBomClosesUnderlyingSource() throws IOException {
final AtomicBoolean closed = new AtomicBoolean();
ResponseBody body = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}
@Override
public long contentLength() {
return 5;
}
@Override
public BufferedSource source() {
ResponseBody body = body("fffe680065006c006c006f00");
return Okio.buffer(new ForwardingSource(body.source()) {
@Override
public void close() throws IOException {
closed.set(true);
super.close();
}
});
}
};
Reader reader = body.charStream();
assertEquals('h', reader.read());
reader.close();
assertTrue(closed.get());
}
use of okio.ForwardingSource in project okhttp by square.
the class ResponseBodyTest method byteStreamClosesUnderlyingSource.
@Test
public void byteStreamClosesUnderlyingSource() throws IOException {
final AtomicBoolean closed = new AtomicBoolean();
ResponseBody body = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}
@Override
public long contentLength() {
return 5;
}
@Override
public BufferedSource source() {
Buffer source = new Buffer().writeUtf8("hello");
return Okio.buffer(new ForwardingSource(source) {
@Override
public void close() throws IOException {
closed.set(true);
super.close();
}
});
}
};
body.byteStream().close();
assertTrue(closed.get());
}
use of okio.ForwardingSource in project okhttp by square.
the class ResponseBodyTest method readerClosedBeforeBomClosesUnderlyingSource.
@Test
public void readerClosedBeforeBomClosesUnderlyingSource() throws IOException {
final AtomicBoolean closed = new AtomicBoolean();
ResponseBody body = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}
@Override
public long contentLength() {
return 5;
}
@Override
public BufferedSource source() {
ResponseBody body = body("fffe680065006c006c006f00");
return Okio.buffer(new ForwardingSource(body.source()) {
@Override
public void close() throws IOException {
closed.set(true);
super.close();
}
});
}
};
body.charStream().close();
assertTrue(closed.get());
}
use of okio.ForwardingSource in project okhttp by square.
the class ResponseBodyTest method sourceClosesUnderlyingSource.
@Test
public void sourceClosesUnderlyingSource() throws IOException {
final AtomicBoolean closed = new AtomicBoolean();
ResponseBody body = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}
@Override
public long contentLength() {
return 5;
}
@Override
public BufferedSource source() {
Buffer source = new Buffer().writeUtf8("hello");
return Okio.buffer(new ForwardingSource(source) {
@Override
public void close() throws IOException {
closed.set(true);
super.close();
}
});
}
};
body.source().close();
assertTrue(closed.get());
}
Aggregations