Class MoreFiles.PathByteSource
- Enclosing class:
MoreFiles
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.common.io.ByteSource
ByteSource.AsCharSource
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final LinkOption[]
private final boolean
private final OpenOption[]
private final Path
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasCharSource
(Charset charset) Returns aCharSource
view of this byte source that decodes bytes read from this source as characters using the givenCharset
.private static boolean
followLinks
(OpenOption[] options) Opens a newInputStream
for reading from this source.byte[]
read()
Reads the full contents of this byte source as a byte array.private BasicFileAttributes
long
size()
Returns the size of this source in bytes, even if doing so requires opening and traversing an entire stream.Returns the size of this source in bytes, if the size can be easily determined without actually opening the data stream.toString()
Methods inherited from class com.google.common.io.ByteSource
concat, concat, concat, contentEquals, copyTo, copyTo, empty, hash, isEmpty, openBufferedStream, read, slice, wrap
-
Field Details
-
FOLLOW_LINKS
-
path
-
options
-
followLinks
private final boolean followLinks
-
-
Constructor Details
-
PathByteSource
-
-
Method Details
-
followLinks
-
openStream
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:
IOException
- if an I/O error occurs while opening the stream
-
readAttributes
- Throws:
IOException
-
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
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:
IOException
- if an I/O error occurs while reading the size of this source
-
read
Description copied from class:ByteSource
Reads the full contents of this byte source as a byte array.- Overrides:
read
in classByteSource
- Throws:
IOException
- if an I/O error occurs while reading from this source
-
asCharSource
Description copied from class:ByteSource
Returns aCharSource
view of this byte source that decodes bytes read from this source as characters using the givenCharset
.If
CharSource.asByteSource(java.nio.charset.Charset)
is called on the returned source with the same charset, the default implementation of this method will ensure that the originalByteSource
is returned, rather than round-trip encoding. Subclasses that override this method should behave the same way.- Overrides:
asCharSource
in classByteSource
-
toString
-