Package com.opengamma.strata.collect.io
Class BeanByteSource
- java.lang.Object
-
- com.google.common.io.ByteSource
-
- com.opengamma.strata.collect.io.BeanByteSource
-
- All Implemented Interfaces:
org.joda.beans.Bean
,org.joda.beans.ImmutableBean
- Direct Known Subclasses:
ArrayByteSource
,FileByteSource
,UriByteSource
public abstract class BeanByteSource extends ByteSource implements org.joda.beans.ImmutableBean
A byte source implementation that is also a Joda-Bean.See
ArrayByteSource
,UriByteSource
andFileByteSource
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BeanByteSource()
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanCharSource
asCharSource(Charset charset)
BeanCharSource
asCharSourceUtf8()
Returns aCharSource
for the same bytes, converted to UTF-8.BeanCharSource
asCharSourceUtf8UsingBom()
Returns aCharSource
for the File, converted to UTF-8 using a Byte-Order Mark if available.Optional<String>
getFileName()
Gets the file name of the source.String
getFileNameOrThrow()
Gets the file name of the source.HashCode
hash(HashFunction hashFunction)
boolean
isEmpty()
Checks if the byte source is empty, throwing an unchecked exception.ArrayByteSource
load()
Loads the content of the byte source into memory.byte[]
read()
Reads the source as a byte array, throwing an unchecked exception.String
readUtf8()
Reads the source, converting to UTF-8.String
readUtf8UsingBom()
Reads the source, converting to UTF-8 using a Byte-Order Mark if available.long
size()
Gets the size of the byte source, throwing an unchecked exception.ArrayByteSource
toBase64()
Encodes the byte source using base-64.String
toBase64String()
Encodes the byte source using base-64, returning a string.ArrayByteSource
toHash(HashFunction hashFunction)
Returns a new byte source containing the hash of the content of this byte source.String
toHashString(HashFunction hashFunction)
Returns a new byte source containing the hash of the content of this byte source.-
Methods inherited from class com.google.common.io.ByteSource
concat, concat, concat, contentEquals, copyTo, copyTo, empty, openBufferedStream, openStream, read, sizeIfKnown, slice, wrap
-
-
-
-
Method Detail
-
getFileName
public Optional<String> getFileName()
Gets the file name of the source.Most sources originate from a file-based location. This is captured and returned here where available.
- Returns:
- the file name, empty if not known
-
getFileNameOrThrow
public String getFileNameOrThrow()
Gets the file name of the source.Most sources originate from a file-based location. This is captured and returned here where available.
- Returns:
- the file name
- Throws:
IllegalArgumentException
- if the file name is not known
-
isEmpty
public boolean isEmpty()
Checks if the byte source is empty, throwing an unchecked exception.This overrides
ByteSource
to throwUncheckedIOException
instead ofIOException
.- Overrides:
isEmpty
in classByteSource
- Throws:
UncheckedIOException
- if an IO error occurs
-
size
public long size()
Gets the size of the byte source, throwing an unchecked exception.This overrides
ByteSource
to throwUncheckedIOException
instead ofIOException
.- Overrides:
size
in classByteSource
- Throws:
UncheckedIOException
- if an IO error occurs
-
read
public byte[] read()
Reads the source as a byte array, throwing an unchecked exception.This overrides
ByteSource
to throwUncheckedIOException
instead ofIOException
.- Overrides:
read
in classByteSource
- Returns:
- the byte array
- Throws:
UncheckedIOException
- if an IO error occurs
-
readUtf8
public String readUtf8()
Reads the source, converting to UTF-8.- Returns:
- the UTF-8 string
- Throws:
UncheckedIOException
- if an IO error occurs
-
readUtf8UsingBom
public String readUtf8UsingBom()
Reads the source, converting to UTF-8 using a Byte-Order Mark if available.- Returns:
- the UTF-8 string
- Throws:
UncheckedIOException
- if an IO error occurs
-
asCharSource
public BeanCharSource asCharSource(Charset charset)
- Overrides:
asCharSource
in classByteSource
-
asCharSourceUtf8
public BeanCharSource asCharSourceUtf8()
Returns aCharSource
for the same bytes, converted to UTF-8.- Returns:
- the equivalent
CharSource
-
asCharSourceUtf8UsingBom
public BeanCharSource asCharSourceUtf8UsingBom()
Returns aCharSource
for the File, converted to UTF-8 using a Byte-Order Mark if available.- Returns:
- the equivalent
CharSource
-
load
public ArrayByteSource load()
Loads the content of the byte source into memory.- Returns:
- the byte array
- Throws:
UncheckedIOException
- if an IO error occurs
-
hash
public HashCode hash(HashFunction hashFunction)
- Overrides:
hash
in classByteSource
-
toHash
public ArrayByteSource toHash(HashFunction hashFunction)
Returns a new byte source containing the hash of the content of this byte source.The returned hash is in byte form.
- Parameters:
hashFunction
- the hash function to use, seeHashing
- Returns:
- the new byte source representing the hash
- Throws:
UncheckedIOException
- if an IO error occurs
-
toHashString
public String toHashString(HashFunction hashFunction)
Returns a new byte source containing the hash of the content of this byte source.The returned hash is in string form. This form is intended to be compatible with tools like the UNIX
md5sum
command.- Parameters:
hashFunction
- the hash function to use, seeHashing
- Returns:
- the new byte source representing the hash
- Throws:
UncheckedIOException
- if an IO error occurs
-
toBase64
public ArrayByteSource toBase64()
Encodes the byte source using base-64.- Returns:
- the base-64 encoded form
- Throws:
UncheckedIOException
- if an IO error occurs
-
toBase64String
public String toBase64String()
Encodes the byte source using base-64, returning a string.Equivalent to
toBase64().readUtf8()
.- Returns:
- the base-64 encoded string
-
-