01: package it.unimi.dsi.mg4j.index;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2004-2007 Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import it.unimi.dsi.fastutil.ints.IntList;
25: import it.unimi.dsi.fastutil.longs.LongList;
26: import it.unimi.dsi.mg4j.index.CompressionFlags.Coding;
27: import it.unimi.dsi.mg4j.index.payload.Payload;
28: import it.unimi.dsi.io.InputBitStream;
29: import it.unimi.dsi.util.Properties;
30: import it.unimi.dsi.util.StringMap;
31: import it.unimi.dsi.util.PrefixMap;
32:
33: import java.io.File;
34: import java.io.FileInputStream;
35: import java.io.FileNotFoundException;
36:
37: /** A file-based index.
38: *
39: * <P>An instance of this class stores additional index data for indices
40: * based on files: for instance, basename, compression flags, etc.
41: *
42: * @author Paolo Boldi
43: * @author Sebastiano Vigna
44: * @since 0.9
45: */
46:
47: public class FileIndex extends BitStreamIndex {
48: private static final long serialVersionUID = 0;
49:
50: /** The basename of this index. All file names will be stemmed from the basename. It may
51: * be <code>null</code>. */
52: public final String basename;
53: /** The file containing the index. It may be <code>null</code>. */
54: public final File indexFile;
55:
56: public FileIndex(final String basename,
57: final int numberOfDocuments, final int numberOfTerms,
58: final long numberOfPostings,
59: final long numberOfOccurrences, final int maxCount,
60: final Payload payload, final Coding frequencyCoding,
61: final Coding pointerCoding, final Coding countCoding,
62: final Coding positionCoding, final int quantum,
63: final int height, final int bufferSize,
64: final TermProcessor termProcessor, final String field,
65: final Properties properties,
66: final StringMap<? extends CharSequence> termMap,
67: final PrefixMap<? extends CharSequence> prefixMap,
68: final IntList sizes, final LongList offsets) {
69: super (numberOfDocuments, numberOfTerms, numberOfPostings,
70: numberOfOccurrences, maxCount, payload,
71: frequencyCoding, pointerCoding, countCoding,
72: positionCoding, quantum, height, bufferSize,
73: termProcessor, field, properties, termMap, prefixMap,
74: sizes, offsets);
75: this .basename = basename;
76: this .indexFile = new File(basename
77: + DiskBasedIndex.INDEX_EXTENSION);
78: }
79:
80: public String toString() {
81: return this .getClass().getSimpleName() + "(" + basename + ")";
82: }
83:
84: @Override
85: public FileInputStream getInputStream()
86: throws FileNotFoundException {
87: return new FileInputStream(indexFile);
88: }
89:
90: @Override
91: public InputBitStream getInputBitStream(final int bufferSize)
92: throws FileNotFoundException {
93: return new InputBitStream(indexFile, bufferSize);
94: }
95: }
|