add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / store / ByteArrayDataOutput.java
1 package org.apache.lucene.store;
2
3 import org.apache.lucene.util.BytesRef;
4
5 /**
6  * @lucene.experimental
7  */
8 public class ByteArrayDataOutput extends DataOutput {
9   private byte[] bytes;
10
11   private int pos;
12   private int limit;
13
14   public ByteArrayDataOutput(byte[] bytes) {
15     reset(bytes);
16   }
17
18   public ByteArrayDataOutput(byte[] bytes, int offset, int len) {
19     reset(bytes, offset, len);
20   }
21
22   public ByteArrayDataOutput() {
23     reset(BytesRef.EMPTY_BYTES);
24   }
25
26   public void reset(byte[] bytes) {
27     reset(bytes, 0, bytes.length);
28   }
29   
30   public void reset(byte[] bytes, int offset, int len) {
31     this.bytes = bytes;
32     pos = offset;
33     limit = offset + len;
34   }
35   
36   public int getPosition() {
37     return pos;
38   }
39
40   @Override
41   public void writeByte(byte b) {
42     assert pos < limit;
43     bytes[pos++] = b;
44   }
45
46   @Override
47   public void writeBytes(byte[] b, int offset, int length) {
48     assert pos + length <= limit;
49     System.arraycopy(b, offset, bytes, pos, length);
50     pos += length;
51   }
52 }