- java.lang.Object
-
- java.io.OutputStream
-
- org.snmp4j.asn1.BEROutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class BEROutputStream extends java.io.OutputStream
TheBEROutputStream
class wraps aByteBuffer
to support BER encoding. The backing buffer can be accessed directly to optimize performance and memory usage.- Version:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description BEROutputStream()
Creates a BER output stream without a backing buffer set.BEROutputStream(java.nio.ByteBuffer buffer)
Create aBEROutputStream
that uses the supplied buffer as backing buffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
java.nio.ByteBuffer
getBuffer()
Gets the backing buffer.java.nio.ByteBuffer
rewind()
Rewinds backing buffer and returns it.void
setBuffer(java.nio.ByteBuffer buffer)
Sets the backing buffer to the supplied one and sets the offset used byrewind()
to the buffers current position.void
setFilledBuffer(java.nio.ByteBuffer buffer)
Sets the backing buffer and sets the current position of the stream to the buffers limit (end).void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Constructor Detail
-
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 aNullPointerException
will be thrown when calling one of thewrite
operations.
-
BEROutputStream
public BEROutputStream(java.nio.ByteBuffer buffer)
Create aBEROutputStream
that uses the supplied buffer as backing buffer.- Parameters:
buffer
- aByteBuffer
whose limit and capacity must be greater or equal that the length of the encoded BER stream.
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
rewind
public java.nio.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 java.nio.ByteBuffer getBuffer()
Gets the backing buffer.- Returns:
- the
ByteBuffer
backing this output stream.
-
setBuffer
public void setBuffer(java.nio.ByteBuffer buffer)
Sets the backing buffer to the supplied one and sets the offset used byrewind()
to the buffers current position.- Parameters:
buffer
- aByteBuffer
whose limit and capacity must be greater or equal that the length of the encoded BER stream.
-
setFilledBuffer
public void setFilledBuffer(java.nio.ByteBuffer buffer)
Sets the backing buffer and sets the current position of the stream to the buffers limit (end).- Parameters:
buffer
- aByteBuffer
whose limit and capacity must be greater or equal that the length of the encoded BER stream.
-
-