1 package org.apache.lucene.facet.index;
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
6 import org.apache.lucene.util.encoding.IntEncoder;
9 * Licensed to the Apache Software Foundation (ASF) under one or more
10 * contributor license agreements. See the NOTICE file distributed with
11 * this work for additional information regarding copyright ownership.
12 * The ASF licenses this file to You under the Apache License, Version 2.0
13 * (the "License"); you may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
26 * Accumulates category IDs for a single document, for writing in byte array
27 * form, for example, to a Lucene Payload.
29 * @lucene.experimental
31 public class CategoryListPayloadStream {
33 private ByteArrayOutputStream baos = new ByteArrayOutputStream(50);
34 private IntEncoder encoder;
36 /** Creates a Payload stream using the specified encoder. */
37 public CategoryListPayloadStream(IntEncoder encoder) {
38 this.encoder = encoder;
39 this.encoder.reInit(baos);
42 /** Appends an integer to the stream. */
43 public void appendIntToStream(int intValue) throws IOException {
44 encoder.encode(intValue);
47 /** Returns the streamed bytes so far accumulated, as an array of bytes. */
48 public byte[] convertStreamToByteArray() {
51 return baos.toByteArray();
52 } catch (IOException e) {
53 // This cannot happen, because of BAOS (no I/O).
58 /** Resets this stream to begin building a new payload. */
59 public void reset() throws IOException {