Coverage Report - org.galagosearch.core.index.VocabularyWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
VocabularyWriter
100%
10/10
N/A
1
 
 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  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