Package com.helger.commons.io
Interface IHasByteArray
-
- All Superinterfaces:
IHasInputStream,IHasInputStreamAndReader,IHasSize
- All Known Implementing Classes:
ByteArrayInputStreamProvider,ByteArrayWrapper,ReadableResourceByteArray,ReadableResourceString
public interface IHasByteArray extends IHasSize, IHasInputStreamAndReader
Base interface for all objects owning a byte array.- Since:
- 9.1.3
- Author:
- Philip Helger
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description byte[]bytes()default byte[]getAllBytes()default StringgetBytesAsString(Charset aCharset)default StringgetHexEncoded()default InputStreamgetInputStream()Get the input stream to read from the object.intgetOffset()default booleanhasOffset()booleanisCopy()default booleanisEmpty()default booleanisNotEmpty()default booleanisReadMultiple()Check 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
-
Methods inherited from interface com.helger.commons.io.IHasInputStreamAndReader
getBufferedReader, getReader
-
-
-
-
Method Detail
-
isEmpty
default boolean isEmpty()
- Specified by:
isEmptyin interfaceIHasSize- Returns:
trueif no items are present,falseif at least a single item is present.- See Also:
IHasSize.size(),IHasSize.isNotEmpty()
-
isNotEmpty
default boolean isNotEmpty()
- Specified by:
isNotEmptyin interfaceIHasSize- Returns:
trueif at least one item is present,falseif no item is present.- See Also:
IHasSize.size(),IHasSize.isEmpty()
-
isCopy
boolean isCopy()
- Returns:
trueif the contained byte array was copied in the constructor or not.
-
getAllBytes
@Nonnull @ReturnsMutableCopy default byte[] getAllBytes()
- Returns:
- A copy of all bytes contained, from
getOffset()forIHasSize.size()bytes. Nevernull.
-
bytes
@Nonnull @ReturnsMutableObject byte[] bytes()
- Returns:
- A reference to the contained byte array. Gives write access to the
payload! Don't forget to apply
getOffset()andIHasSize.size(). Nevernull.
-
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:
bytes(),IHasSize.size()
-
hasOffset
default boolean hasOffset()
- Returns:
trueif an offset is present,falseif not.
-
getInputStream
@Nonnull default InputStream 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
default void writeTo(@Nonnull @WillNotClose OutputStream aOS) throws IOException
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
default boolean startsWith(@Nonnull byte[] 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
@Nonnull default String getHexEncoded()
- Returns:
- The hex encoded version of this string. Never
nullbut maybe empty, if the underlying array length is empty.
-
getBytesAsString
@Nonnull default String getBytesAsString(@Nonnull Charset aCharset)
- Parameters:
aCharset- The character set to use. May not benull.- Returns:
- The byte array converted to a String, honouring
getOffset()andIHasSize.size(). - Since:
- 10.1.3
-
-