View Javadoc

1   // BSD License (http://www.galagosearch.org/license)
2   
3   package org.galagosearch.core.index;
4   
5   import java.io.BufferedOutputStream;
6   import java.io.ByteArrayOutputStream;
7   import java.io.DataOutputStream;
8   import java.io.IOException;
9   
10  /***
11   *
12   * @author trevor
13   */
14  public class VocabularyWriter {
15      DataOutputStream output;
16      ByteArrayOutputStream buffer;
17  
18      public VocabularyWriter() throws IOException {
19          buffer = new ByteArrayOutputStream();
20          output = new DataOutputStream(new BufferedOutputStream(buffer));
21      }
22  
23      public void add(byte[] word, long offset) throws IOException {
24          output.writeShort(word.length);
25          output.write(word);
26          output.writeLong(offset);
27      }
28  
29      public byte[] data() throws IOException {
30          output.close();
31          return buffer.toByteArray();
32      }
33  }
34