|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.io.ByteSource
public abstract class ByteSource
A readable source of bytes, such as a file. Unlike an InputStream
, a
ByteSource
is not an open, stateful stream for input that can be read and closed.
Instead, it is an immutable supplier of InputStream
instances.
ByteSource
provides two kinds of methods:
Constructor Summary | |
---|---|
ByteSource()
|
Method Summary | |
---|---|
CharSource |
asCharSource(java.nio.charset.Charset charset)
Returns a CharSource view of this byte source that decodes bytes read from this source
as characters using the given Charset . |
boolean |
contentEquals(ByteSource other)
Checks that the contents of this byte source are equal to the contents of the given byte source. |
long |
copyTo(ByteSink sink)
Copies the contents of this byte source to the given ByteSink . |
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. |
java.io.BufferedInputStream |
openBufferedStream()
Opens a new BufferedInputStream for reading from this source. |
abstract 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. |
long |
size()
Returns the size of this source in bytes. |
ByteSource |
slice(long offset,
long length)
Returns a view of a slice of this byte source that is at most length bytes long
starting at the given offset . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteSource()
Method Detail |
---|
public CharSource asCharSource(java.nio.charset.Charset charset)
CharSource
view of this byte source that decodes bytes read from this source
as characters using the given Charset
.
public abstract java.io.InputStream openStream() throws java.io.IOException
InputStream
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.
java.io.IOException
- if an I/O error occurs in the process of opening the streampublic java.io.BufferedInputStream openBufferedStream() throws java.io.IOException
BufferedInputStream
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.
java.io.IOException
- if an I/O error occurs in the process of opening the streampublic ByteSource slice(long offset, long length)
length
bytes long
starting at the given offset
.
java.lang.IllegalArgumentException
- if offset
or length
is negativepublic long size() throws java.io.IOException
skip
, 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.
java.io.IOException
- if an I/O error occurs in the process of reading the size of this sourcepublic long copyTo(java.io.OutputStream output) throws java.io.IOException
OutputStream
. Does not close
output
.
java.io.IOException
- if an I/O error occurs in the process of reading from this source or
writing to output
public long copyTo(ByteSink sink) throws java.io.IOException
ByteSink
.
java.io.IOException
- if an I/O error occurs in the process of reading from this source or
writing to sink
public byte[] read() throws java.io.IOException
java.io.IOException
- if an I/O error occurs in the process of reading from this sourcepublic HashCode hash(HashFunction hashFunction) throws java.io.IOException
java.io.IOException
- if an I/O error occurs in the process of reading from this sourcepublic boolean contentEquals(ByteSource other) throws java.io.IOException
java.io.IOException
- if an I/O error occurs in the process of reading from this source or
other
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |