annotate src/goodjava/lucene/logging/LogOutputStream.java @ 1602:55d7b60c074d

add DirHandler to WebHandler
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 09 Apr 2021 23:46:12 -0600
parents 117ce8645b7f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.lucene.logging;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
1481
3cff066f3bbc output buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1480
diff changeset
3 import java.io.OutputStream;
1557
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
4 import goodjava.io.DataOutputStream;
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import java.io.RandomAccessFile;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import java.io.IOException;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 import java.util.List;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 import java.util.Map;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 import org.apache.lucene.index.Term;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 import org.apache.lucene.search.Query;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 import org.apache.lucene.search.MatchAllDocsQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 import org.apache.lucene.search.TermQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 import org.apache.lucene.search.PrefixQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 import org.apache.lucene.search.WildcardQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 import org.apache.lucene.search.TermRangeQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 import org.apache.lucene.search.PhraseQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 import org.apache.lucene.search.NumericRangeQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 import org.apache.lucene.search.BooleanQuery;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 import org.apache.lucene.search.BooleanClause;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 import org.apache.lucene.util.BytesRef;
1465
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
21 import goodjava.logging.Logger;
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
22 import goodjava.logging.LoggerFactory;
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
25 public class LogOutputStream extends DataOutputStream {
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
26 private static final Logger logger = LoggerFactory.getLogger(LogOutputStream.class);
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
27 public final LogFile logFile;
1476
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
28 private final RandomAccessFile raf;
1484
1fa6e8ec2d53 lucene.logging cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1481
diff changeset
29
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
30 protected LogOutputStream(LogFile logFile,RandomAccessFile raf,OutputStream out) throws IOException {
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
31 super(out);
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
32 this.logFile = logFile;
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
33 this.raf = raf;
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
34 raf.seek(logFile.end);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 public void commit() throws IOException {
1484
1fa6e8ec2d53 lucene.logging cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1481
diff changeset
38 flush();
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
39 long end = raf.getFilePointer();
1476
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
40 raf.seek(0L);
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
41 raf.writeLong(end);
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
42 logFile.end = end;
1481
3cff066f3bbc output buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1480
diff changeset
43 raf.seek(end);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45
1476
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
46 public void rollback() throws IOException {
1484
1fa6e8ec2d53 lucene.logging cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1481
diff changeset
47 flush();
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
48 raf.seek(logFile.end);
1476
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
49 }
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
50
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 public void writeObject(Object obj) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 if( obj==null ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
53 writeByte(LogFile.TYPE_NULL);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 if( obj instanceof String ) {
1557
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
57 String s = (String)obj;
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
58 if( s.length() <= 65535 ) {
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
59 writeByte(LogFile.TYPE_STRING);
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
60 writeUTF(s);
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
61 } else {
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
62 writeByte(LogFile.TYPE_LONG_STRING);
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
63 writeString(s);
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
64 }
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 if( obj instanceof Integer ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
68 writeByte(LogFile.TYPE_INT);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 writeInt((Integer)obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 if( obj instanceof Long ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
73 writeByte(LogFile.TYPE_LONG);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 writeLong((Long)obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 if( obj instanceof Float ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
78 writeByte(LogFile.TYPE_FLOAT);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 writeFloat((Float)obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 if( obj instanceof Double ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
83 writeByte(LogFile.TYPE_DOUBLE);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 writeDouble((Double)obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 if( obj instanceof byte[] ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
88 writeByte(LogFile.TYPE_BYTES);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 writeByteArray((byte[])obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 if( obj instanceof List ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
93 writeByte(LogFile.TYPE_LIST);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 writeList((List)obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 if( obj instanceof MatchAllDocsQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
98 writeByte(LogFile.TYPE_QUERY_MATCH_ALL_DOCS);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 if( obj instanceof TermQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
102 writeByte(LogFile.TYPE_QUERY_TERM);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 TermQuery query = (TermQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 writeTerm( query.getTerm() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 if( obj instanceof PrefixQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
108 writeByte(LogFile.TYPE_QUERY_PREFIX);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 PrefixQuery query = (PrefixQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 writeTerm( query.getPrefix() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 if( obj instanceof WildcardQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
114 writeByte(LogFile.TYPE_QUERY_TERM_RANGE);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 WildcardQuery query = (WildcardQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 writeTerm( query.getTerm() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 if( obj instanceof TermRangeQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
120 writeByte(LogFile.TYPE_QUERY_TERM_RANGE);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 TermRangeQuery query = (TermRangeQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 writeUTF( query.getField() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 writeBytesRef( query.getLowerTerm() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 writeBytesRef( query.getUpperTerm() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 writeBoolean( query.includesLower() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 writeBoolean( query.includesUpper() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 if( obj instanceof PhraseQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
130 writeByte(LogFile.TYPE_QUERY_PHRASE);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 PhraseQuery query = (PhraseQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 Term[] terms = query.getTerms();
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 int[] positions = query.getPositions();
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 if( terms.length != positions.length )
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 throw new RuntimeException();
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 writeInt( terms.length );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 for( int i=0; i<terms.length; i++ ) {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138 writeTerm( terms[i] );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 writeInt( positions[i] );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 if( obj instanceof NumericRangeQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
144 writeByte(LogFile.TYPE_QUERY_NUMERIC_RANGE);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 NumericRangeQuery query = (NumericRangeQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 writeUTF( query.getField() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 writeObject( query.getMin() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 writeObject( query.getMax() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 writeBoolean( query.includesMin() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 writeBoolean( query.includesMax() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 if( obj instanceof BooleanQuery ) {
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
154 writeByte(LogFile.TYPE_QUERY_BOOLEAN);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 BooleanQuery query = (BooleanQuery)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 BooleanClause[] a = query.getClauses();
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 writeInt(a.length);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 for( BooleanClause bc : a ) {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 writeQuery( bc.getQuery() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 writeUTF( bc.getOccur().name() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 return;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 throw new IllegalArgumentException("invalid type for "+obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 public void writeByteArray(byte[] bytes) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 writeInt(bytes.length);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 write(bytes);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 public void writeList(List list) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 writeInt(list.size());
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 for( Object obj : list ) {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 writeObject(obj);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 public void writeMap(Map map) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 writeInt(map.size());
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 for( Object obj : map.entrySet() ) {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 Map.Entry entry = (Map.Entry)obj;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 writeObject( entry.getKey() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 writeObject( entry.getValue() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 public void writeQuery(Query query) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189 writeObject(query);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192 public void writeBytesRef(BytesRef br) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193 writeInt(br.length);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 write(br.bytes,0,br.length);
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 public void writeTerm(Term term) throws IOException {
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198 writeUTF(term.field());
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 writeBytesRef( term.bytes() );
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202 }