Package com.helger.commons.io
Interface IHasByteArray
- All Superinterfaces:
IHasInputStream,IHasInputStreamAndReader,IHasSize
- All Known Implementing Classes:
ByteArrayInputStreamProvider,ByteArrayWrapper,ReadableResourceByteArray,ReadableResourceString
Base interface for all objects owning a byte array.
- Since:
- 9.1.3
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]bytes()default byte[]default StringgetBytesAsString(Charset aCharset) default Stringdefault InputStreamGet the input stream to read from the object.intdefault booleanbooleanisCopy()default booleanisEmpty()default booleandefault booleandefault booleanCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.default booleanstartsWith(byte[] aCmpBytes) Check if the passed byte array starts with the bytes of this object.default voidwriteTo(OutputStream aOS) Write the relevant part of the byte array onto the provided output stream.Methods inherited from interface com.helger.commons.io.IHasInputStream
getBufferedInputStream, withBufferedInputStreamDo, withInputStreamDoMethods inherited from interface com.helger.commons.io.IHasInputStreamAndReader
getBufferedReader, getReader
-
Method Details
-
isEmpty
default boolean isEmpty() -
isNotEmpty
default boolean isNotEmpty()- Specified by:
isNotEmptyin interfaceIHasSize- Returns:
trueif at least one item is present,falseif no item is present.- See Also:
-
isCopy
boolean isCopy()- Returns:
trueif the contained byte array was copied in the constructor or not.
-
getAllBytes
- Returns:
- A copy of all bytes contained, from
getOffset()forIHasSize.size()bytes. Nevernull.
-
bytes
- Returns:
- A reference to the contained byte array. Gives write access to the
payload! Don't forget to apply
getOffset()andIHasSize.size(). Nevernull.
-
isPartialArray
default boolean isPartialArray()- Returns:
trueif this object deals with a partial array that either has an offset or which is not completely used. Based on this method, some performance optimizations might be used to avoid copying data.- Since:
- 11.1.5
-
getOffset
- Returns:
- The offset into the byte array to start reading. This is always 0 when copied. Must be ge; 0.
- See Also:
-
hasOffset
default boolean hasOffset()- Returns:
trueif an offset is present,falseif not.
-
getInputStream
Description copied from interface:IHasInputStreamGet the input stream to read from the object. Each time this method is called, a newInputStreamneeds to be created.- Specified by:
getInputStreamin interfaceIHasInputStream- Returns:
nullif resolving failed.
-
isReadMultiple
default boolean isReadMultiple()Description copied from interface:IHasInputStreamCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.- Specified by:
isReadMultiplein interfaceIHasInputStream- Returns:
trueif the input stream can be acquired more than once,falseif not.
-
writeTo
Write the relevant part of the byte array onto the provided output stream.- Parameters:
aOS- The output stream to write to. May not benull.- Throws:
IOException- In case of a write error.
-
startsWith
Check if the passed byte array starts with the bytes of this object.- Parameters:
aCmpBytes- The bytes to compare to. May not benull.- Returns:
trueif the passed bytes start with the bytes in this object.
-
getHexEncoded
- Returns:
- The hex encoded version of this string. Never
nullbut maybe empty, if the underlying array length is empty.
-
getBytesAsString
- Parameters:
aCharset- The character set to use. May not benull.- Returns:
- The byte array converted to a String, honoring
getOffset()andIHasSize.size(). - Since:
- 10.1.3
-