Package org.apache.xml.security.utils
Class UnsyncByteArrayInputStream
java.lang.Object
java.io.InputStream
org.apache.xml.security.utils.UnsyncByteArrayInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A specialized
InputStream for reading the contents of a byte array.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]Thebytearray containing the bytes to stream over.protected intThe total number of bytes initially available in the byte arraybuf.protected intThe current mark position.protected intThe current position within the byte array. -
Constructor Summary
ConstructorsConstructorDescriptionUnsyncByteArrayInputStream(byte[] buf) Constructs a newByteArrayInputStreamon the byte arraybuf.UnsyncByteArrayInputStream(byte[] buf, int offset, int length) Constructs a newByteArrayInputStreamon the byte arraybufwith the initial position set tooffsetand the number of bytes available set tooffset+length. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bytes that are available before this stream will block.voidclose()Closes this stream and frees resources associated with this stream.voidmark(int readlimit) Sets a mark position in this ByteArrayInputStream.booleanIndicates whether this stream supports themark()andreset()methods.intread()Reads a single byte from the source byte array and returns it as an integer in the range from 0 to 255.intread(byte[] b, int offset, int length) Reads at mostlenbytes from this stream and stores them in byte arraybstarting atoffset.voidreset()Resets this stream to the last marked location.longskip(long n) Skipscountnumber of bytes in this InputStream.Methods inherited from class java.io.InputStream
read
-
Field Details
-
buf
protected byte[] bufThebytearray containing the bytes to stream over. -
pos
protected int posThe current position within the byte array. -
mark
protected int markThe current mark position. Initially set to 0 or theoffsetparameter within the constructor. -
count
protected int countThe total number of bytes initially available in the byte arraybuf.
-
-
Constructor Details
-
UnsyncByteArrayInputStream
public UnsyncByteArrayInputStream(byte[] buf) Constructs a newByteArrayInputStreamon the byte arraybuf.- Parameters:
buf- the byte array to stream over.
-
UnsyncByteArrayInputStream
public UnsyncByteArrayInputStream(byte[] buf, int offset, int length) Constructs a newByteArrayInputStreamon the byte arraybufwith the initial position set tooffsetand the number of bytes available set tooffset+length.- Parameters:
buf- the byte array to stream over.offset- the initial position inbufto start streaming from.length- the number of bytes available for streaming.
-
-
Method Details
-
available
public int available()Returns the number of bytes that are available before this stream will block. This method returns the number of bytes yet to be read from the source byte array.- Overrides:
availablein classInputStream- Returns:
- the number of bytes available before blocking.
-
close
Closes this stream and frees resources associated with this stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if an I/O error occurs while closing this stream.
-
mark
public void mark(int readlimit) Sets a mark position in this ByteArrayInputStream. The parameterreadlimitis ignored. Sendingreset()will reposition the stream back to the marked position.- Overrides:
markin classInputStream- Parameters:
readlimit- ignored.- See Also:
-
markSupported
public boolean markSupported()Indicates whether this stream supports themark()andreset()methods. Returnstruesince this class supports these methods.- Overrides:
markSupportedin classInputStream- Returns:
- always
true. - See Also:
-
read
public int read()Reads a single byte from the source byte array and returns it as an integer in the range from 0 to 255. Returns -1 if the end of the source array has been reached.- Specified by:
readin classInputStream- Returns:
- the byte read or -1 if the end of this stream has been reached.
-
read
public int read(byte[] b, int offset, int length) Reads at mostlenbytes from this stream and stores them in byte arraybstarting atoffset. This implementation reads bytes from the source byte array.- Overrides:
readin classInputStream- Parameters:
b- the byte array in which to store the bytes read.offset- the initial position inbto store the bytes read from this stream.length- the maximum number of bytes to store inb.- Returns:
- the number of bytes actually read or -1 if no bytes were read and the end of the stream was encountered.
- Throws:
IndexOutOfBoundsException- ifoffset < 0orlength < 0, or ifoffset + lengthis greater than the size ofb.NullPointerException- ifbisnull.
-
reset
public void reset()Resets this stream to the last marked location. This implementation resets the position to either the marked position, the start position supplied in the constructor or 0 if neither has been provided.- Overrides:
resetin classInputStream- See Also:
-
skip
public long skip(long n) Skipscountnumber of bytes in this InputStream. Subsequentread()s will not return these bytes unlessreset()is used. This implementation skipscountnumber of bytes in the target stream. It does nothing and returns 0 ifnis negative.- Overrides:
skipin classInputStream- Parameters:
n- the number of bytes to skip.- Returns:
- the number of bytes actually skipped.
-