Module org.snmp4j

Class BERInputStream

java.lang.Object
java.io.InputStream
org.snmp4j.asn1.BERInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class BERInputStream extends InputStream
The BERInputStream class wraps a ByteBuffer and implements the InputStream abstract class. positions in the input stream.
Version:
1.6.1
Author:
Frank Fock
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    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
    Closes this input stream and releases any system resources associated with the stream.
    int
    Gets the total number of bytes that can be read from this input stream.
     
    long
    Gets the current position in the underlying buffer.
    boolean
    Checks whether a mark has been set on the input stream.
    void
    mark(int readlimit)
    Marks the current position in this input stream.
    boolean
    Tests if this input stream supports the mark and reset methods.
    int
     
    int
    read(byte[] b)
    Reads some number of bytes from the input stream and stores them into the buffer array b.
    int
    read(byte[] b, int off, int len)
    Reads up to len bytes of data from the input stream into an array of bytes.
    void
    Repositions this stream to the position at the time the mark method was last called on this input stream.
    void
     
    long
    skip(long n)
    Skips over and discards n bytes of data from this input stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BERInputStream

      public BERInputStream(ByteBuffer buffer)
  • Method Details

    • getBuffer

      public ByteBuffer getBuffer()
    • setBuffer

      public void setBuffer(ByteBuffer buf)
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • available

      public int available() throws 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 class InputStream
      Returns:
      the number of bytes that can be read from this input stream without blocking.
      Throws:
      IOException - if an I/O error occurs.
    • close

      public void close() throws IOException
      Closes this input stream and releases any system resources associated with the stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - if an I/O error occurs.
    • mark

      public void mark(int readlimit)
      Marks the current position in this input stream.
      Overrides:
      mark in class 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 the mark and reset methods.
      Overrides:
      markSupported in class InputStream
      Returns:
      true if this stream instance supports the mark and reset methods; false otherwise.
    • read

      public int read(byte[] b) throws IOException
      Reads some number of bytes from the input stream and stores them into the buffer array b.
      Overrides:
      read in class 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:
      IOException - if an I/O error occurs.
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads up to len bytes of data from the input stream into an array of bytes.
      Overrides:
      read in class InputStream
      Parameters:
      b - the buffer into which the data is read.
      off - the start offset in array b 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:
      IOException - if an I/O error occurs.
    • reset

      public void reset() throws IOException
      Repositions this stream to the position at the time the mark method was last called on this input stream.
      Overrides:
      reset in class InputStream
      Throws:
      IOException - if this stream has not been marked or if the mark has been invalidated.
    • skip

      public long skip(long n) throws IOException
      Skips over and discards n bytes of data from this input stream.
      Overrides:
      skip in class InputStream
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped.
      Throws:
      IOException - if an I/O error occurs.
    • getPosition

      public long getPosition()
      Gets the current position in the underlying buffer.
      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 by available() 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.