pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / java / org / apache / lucene / util / encoding / SimpleIntEncoder.java
1 package org.apache.lucene.util.encoding;
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  * A simple {@link IntEncoder}, writing an integer as 4 raw bytes. *
24  * 
25  * @lucene.experimental
26  */
27 public class SimpleIntEncoder extends IntEncoder {
28
29   /**
30    * This method makes sure the value wasn't previously encoded by checking
31    * against the Set. If the value wasn't encoded, it's added to the Set, and
32    * encoded with {#link Vint8#encode}
33    * 
34    * @param value
35    *            an integer to be encoded
36    * @throws IOException
37    *             possibly thrown by the OutputStream
38    */
39   @Override
40   public void encode(int value) throws IOException {
41     out.write(value >>> 24);
42     out.write((value >> 16) & 0xFF);
43     out.write((value >> 8) & 0xFF);
44     out.write(value & 0xFF);
45   }
46
47   @Override
48   public IntDecoder createMatchingDecoder() {
49     return new SimpleIntDecoder();
50   }
51
52   @Override
53   public String toString() {
54     return "Simple";
55   }
56
57 }