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,UriByteSourceandFileByteSource.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBeanByteSource()Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanCharSourceasCharSource(Charset charset)BeanCharSourceasCharSourceUtf8()Returns aCharSourcefor the same bytes, converted to UTF-8.BeanCharSourceasCharSourceUtf8UsingBom()Returns aCharSourcefor the File, converted to UTF-8 using a Byte-Order Mark if available.Optional<String>getFileName()Gets the file name of the source.StringgetFileNameOrThrow()Gets the file name of the source.HashCodehash(HashFunction hashFunction)booleanisEmpty()Checks if the byte source is empty, throwing an unchecked exception.ArrayByteSourceload()Loads the content of the byte source into memory.byte[]read()Reads the source as a byte array, throwing an unchecked exception.StringreadUtf8()Reads the source, converting to UTF-8.StringreadUtf8UsingBom()Reads the source, converting to UTF-8 using a Byte-Order Mark if available.longsize()Gets the size of the byte source, throwing an unchecked exception.ArrayByteSourcetoBase64()Encodes the byte source using base-64.StringtoBase64String()Encodes the byte source using base-64, returning a string.ArrayByteSourcetoHash(HashFunction hashFunction)Returns a new byte source containing the hash of the content of this byte source.StringtoHashString(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
ByteSourceto throwUncheckedIOExceptioninstead ofIOException.- Overrides:
isEmptyin 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
ByteSourceto throwUncheckedIOExceptioninstead ofIOException.- Overrides:
sizein 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
ByteSourceto throwUncheckedIOExceptioninstead ofIOException.- Overrides:
readin 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:
asCharSourcein classByteSource
-
asCharSourceUtf8
public BeanCharSource asCharSourceUtf8()
Returns aCharSourcefor the same bytes, converted to UTF-8.- Returns:
- the equivalent
CharSource
-
asCharSourceUtf8UsingBom
public BeanCharSource asCharSourceUtf8UsingBom()
Returns aCharSourcefor 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:
hashin 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
md5sumcommand.- 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
-
-