Module org.snmp4j

Class BEROutputStream

java.lang.Object
java.io.OutputStream
org.snmp4j.asn1.BEROutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BEROutputStream extends OutputStream
The BEROutputStream class wraps a ByteBuffer to support BER encoding. The backing buffer can be accessed directly to optimize performance and memory usage.
Version:
1.0
Author:
Frank Fock
  • Constructor Details

    • BEROutputStream

      public BEROutputStream()
      Creates a BER output stream without a backing buffer set. In order to be able to write anything to the stream, setBuffer(ByteBuffer buffer) has to be called before. Otherwise a NullPointerException will be thrown when calling one of the write operations.
    • BEROutputStream

      public BEROutputStream(ByteBuffer buffer)
      Create a BEROutputStream that uses the supplied buffer as backing buffer.
      Parameters:
      buffer - a ByteBuffer whose limit and capacity must be greater or equal that the length of the encoded BER stream.
  • Method Details

    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • rewind

      public ByteBuffer rewind()
      Rewinds backing buffer and returns it. In contrast to the backing buffer's rewind method, this method sets the position of the buffer to the first byte of this output stream rather than to the first byte of the underlying byte array!
      Returns:
      the ByteBuffer backing this output stream with its current position set to the begin of the output stream.
    • getBuffer

      public ByteBuffer getBuffer()
      Gets the backing buffer.
      Returns:
      the ByteBuffer backing this output stream.
    • setBuffer

      public void setBuffer(ByteBuffer buffer)
      Sets the backing buffer to the supplied one and sets the offset used by rewind() to the buffers current position.
      Parameters:
      buffer - a ByteBuffer whose limit and capacity must be greater or equal that the length of the encoded BER stream.
    • setFilledBuffer

      public void setFilledBuffer(ByteBuffer buffer)
      Sets the backing buffer and sets the current position of the stream to the buffers limit (end).
      Parameters:
      buffer - a ByteBuffer whose limit and capacity must be greater or equal that the length of the encoded BER stream.