Class MoreFiles.PathByteSource
- java.lang.Object
-
- com.google.common.io.ByteSource
-
- com.google.common.io.MoreFiles.PathByteSource
-
- Enclosing class:
- MoreFiles
private static final class MoreFiles.PathByteSource 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 private static java.nio.file.LinkOption[]FOLLOW_LINKSprivate booleanfollowLinksprivate java.nio.file.OpenOption[]optionsprivate java.nio.file.Pathpath
-
Constructor Summary
Constructors Modifier Constructor Description privatePathByteSource(java.nio.file.Path path, java.nio.file.OpenOption... options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CharSourceasCharSource(java.nio.charset.Charset charset)Returns aCharSourceview of this byte source that decodes bytes read from this source as characters using the givenCharset.private static booleanfollowLinks(java.nio.file.OpenOption[] options)java.io.InputStreamopenStream()Opens a newInputStreamfor reading from this source.byte[]read()Reads the full contents of this byte source as a byte array.private java.nio.file.attribute.BasicFileAttributesreadAttributes()longsize()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.StringtoString()-
Methods inherited from class com.google.common.io.ByteSource
concat, concat, concat, contentEquals, copyTo, copyTo, empty, hash, isEmpty, openBufferedStream, read, slice, wrap
-
-
-
-
Method Detail
-
followLinks
private static boolean followLinks(java.nio.file.OpenOption[] options)
-
openStream
public java.io.InputStream openStream() throws java.io.IOExceptionDescription copied from class:ByteSourceOpens a newInputStreamfor 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:
openStreamin classByteSource- Throws:
java.io.IOException- if an I/O error occurs while opening the stream
-
readAttributes
private java.nio.file.attribute.BasicFileAttributes readAttributes() throws java.io.IOException- Throws:
java.io.IOException
-
sizeIfKnown
public Optional<java.lang.Long> sizeIfKnown()
Description copied from class:ByteSourceReturns 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:
sizeIfKnownin classByteSource
-
size
public long size() throws java.io.IOExceptionDescription copied from class:ByteSourceReturns 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:
sizein classByteSource- Throws:
java.io.IOException- if an I/O error occurs while reading the size of this source
-
read
public byte[] read() throws java.io.IOExceptionDescription copied from class:ByteSourceReads the full contents of this byte source as a byte array.- Overrides:
readin classByteSource- Throws:
java.io.IOException- if an I/O error occurs while reading from this source
-
asCharSource
public CharSource asCharSource(java.nio.charset.Charset charset)
Description copied from class:ByteSourceReturns aCharSourceview 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 originalByteSourceis returned, rather than round-trip encoding. Subclasses that override this method should behave the same way.- Overrides:
asCharSourcein classByteSource
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-