add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / java / org / apache / lucene / benchmark / byTask / feeds / SingleDocSource.java
1 package org.apache.lucene.benchmark.byTask.feeds;
2
3 import java.io.IOException;
4
5 /**
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 /**
23  * Creates the same document each time {@link #getNextDocData(DocData)} is called.
24  */
25 public class SingleDocSource extends ContentSource {
26   
27   private int docID = 0;
28
29   static final String DOC_TEXT =  
30     "Well, this is just some plain text we use for creating the " +
31     "test documents. It used to be a text from an online collection " +
32     "devoted to first aid, but if there was there an (online) lawyers " +
33     "first aid collection with legal advices, \"it\" might have quite " +
34     "probably advised one not to include \"it\"'s text or the text of " +
35     "any other online collection in one's code, unless one has money " +
36     "that one don't need and one is happy to donate for lawyers " +
37     "charity. Anyhow at some point, rechecking the usage of this text, " +
38     "it became uncertain that this text is free to use, because " +
39     "the web site in the disclaimer of he eBook containing that text " +
40     "was not responding anymore, and at the same time, in projGut, " +
41     "searching for first aid no longer found that eBook as well. " +
42     "So here we are, with a perhaps much less interesting " +
43     "text for the test, but oh much much safer. ";
44   
45   // return a new docid
46   private synchronized int newdocid() throws NoMoreDataException {
47     if (docID > 0 && !forever) {
48       throw new NoMoreDataException();
49     }
50     return docID++;
51   }
52
53   @Override
54   public void close() throws IOException {}
55   
56   @Override
57   public DocData getNextDocData(DocData docData) throws NoMoreDataException {
58     int id = newdocid();
59     addBytes(DOC_TEXT.length());
60     docData.clear();
61     docData.setName("doc" + id);
62     docData.setBody(DOC_TEXT);
63     return docData;
64   }
65
66   @Override
67   public synchronized void resetInputs() throws IOException {
68     super.resetInputs();
69     docID = 0;
70   }
71
72 }