KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > analysis > KeywordTokenizer


1 package org.apache.lucene.analysis;
2
3 /**
4  * Copyright 2004-2005 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.IOException JavaDoc;
20 import java.io.Reader JavaDoc;
21
22 /**
23  * Emits the entire input as a single token.
24  */

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 JavaDoc input) {
33     this(input, DEFAULT_BUFFER_SIZE);
34   }
35
36   public KeywordTokenizer(Reader JavaDoc input, int bufferSize) {
37     super(input);
38     this.buffer = new char[bufferSize];
39     this.done = false;
40   }
41
42   public Token next() throws IOException JavaDoc {
43     if (!done) {
44       done = true;
45       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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 JavaDoc text = buffer.toString();
54       return new Token(text, 0, text.length());
55     }
56     return null;
57   }
58 }
59
Popular Tags