private static class ByteSource.ByteArrayByteSource extends ByteSource
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
bytes |
| Modifier | Constructor and Description |
|---|---|
protected |
ByteArrayByteSource(byte[] bytes) |
| Modifier and Type | Method and Description |
|---|---|
long |
copyTo(java.io.OutputStream output)
Copies the contents of this byte source to the given
OutputStream. |
HashCode |
hash(HashFunction hashFunction)
Hashes the contents of this byte source using the given hash function.
|
boolean |
isEmpty()
Returns whether the source has zero bytes.
|
java.io.InputStream |
openBufferedStream()
Opens a new buffered
InputStream for reading from this source. |
java.io.InputStream |
openStream()
Opens a new
InputStream for reading from this source. |
byte[] |
read()
Reads the full contents of this byte source as a byte array.
|
<T> T |
read(ByteProcessor<T> processor)
Reads the contents of this byte source using the given
processor to process bytes as
they are read. |
long |
size()
Returns the size of this source in bytes.
|
java.lang.String |
toString() |
asCharSource, concat, concat, concat, contentEquals, copyTo, empty, slice, wrappublic java.io.InputStream openStream()
ByteSourceInputStream for reading from this source. This method should return a new,
independent stream each time it is called.
The caller is responsible for ensuring that the returned stream is closed.
openStream in class ByteSourcepublic java.io.InputStream openBufferedStream()
throws java.io.IOException
ByteSourceInputStream for reading from this source. The returned stream is
not required to be a BufferedInputStream in order to allow implementations to simply
delegate to ByteSource.openStream() when the stream returned by that method does not benefit
from additional buffering (for example, a ByteArrayInputStream). This method should
return a new, independent stream each time it is called.
The caller is responsible for ensuring that the returned stream is closed.
openBufferedStream in class ByteSourcejava.io.IOException - if an I/O error occurs in the process of opening the streampublic boolean isEmpty()
ByteSourceisEmpty in class ByteSourcepublic long size()
ByteSourceskip, if possible)
to the end of the stream and return the total number of bytes that were read.
For some sources, such as a file, this method may use a more efficient implementation. Note that in such cases, it is possible that this method will return a different number of bytes than would be returned by reading all of the bytes (for example, some special files may return a size of 0 despite actually having content when read).
In either case, if this is a mutable source such as a file, the size it returns may not be the same number of bytes a subsequent read would return.
size in class ByteSourcepublic byte[] read()
ByteSourceread in class ByteSourcepublic long copyTo(java.io.OutputStream output)
throws java.io.IOException
ByteSourceOutputStream. Does not close
output.copyTo in class ByteSourcejava.io.IOException - if an I/O error occurs in the process of reading from this source or
writing to outputpublic <T> T read(ByteProcessor<T> processor) throws java.io.IOException
ByteSourceprocessor to process bytes as
they are read. Stops when all bytes have been read or the consumer returns false.
Returns the result produced by the processor.read in class ByteSourcejava.io.IOException - if an I/O error occurs in the process of reading from this source or if
processor throws an IOExceptionpublic HashCode hash(HashFunction hashFunction) throws java.io.IOException
ByteSourcehash in class ByteSourcejava.io.IOException - if an I/O error occurs in the process of reading from this sourcepublic java.lang.String toString()
toString in class java.lang.Object