Class ByteSource.ConcatenatedByteSource
- java.lang.Object
-
- com.google.common.io.ByteSource
-
- com.google.common.io.ByteSource.ConcatenatedByteSource
-
- Enclosing class:
- ByteSource
private static final class ByteSource.ConcatenatedByteSource extends ByteSource
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.io.ByteSource
ByteSource.AsCharSource
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Iterable<? extends ByteSource>
sources
-
Constructor Summary
Constructors Constructor Description ConcatenatedByteSource(java.lang.Iterable<? extends ByteSource> sources)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isEmpty()
Returns whether the source has zero bytes.java.io.InputStream
openStream()
Opens a newInputStream
for reading from this source.long
size()
Returns the size of this source in bytes, even if doing so requires opening and traversing an entire stream.Optional<java.lang.Long>
sizeIfKnown()
Returns the size of this source in bytes, if the size can be easily determined without actually opening the data stream.java.lang.String
toString()
-
Methods inherited from class com.google.common.io.ByteSource
asCharSource, concat, concat, concat, contentEquals, copyTo, copyTo, empty, hash, openBufferedStream, read, read, slice, wrap
-
-
-
-
Field Detail
-
sources
final java.lang.Iterable<? extends ByteSource> sources
-
-
Constructor Detail
-
ConcatenatedByteSource
ConcatenatedByteSource(java.lang.Iterable<? extends ByteSource> sources)
-
-
Method Detail
-
openStream
public java.io.InputStream openStream() throws java.io.IOException
Description copied from class:ByteSource
Opens a newInputStream
for reading from this source. This method returns a new, independent stream each time it is called.The caller is responsible for ensuring that the returned stream is closed.
- Specified by:
openStream
in classByteSource
- Throws:
java.io.IOException
- if an I/O error occurs while opening the stream
-
isEmpty
public boolean isEmpty() throws java.io.IOException
Description copied from class:ByteSource
Returns whether the source has zero bytes. The default implementation first checksByteSource.sizeIfKnown()
, returning true if it's known to be zero and false if it's known to be non-zero. If the size is not known, it falls back to opening a stream and checking for EOF.Note that, in cases where
sizeIfKnown
returns zero, it is possible that bytes are actually available for reading. (For example, some special files may return a size of 0 despite actually having content when read.) This means that a source may returntrue
fromisEmpty()
despite having readable content.- Overrides:
isEmpty
in classByteSource
- Throws:
java.io.IOException
- if an I/O error occurs
-
sizeIfKnown
public Optional<java.lang.Long> sizeIfKnown()
Description copied from class:ByteSource
Returns the size of this source in bytes, if the size can be easily determined without actually opening the data stream.The default implementation returns
Optional.absent()
. Some sources, such as a file, may return a non-absent value. 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).Additionally, for mutable sources such as files, a subsequent read may return a different number of bytes if the contents are changed.
- Overrides:
sizeIfKnown
in classByteSource
-
size
public long size() throws java.io.IOException
Description copied from class:ByteSource
Returns the size of this source in bytes, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, seeByteSource.sizeIfKnown()
.The default implementation calls
ByteSource.sizeIfKnown()
and returns the value if present. If absent, it will fall back to a heavyweight operation that will open a stream, read (orskip
, if possible) to the end of the stream and return the total number of bytes that were read.Note that for some sources that implement
ByteSource.sizeIfKnown()
to provide a more efficient implementation, 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, for mutable sources such as files, a subsequent read may return a different number of bytes if the contents are changed.
- Overrides:
size
in classByteSource
- Throws:
java.io.IOException
- if an I/O error occurs while reading the size of this source
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-