本文整理了Java中okio.Source.close()
方法的一些代码示例,展示了Source.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Source.close()
方法的具体详情如下:
包路径:okio.Source
类名称:Source
方法名:close
[英]Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.
[中]关闭此源并释放此源持有的资源。读取封闭源代码是错误的。多次关闭源是安全的。
代码示例来源:origin: apollographql/apollo-android
static void closeQuietly(Source source) {
try {
source.close();
} catch (Exception ignore) {
// ignore
}
}
代码示例来源:origin: square/okio
@Override public void close() throws IOException {
source.close();
}
}
代码示例来源:origin: apollographql/apollo-android
@Override public void close() throws IOException {
if (closed) return;
closed = true;
if (discard(this, HttpCodec.DISCARD_STREAM_TIMEOUT_MILLIS, MILLISECONDS)) {
responseBodySource.close();
commitCache();
} else {
responseBodySource.close();
abortCacheQuietly();
}
}
代码示例来源:origin: square/okio
@Override public void run() {
try {
pipe.source().close();
} catch (IOException e) {
throw new AssertionError();
}
}
}, 1000, TimeUnit.MILLISECONDS);
代码示例来源:origin: square/wire
/**
* Parses the {@code .wire} file at {@code base/path} and returns it. Returns null if no such
* file exists.
*/
private ProfileFileElement loadProfileFile(Path base, String path) throws IOException {
Source source = source(base, path);
if (source == null) return null;
try {
Location location = Location.get(base.toString(), path);
String data = Okio.buffer(source).readUtf8();
return new ProfileParser(location, data).read();
} catch (IOException e) {
throw new IOException("Failed to load " + source + " from " + base, e);
} finally {
source.close();
}
}
代码示例来源:origin: square/picasso
@Override
public void load(@NonNull Picasso picasso, @NonNull Request request, @NonNull Callback callback) {
initializeIfFirstTime();
boolean signaledCallback = false;
try {
Source source = Okio.source(assetManager.open(getFilePath(request)));
try {
Bitmap bitmap = decodeStream(source, request);
signaledCallback = true;
callback.onSuccess(new Result(bitmap, DISK));
} finally {
try {
source.close();
} catch (IOException ignored) {
}
}
} catch (Exception e) {
if (!signaledCallback) {
callback.onError(e);
}
}
}
代码示例来源:origin: square/wire
throw new IOException("Failed to load " + proto + " from " + base, e);
} finally {
source.close();
代码示例来源:origin: square/okio
@Test public void sourceMultipleClose() throws Exception {
Pipe pipe = new Pipe(100L);
pipe.source().close();
pipe.source().close();
}
代码示例来源:origin: square/okio
/** Reads all bytes from {@code source} and writes them to {@code sink}. */
private Long readAllAndClose(Source source, Sink sink) throws IOException {
long result = 0L;
Buffer buffer = new Buffer();
for (long count; (count = source.read(buffer, SEGMENT_SIZE)) != -1L; result += count) {
sink.write(buffer, count);
}
source.close();
sink.close();
return result;
}
代码示例来源:origin: square/okhttp
body.close();
代码示例来源:origin: square/okio
@Test public void sourceClose() throws Exception {
Pipe pipe = new Pipe(100L);
pipe.source().close();
try {
pipe.source().read(new Buffer(), 3);
fail();
} catch (IllegalStateException expected) {
assertEquals("closed", expected.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void wrappedSourceCloseTimesOut() throws Exception {
Source source = new ForwardingSource(new Buffer()) {
@Override public void close() throws IOException {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new AssertionError();
}
}
};
AsyncTimeout timeout = new AsyncTimeout();
timeout.timeout(250, TimeUnit.MILLISECONDS);
Source timeoutSource = timeout.source(source);
try {
timeoutSource.close();
fail();
} catch (InterruptedIOException expected) {
}
}
代码示例来源:origin: square/okio
@Override public ByteString call() throws Exception {
Buffer blackhole = new Buffer();
HashingSink hashingSink = HashingSink.sha1(blackhole);
Buffer buffer = new Buffer();
while (pipe.source().read(buffer, Long.MAX_VALUE) != -1) {
hashingSink.write(buffer, buffer.size());
blackhole.clear();
}
pipe.source().close();
return hashingSink.hash();
}
});
代码示例来源:origin: square/okio
@Test public void sinkCloseFailsIfReaderIsClosedBeforeAllDataIsRead() throws Exception {
Pipe pipe = new Pipe(100L);
pipe.sink().write(new Buffer().writeUtf8("abc"), 3);
pipe.source().close();
try {
pipe.sink().close();
fail();
} catch (IOException expected) {
assertEquals("source is closed", expected.getMessage());
}
}
代码示例来源:origin: square/okio
@Test public void sinkFlushFailsIfReaderIsClosedBeforeAllDataIsRead() throws Exception {
Pipe pipe = new Pipe(100L);
pipe.sink().write(new Buffer().writeUtf8("abc"), 3);
pipe.source().close();
try {
pipe.sink().flush();
fail();
} catch (IOException expected) {
assertEquals("source is closed", expected.getMessage());
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
body.close();
代码示例来源:origin: square/okhttp
in.close();
代码示例来源:origin: square/okio
@Test public void test() throws Exception {
Pipe pipe = new Pipe(6);
pipe.sink().write(new Buffer().writeUtf8("abc"), 3L);
Source source = pipe.source();
Buffer readBuffer = new Buffer();
assertEquals(3L, source.read(readBuffer, 6L));
assertEquals("abc", readBuffer.readUtf8());
pipe.sink().close();
assertEquals(-1L, source.read(readBuffer, 6L));
source.close();
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
in.close();
代码示例来源:origin: apollographql/apollo-android
in.close();
内容来源于网络,如有侵权,请联系作者删除!