package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.BufferedIndexInput; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.Lock; import java.util.HashMap; import java.io.IOException; /** * Class for accessing a compound stream. * This class implements a directory, but is limited to only read operations. * Directory methods that would normally modify data throw an exception. * * @author Dmitry Serebrennikov * @version $Id: CompoundFileReader.java 472959 2006-11-09 16:21:50Z yonik $ */ class CompoundFileReader extends Directory { private static final class FileEntry { long offset; long length; } // Base info private Directory directory; private String fileName; private IndexInput stream; private HashMap entries = new HashMap(); public CompoundFileReader(Directory dir, String name) throws IOException { directory = dir; fileName = name; boolean success = false; try { stream = dir.openInput(name); // read the directory and init files int count = stream.readVInt(); FileEntry entry = null; for (int i=0; i length) throw new IOException("read past EOF"); base.seek(fileOffset + start); base.readBytes(b, offset, len); } } /** Expert: implements seek. Sets current position in this file, where * the next {@link #readInternal(byte[],int,int)} will occur. * @see #readInternal(byte[],int,int) */ protected void seekInternal(long pos) {} /** Closes the stream to further operations. */ public void close() {} public long length() { return length; } } }