Class ReadableResourceByteArray
java.lang.Object
com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource
com.helger.commons.io.resource.inmemory.ReadableResourceByteArray
- All Implemented Interfaces:
IHasByteArray,IHasInputStream,IHasInputStreamAndReader,IMemoryReadableResource,IReadableResource,IResourceBase,IHasSize
- Direct Known Subclasses:
ReadableResourceString
public class ReadableResourceByteArray
extends AbstractMemoryReadableResource
implements IHasByteArray
An in-memory
IReadableResource based on a byte array.- Author:
- Philip Helger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReadableResourceByteArray(byte[] aBytes) ReadableResourceByteArray(byte[] aBytes, boolean bCopyNeeded) ReadableResourceByteArray(byte[] aBytes, int nOfs, int nLen) ReadableResourceByteArray(byte[] aBytes, int nOfs, int nLen, boolean bCopyNeeded) ReadableResourceByteArray(String sResourceID, byte[] aBytes) ReadableResourceByteArray(String sResourceID, byte[] aBytes, boolean bCopyNeeded) ReadableResourceByteArray(String sResourceID, byte[] aBytes, int nOfs, int nLen) ReadableResourceByteArray(String sResourceID, byte[] aBytes, int nOfs, int nLen, boolean bCopyNeeded) -
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]bytes()Get the input stream to read from the object.intfinal booleanisCopy()booleanisEmpty()booleanCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.final intsize()toString()Methods inherited from class com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource
exists, getAsFile, getAsURL, getPath, getReadableCloneForPath, getResourceIDMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.commons.io.IHasByteArray
getAllBytes, getBytesAsString, getHexEncoded, hasOffset, isNotEmpty, isPartialArray, startsWith, writeToMethods inherited from interface com.helger.commons.io.IHasInputStream
getBufferedInputStream, withBufferedInputStreamDo, withInputStreamDoMethods inherited from interface com.helger.commons.io.IHasInputStreamAndReader
getBufferedReader, getReader
-
Field Details
-
DEFAULT_COPY_NEEDED
public static final boolean DEFAULT_COPY_NEEDED- See Also:
-
-
Constructor Details
-
ReadableResourceByteArray
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen) -
ReadableResourceByteArray
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded) -
ReadableResourceByteArray
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nullable String sResourceID, @Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen) -
ReadableResourceByteArray
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nullable String sResourceID, @Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded)
-
-
Method Details
-
isCopy
public final boolean isCopy()- Specified by:
isCopyin interfaceIHasByteArray- Returns:
trueif the contained byte array was copied in the constructor or not.
-
bytes
- Specified by:
bytesin interfaceIHasByteArray- Returns:
- A reference to the contained byte array. Gives write access to the
payload! Don't forget to apply
IHasByteArray.getOffset()andIHasSize.size(). Nevernull.
-
getOffset
- Specified by:
getOffsetin interfaceIHasByteArray- Returns:
- The offset into the byte array to start reading. This is always 0 when copied. Must be ge; 0.
- See Also:
-
size
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceIHasByteArray- Specified by:
isEmptyin interfaceIHasSize- Returns:
trueif no items are present,falseif at least a single item is present.- See Also:
-
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 interfaceIHasByteArray- Specified by:
getInputStreamin interfaceIHasInputStream- Returns:
nullif resolving failed.
-
isReadMultiple
public boolean isReadMultiple()Description copied from interface:IHasInputStreamCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.- Specified by:
isReadMultiplein interfaceIHasByteArray- Specified by:
isReadMultiplein interfaceIHasInputStream- Returns:
trueif the input stream can be acquired more than once,falseif not.
-
toString
- Overrides:
toStringin classAbstractMemoryReadableResource
-