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-memoryIReadableResourcebased on a byte array.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_COPY_NEEDED
-
Constructor Summary
Constructors Constructor Description ReadableResourceByteArray(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]bytes()InputStreamgetInputStream()Get the input stream to read from the object.intgetOffset()booleanisCopy()booleanisEmpty()booleanisReadMultiple()Check if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.intsize()StringtoString()-
Methods inherited from class com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource
exists, getAsFile, getAsURL, getPath, getReadableCloneForPath, getResourceID
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.io.IHasByteArray
getAllBytes, getBytesAsString, getHexEncoded, hasOffset, isNotEmpty, startsWith, writeTo
-
Methods inherited from interface com.helger.commons.io.IHasInputStream
getBufferedInputStream
-
Methods inherited from interface com.helger.commons.io.IHasInputStreamAndReader
getBufferedReader, getReader
-
-
-
-
Field Detail
-
DEFAULT_COPY_NEEDED
public static final boolean DEFAULT_COPY_NEEDED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nonnull byte[] aBytes)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nonnull byte[] aBytes, boolean bCopyNeeded)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nullable String sResourceID, @Nonnull byte[] aBytes)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nullable String sResourceID, @Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nullable String sResourceID, @Nonnull byte[] aBytes, boolean bCopyNeeded)
-
ReadableResourceByteArray
public ReadableResourceByteArray(@Nullable String sResourceID, @Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded)
-
-
Method Detail
-
isCopy
public final boolean isCopy()
- Specified by:
isCopyin interfaceIHasByteArray- Returns:
trueif the contained byte array was copied in the constructor or not.
-
bytes
@Nonnull @ReturnsMutableObject public final byte[] 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
@Nonnegative public int 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:
IHasByteArray.bytes(),IHasSize.size()
-
size
@Nonnegative public final int 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:
IHasSize.size(),IHasSize.isNotEmpty()
-
getInputStream
@Nonnull public 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 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
public String toString()
- Overrides:
toStringin classAbstractMemoryReadableResource
-
-