1 package org.apache.lucene.analysis; 2 3 18 19 import java.io.IOException ; 20 import java.io.Reader ; 21 22 25 public class KeywordTokenizer extends Tokenizer { 26 27 private static final int DEFAULT_BUFFER_SIZE = 256; 28 29 private boolean done; 30 private final char[] buffer; 31 32 public KeywordTokenizer(Reader input) { 33 this(input, DEFAULT_BUFFER_SIZE); 34 } 35 36 public KeywordTokenizer(Reader input, int bufferSize) { 37 super(input); 38 this.buffer = new char[bufferSize]; 39 this.done = false; 40 } 41 42 public Token next() throws IOException { 43 if (!done) { 44 done = true; 45 StringBuffer buffer = new StringBuffer (); 46 int length; 47 while (true) { 48 length = input.read(this.buffer); 49 if (length == -1) break; 50 51 buffer.append(this.buffer, 0, length); 52 } 53 String text = buffer.toString(); 54 return new Token(text, 0, text.length()); 55 } 56 return null; 57 } 58 } 59 | Popular Tags |