Package org.apache.xml.security.utils
Class UnsyncByteArrayInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.xml.security.utils.UnsyncByteArrayInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class UnsyncByteArrayInputStream extends java.io.InputStream
A specializedInputStream
for reading the contents of a byte array.- See Also:
UnsyncByteArrayOutputStream
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buf
Thebyte
array containing the bytes to stream over.protected int
count
The total number of bytes initially available in the byte arraybuf
.protected int
mark
The current mark position.protected int
pos
The current position within the byte array.
-
Constructor Summary
Constructors Constructor Description UnsyncByteArrayInputStream(byte[] buf)
Constructs a newByteArrayInputStream
on the byte arraybuf
.UnsyncByteArrayInputStream(byte[] buf, int offset, int length)
Constructs a newByteArrayInputStream
on the byte arraybuf
with the initial position set tooffset
and the number of bytes available set tooffset
+length
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns the number of bytes that are available before this stream will block.void
close()
Closes this stream and frees resources associated with this stream.void
mark(int readlimit)
Sets a mark position in this ByteArrayInputStream.boolean
markSupported()
Indicates whether this stream supports themark()
andreset()
methods.int
read()
Reads a single byte from the source byte array and returns it as an integer in the range from 0 to 255.int
read(byte[] b, int offset, int length)
Reads at mostlen
bytes from this stream and stores them in byte arrayb
starting atoffset
.void
reset()
Resets this stream to the last marked location.long
skip(long n)
Skipscount
number of bytes in this InputStream.
-
-
-
Field Detail
-
buf
protected byte[] buf
Thebyte
array containing the bytes to stream over.
-
pos
protected int pos
The current position within the byte array.
-
mark
protected int mark
The current mark position. Initially set to 0 or theoffset
parameter within the constructor.
-
count
protected int count
The total number of bytes initially available in the byte arraybuf
.
-
-
Constructor Detail
-
UnsyncByteArrayInputStream
public UnsyncByteArrayInputStream(byte[] buf)
Constructs a newByteArrayInputStream
on the byte arraybuf
.- Parameters:
buf
- the byte array to stream over.
-
UnsyncByteArrayInputStream
public UnsyncByteArrayInputStream(byte[] buf, int offset, int length)
Constructs a newByteArrayInputStream
on the byte arraybuf
with the initial position set tooffset
and the number of bytes available set tooffset
+length
.- Parameters:
buf
- the byte array to stream over.offset
- the initial position inbuf
to start streaming from.length
- the number of bytes available for streaming.
-
-
Method Detail
-
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:
available
in classjava.io.InputStream
- Returns:
- the number of bytes available before blocking.
-
close
public void close() throws java.io.IOException
Closes this stream and frees resources associated with this stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.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 parameterreadlimit
is ignored. Sendingreset()
will reposition the stream back to the marked position.- Overrides:
mark
in classjava.io.InputStream
- Parameters:
readlimit
- ignored.- See Also:
markSupported()
,reset()
-
markSupported
public boolean markSupported()
Indicates whether this stream supports themark()
andreset()
methods. Returnstrue
since this class supports these methods.
-
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:
read
in classjava.io.InputStream
- 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 mostlen
bytes from this stream and stores them in byte arrayb
starting atoffset
. This implementation reads bytes from the source byte array.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the byte array in which to store the bytes read.offset
- the initial position inb
to 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:
java.lang.IndexOutOfBoundsException
- ifoffset < 0
orlength < 0
, or ifoffset + length
is greater than the size ofb
.java.lang.NullPointerException
- ifb
isnull
.
-
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:
reset
in classjava.io.InputStream
- See Also:
mark(int)
-
skip
public long skip(long n)
Skipscount
number of bytes in this InputStream. Subsequentread()
s will not return these bytes unlessreset()
is used. This implementation skipscount
number of bytes in the target stream. It does nothing and returns 0 ifn
is negative.- Overrides:
skip
in classjava.io.InputStream
- Parameters:
n
- the number of bytes to skip.- Returns:
- the number of bytes actually skipped.
-
-