Interface DataConverter
public interface DataConverter
Container class that allows retrieving various representations of its contents.
If the underlying data is binary, and a character representation is required, then the container implementation should have the means to determine the character set of the underlying data. The character set is not passed in to any of the interface methods.
-
Method Summary
Modifier and TypeMethodDescriptionbyte @Nullable []@Nullable InputSourceReturn the underlying data as an XMLInputSource.Return data as anInputStream.asInputStream(String encodingCharset) Return data as anInputStream, encoded in the specifiedencodingCharset.@Nullable ObjectReturns the raw object inside this container, orNULLifisNull().asReader()Return data as aReader.@Nullable Serializable@Nullable SourceasSource()Return the underlying data as an XMLInputSource.@Nullable StringasString()booleanisBinary()Check if the underlying data is binary, or natively character-based.booleanisEmpty()Check if the data in the container is empty, such as a String of length 0.default booleanisNull()Check if the container containsNULLdata or not.booleanCheck if the data prefers to be represented in a Streaming format (InputStreamorReader.longsize()Size of (the binary representation of) the data, if possible to determine.
-
Method Details
-
isBinary
boolean isBinary()Check if the underlying data is binary, or natively character-based. Not related to whether a character set can be derived for the data. -
isEmpty
boolean isEmpty()Check if the data in the container is empty, such as a String of length 0. This is not the same asNULLdata, butNULLis always empty. -
isNull
default boolean isNull()Check if the container containsNULLdata or not. -
prefersStreaming
boolean prefersStreaming()Check if the data prefers to be represented in a Streaming format (InputStreamorReader. Generally, this implies the data is not readily available in-memory. -
size
long size()Size of (the binary representation of) the data, if possible to determine. WhenisEmpty()orisNull(), this method returns0. When the size of the data cannot be determined, will returnMessage.MESSAGE_SIZE_UNKNOWN. -
asRawObject
-
asSerializable
Returns aSerializablerepresentation of the data, orNULLifisNull(). This may be the same instance as the original data, if it already implementsSerializablenatively.- Throws:
IOException
-
asString
- Throws:
IOException
-
asByteArray
- Throws:
IOException
-
asReader
- Returns:
- A
Readerbacked by the represented data. The Reader might not have any data. Will never returnNULL. - Throws:
IOException- When any error occurs.
-
asInputStream
Return data as anInputStream. TheInputStreamis guaranteed to supportInputStream.mark(int)andInputStream.reset(). If the underlying data is character-based, the encoding of the stream is theStreamUtil.DEFAULT_INPUT_STREAM_ENCODING.- Returns:
- An
InputStreambacked by the represented data. The InputStream might not have any data. Will never returnNULL. - Throws:
IOException- When any error occurs.
-
asInputStream
Return data as anInputStream, encoded in the specifiedencodingCharset. TheInputStreamis guaranteed to supportInputStream.mark(int)andInputStream.reset().- Parameters:
encodingCharset- The charset into which to encode the data on theInputStream.- Returns:
- An
InputStreambacked by the represented data, (re-)encoded in the specifiedencodingCharset. The InputStream might not have any data. Will never returnNULL. - Throws:
IOException- When there was an error.
-
asInputSource
Return the underlying data as an XMLInputSource.- Throws:
IOException
-
asSource
Return the underlying data as an XMLInputSource.- Throws:
IOExceptionSAXException
-