Package com.helger.base.io.iface
Interface IHasByteArray
- All Superinterfaces:
IHasInputStream,IHasInputStreamAndReader,IHasSize,IWriteToStream
- All Known Implementing Classes:
ByteArrayInputStreamProvider,ByteArrayWrapper
Base interface for all objects owning a byte array.
- Since:
- 9.1.3
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionbyte @NonNull []bytes()default byte @NonNull []default @NonNull StringgetBytesAsString(@NonNull Charset aCharset) default @NonNull Stringdefault @NonNull 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 @NonNull [] aCmpBytes) Check if the passed byte array starts with the bytes of this object.default voidwriteTo(@NonNull OutputStream aOS) Write the relevant part of the byte array onto the provided output stream.Methods inherited from interface com.helger.base.io.iface.IHasInputStream
getBufferedInputStream, withBufferedInputStreamDo, withInputStreamDoMethods inherited from interface com.helger.base.io.iface.IHasInputStreamAndReader
getBufferedReader, getReaderMethods inherited from interface com.helger.base.io.iface.IWriteToStream
writeToAndClose
-
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
@ReturnsMutableCopy default byte @NonNull [] getAllBytes()- Returns:
- A copy of all bytes contained, from
getOffset()forIHasSize.size()bytes. Nevernull.
-
bytes
@ReturnsMutableObject byte @NonNull [] 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
@Nonnegative int 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
Get 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()Check 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.- Specified by:
writeToin interfaceIWriteToStream- Parameters:
aOS- The output stream to write to. May not benull.- Throws:
IOException- In case of a write error.
-
startsWith
default boolean startsWith(byte @NonNull [] aCmpBytes) 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
-