public interface Source extends java.io.Closeable
Sources are easy to test: just use a
Buffer in your tests, and
fill it with the data your application is to read.
InputStream requires multiple layers when consumed data is
DataInputStream for primitive values, a
BufferedInputStream for buffering, and
strings. This class uses
BufferedSource for all of the above.
Source avoids the impossible-to-implement available() method. Instead callers specify
how many bytes they
Source omits the unsafe-to-compose mark and reset state that's tracked by
InputStream; instead, callers
just buffer what they need.
When implementing a source, you don't need to worry about the single-byte read method that is awkward to implement efficiently and returns one of 257 possible values.
And source has a stronger
won't return prematurely.
Okio.source(java.io.InputStream)to adapt an
InputStreamto a source. Use
BufferedSource.inputStream()to adapt a source to an
|Modifier and Type||Method and Description|
Closes this source and releases the resources held by this source.
Removes at least 1, and up to
Returns the timeout for this source.
long read(Buffer sink, long byteCount) throws java.io.IOException
byteCountbytes from this and appends them to
sink. Returns the number of bytes read, or -1 if this source is exhausted.
void close() throws java.io.IOException
Copyright © 2018. All Rights Reserved.