public final class StringCharSource extends BeanCharSource implements org.joda.beans.ImmutableBean, Serializable
String.
This implementation allows IOException to be avoided in many cases,
and to be able to create and retrieve the internal array unsafely.
| Modifier and Type | Field and Description |
|---|---|
static StringCharSource |
EMPTY
An empty source.
|
| Modifier and Type | Method and Description |
|---|---|
ArrayByteSource |
asByteSource(Charset charset) |
ArrayByteSource |
asByteSourceUtf8()
Converts this char source to a byte source in UTF-8.
|
long |
copyTo(Appendable appendable) |
long |
copyTo(CharSink sink) |
boolean |
equals(Object obj) |
static StringCharSource |
from(CharSource other)
Obtains an instance from another char source.
|
static StringCharSource |
from(CheckedSupplier<? extends Reader> readerSupplier)
Obtains an instance from a
Reader. |
static StringCharSource |
from(Readable reader)
Obtains an instance from a
Readable. |
static StringCharSource |
fromBytes(byte[] bytes,
Charset charset)
Obtains an instance from a byte array.
|
static StringCharSource |
fromBytesUtf8(byte[] bytes)
Obtains an instance from a UTF-8 byte array.
|
Optional<String> |
getFileName()
Gets the file name of the source.
|
int |
hashCode() |
boolean |
isEmpty() |
long |
length() |
Optional<Long> |
lengthIfKnown()
Gets the length, which is always known.
|
StringCharSource |
load()
Loads the content of the source into memory.
|
org.joda.beans.MetaBean |
metaBean() |
static StringCharSource |
of(String str)
Obtains an instance.
|
Reader |
openStream() |
String |
read() |
String |
toString() |
StringCharSource |
withFileName(String fileName)
Returns an instance with the file name updated.
|
forEachLine, getFileNameOrThrow, lines, readFirstLine, readLines, readLinesconcat, concat, concat, empty, openBufferedStream, wrappublic static final StringCharSource EMPTY
public static StringCharSource of(String str)
str - the stringpublic static StringCharSource fromBytesUtf8(byte[] bytes)
bytes - the UTF-8 bytespublic static StringCharSource fromBytes(byte[] bytes, Charset charset)
bytes - the bytescharset - the encodingpublic static StringCharSource from(CharSource other)
other - the other char sourceUncheckedIOException - if an IO error occurspublic static StringCharSource from(CheckedSupplier<? extends Reader> readerSupplier)
Reader.
This method use the supplier to open the reader, extract the chars and close the reader. It is intended that invoking the supplier opens the reader. It is not intended that an already open reader is supplied.
readerSupplier - the supplier of the readerUncheckedIOException - if an IO error occurspublic static StringCharSource from(Readable reader) throws IOException
Readable.
This method uses an already open reader, extracting the chars. The stream is not closed - that is the responsibility of the caller.
reader - the open reader, which will not be closedIOException - if an IO error occurspublic org.joda.beans.MetaBean metaBean()
metaBean in interface org.joda.beans.Beanpublic Optional<String> getFileName()
BeanCharSourceMost sources originate from a file-based location. This is captured and returned here where available.
getFileName in class BeanCharSourcepublic StringCharSource withFileName(String fileName)
If a path is passed in, only the file name is retained.
fileName - the file name, an empty string can be used to remove the file namepublic Reader openStream()
openStream in class CharSourcepublic boolean isEmpty()
isEmpty in class BeanCharSourcepublic Optional<Long> lengthIfKnown()
lengthIfKnown in class CharSourcepublic long length()
length in class BeanCharSourcepublic long copyTo(Appendable appendable) throws IOException
copyTo in class CharSourceIOExceptionpublic long copyTo(CharSink sink) throws IOException
copyTo in class CharSourceIOExceptionpublic String read()
read in class BeanCharSourcepublic StringCharSource load()
BeanCharSourceload in class BeanCharSourcepublic ArrayByteSource asByteSourceUtf8()
BeanCharSourceasByteSourceUtf8 in class BeanCharSourcepublic ArrayByteSource asByteSource(Charset charset)
asByteSource in class BeanCharSourceCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.