1
2
3 package org.galagosearch.core.index;
4
5 import java.io.File;
6 import java.io.FileNotFoundException;
7 import java.io.IOException;
8 import java.io.RandomAccessFile;
9 import java.nio.ByteBuffer;
10 import java.nio.channels.FileChannel;
11
12 /***
13 *
14 * @author trevor
15 */
16 public class DocumentLengthsReader {
17 RandomAccessFile file;
18 FileChannel channel;
19 ByteBuffer buffer;
20
21 public DocumentLengthsReader(String filename) throws FileNotFoundException, IOException {
22 file = new RandomAccessFile(new File(filename), "r");
23 channel = file.getChannel();
24 buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
25 }
26
27 public void close() throws IOException {
28 channel.close();
29 file.close();
30 }
31
32 public int getLength(int document) {
33 return buffer.getInt(document*4);
34 }
35 }