| 1 | |
|
| 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 | |
|
| 13 | |
|
| 14 | |
public class VocabularyWriter { |
| 15 | |
DataOutputStream output; |
| 16 | |
ByteArrayOutputStream buffer; |
| 17 | |
|
| 18 | 92 | public VocabularyWriter() throws IOException { |
| 19 | 92 | buffer = new ByteArrayOutputStream(); |
| 20 | 92 | output = new DataOutputStream(new BufferedOutputStream(buffer)); |
| 21 | 92 | } |
| 22 | |
|
| 23 | |
public void add(byte[] word, long offset) throws IOException { |
| 24 | 4088 | output.writeShort(word.length); |
| 25 | 4088 | output.write(word); |
| 26 | 4088 | output.writeLong(offset); |
| 27 | 4088 | } |
| 28 | |
|
| 29 | |
public byte[] data() throws IOException { |
| 30 | 92 | output.close(); |
| 31 | 92 | return buffer.toByteArray(); |
| 32 | |
} |
| 33 | |
} |
| 34 | |
|