1 20 21 22 23 24 package org.snmp4j.asn1; 25 26 import java.io.*; 27 import java.nio.ByteBuffer ; 28 29 30 38 public class BEROutputStream extends OutputStream { 39 40 private ByteBuffer buffer; 41 private int offset = 0; 42 43 50 public BEROutputStream() { 51 this.buffer = null; 52 } 53 54 61 public BEROutputStream(ByteBuffer buffer) { 62 this.buffer = buffer; 63 this.offset = buffer.position(); 64 } 65 66 public void write(int b) throws java.io.IOException { 67 buffer.put((byte)b); 68 } 69 70 public void write(byte[] b) throws IOException { 71 buffer.put(b); 72 } 73 74 public void write(byte[] b, int off, int len) throws IOException { 75 buffer.put(b, off, len); 76 } 77 78 public void close() throws IOException { 79 } 80 81 public void flush() throws IOException { 82 } 83 84 93 public ByteBuffer rewind() { 94 return (ByteBuffer ) buffer.position(offset); 95 } 96 97 102 public ByteBuffer getBuffer() { 103 return buffer; 104 } 105 106 113 public void setBuffer(ByteBuffer buffer) { 114 this.buffer = buffer; 115 this.offset = buffer.position(); 116 } 117 118 125 public void setFilledBuffer(ByteBuffer buffer) { 126 this.buffer = buffer; 127 this.offset = buffer.position(); 128 buffer.position(buffer.limit()); 129 } 130 131 } 132 | Popular Tags |