- java.lang.Object
-
- java.io.InputStream
-
- org.snmp4j.asn1.BERInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class BERInputStream extends java.io.InputStream
TheBERInputStream
class wraps aByteBuffer
and implements theInputStream
abstract class. positions in the input stream.- Version:
- 1.6.1
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer
buffer
-
Constructor Summary
Constructors Constructor Description BERInputStream(java.nio.ByteBuffer buffer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.void
close()
Closes this input stream and releases any system resources associated with the stream.int
getAvailableBytes()
Gets the total number of bytes that can be read from this input stream.java.nio.ByteBuffer
getBuffer()
long
getPosition()
Gets the current position in the underlyingbuffer
.boolean
isMarked()
Checks whether a mark has been set on the input stream.void
mark(int readlimit)
Marks the current position in this input stream.boolean
markSupported()
Tests if this input stream supports themark
andreset
methods.int
read()
int
read(byte[] b)
Reads some number of bytes from the input stream and stores them into the buffer arrayb
.int
read(byte[] b, int off, int len)
Reads up tolen
bytes of data from the input stream into an array of bytes.void
reset()
Repositions this stream to the position at the time themark
method was last called on this input stream.void
setBuffer(java.nio.ByteBuffer buf)
long
skip(long n)
Skips over and discardsn
bytes of data from this input stream.
-
-
-
Method Detail
-
getBuffer
public java.nio.ByteBuffer getBuffer()
-
setBuffer
public void setBuffer(java.nio.ByteBuffer buf)
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.- Overrides:
available
in classjava.io.InputStream
- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
close
public void close() throws java.io.IOException
Closes this input stream and releases any system resources associated with the 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.
-
mark
public void mark(int readlimit)
Marks the current position in this input stream.- Overrides:
mark
in classjava.io.InputStream
- Parameters:
readlimit
- the maximum limit of bytes that can be read before the mark position becomes invalid.
-
markSupported
public boolean markSupported()
Tests if this input stream supports themark
andreset
methods.- Overrides:
markSupported
in classjava.io.InputStream
- Returns:
true
if this stream instance supports the mark and reset methods;false
otherwise.
-
read
public int read(byte[] b) throws java.io.IOException
Reads some number of bytes from the input stream and stores them into the buffer arrayb
.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1
is there is no more data because the end of the stream has been reached. - Throws:
java.io.IOException
- if an I/O error occurs.
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
Reads up tolen
bytes of data from the input stream into an array of bytes.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the buffer into which the data is read.off
- the start offset in arrayb
at which the data is written.len
- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached. - Throws:
java.io.IOException
- if an I/O error occurs.
-
reset
public void reset() throws java.io.IOException
Repositions this stream to the position at the time themark
method was last called on this input stream.- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
- if this stream has not been marked or if the mark has been invalidated.
-
skip
public long skip(long n) throws java.io.IOException
Skips over and discardsn
bytes of data from this input stream.- Overrides:
skip
in classjava.io.InputStream
- Parameters:
n
- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
getPosition
public long getPosition()
Gets the current position in the underlyingbuffer
.- Returns:
buffer.position()
.
-
isMarked
public boolean isMarked()
Checks whether a mark has been set on the input stream. This can be used to determine whether the value returned byavailable()
is limited by a readlimit set when the mark has been set.- Returns:
- always
true
. If no mark has been set explicitly, the mark is set to the initial position (i.e. zero).
-
getAvailableBytes
public int getAvailableBytes()
Gets the total number of bytes that can be read from this input stream.- Returns:
- the number of bytes that can be read from this stream.
-
-