Class IndexInput
- java.lang.Object
-
- org.apache.lucene.store.DataInput
-
- org.apache.lucene.store.IndexInput
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Cloneable
- Direct Known Subclasses:
BufferedIndexInput,ByteBufferIndexInput,ByteBuffersIndexInput,ChecksumIndexInput,FilterIndexInput
public abstract class IndexInput extends DataInput implements Closeable
Abstract base class for input from a file in aDirectory. A random-access input stream. Used for all Lucene index input operations.IndexInputmay only be used from one thread, because it is not thread safe (it keeps internal state like file position). To allow multithreaded use, everyIndexInputinstance must be cloned before it is used in another thread. Subclasses must therefore implementclone(), returning a newIndexInputwhich operates on the same underlying resource, but positioned independently.Warning: Lucene never closes cloned
IndexInputs, it will only callclose()on the original object.If you access the cloned IndexInput after closing the original object, any
readXXXmethods will throwAlreadyClosedException.- See Also:
Directory
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedIndexInput(String resourceDescription)resourceDescription should be a non-null, opaque string describing this resource; it's returned fromtoString().
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description IndexInputclone()Returns a clone of this stream.abstract voidclose()Closes the stream to further operations.abstract longgetFilePointer()Returns the current position in this file, where the next read will occur.protected StringgetFullSliceDescription(String sliceDescription)Subclasses call this to get the String for resourceDescription of a slice of thisIndexInput.abstract longlength()The number of bytes in the file.RandomAccessInputrandomAccessSlice(long offset, long length)Creates a random-access slice of this index input, with the given offset and length.abstract voidseek(long pos)Sets current position in this file, where the next read will occur.voidskipBytes(long numBytes)Skip overnumBytesbytes.abstract IndexInputslice(String sliceDescription, long offset, long length)Creates a slice of this index input, with the given description, offset, and length.StringtoString()-
Methods inherited from class org.apache.lucene.store.DataInput
readByte, readBytes, readBytes, readFloats, readGroupVInt, readGroupVInts, readInt, readInts, readLong, readLongs, readMapOfStrings, readSetOfStrings, readShort, readString, readVInt, readVLong, readZInt, readZLong
-
-
-
-
Constructor Detail
-
IndexInput
protected IndexInput(String resourceDescription)
resourceDescription should be a non-null, opaque string describing this resource; it's returned fromtoString().
-
-
Method Detail
-
close
public abstract void close() throws IOExceptionCloses the stream to further operations.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getFilePointer
public abstract long getFilePointer()
Returns the current position in this file, where the next read will occur.- See Also:
seek(long)
-
seek
public abstract void seek(long pos) throws IOExceptionSets current position in this file, where the next read will occur. If this is beyond the end of the file then this will throwEOFExceptionand then the stream is in an undetermined state.- Throws:
IOException- See Also:
getFilePointer()
-
skipBytes
public void skipBytes(long numBytes) throws IOExceptionSkip overnumBytesbytes. This method may skip bytes in whatever way is most optimal, and may not have the same behavior as reading the skipped bytes. In general, negativenumBytesare not supported.Behavior is functionally equivalent to seeking to
getFilePointer() + numBytes.- Specified by:
skipBytesin classDataInput- Throws:
IOException- See Also:
getFilePointer(),seek(long)
-
length
public abstract long length()
The number of bytes in the file.
-
clone
public IndexInput clone()
Returns a clone of this stream.Clones of a stream access the same data, and are positioned at the same point as the stream they were cloned from.
Expert: Subclasses must ensure that clones may be positioned at different points in the input from each other and from the stream they were cloned from.
Warning: Lucene never closes cloned
IndexInputs, it will only callclose()on the original object.If you access the cloned IndexInput after closing the original object, any
readXXXmethods will throwAlreadyClosedException.This method is NOT thread safe, so if the current
IndexInputis being used by one thread whilecloneis called by another, disaster could strike.
-
slice
public abstract IndexInput slice(String sliceDescription, long offset, long length) throws IOException
Creates a slice of this index input, with the given description, offset, and length. The slice is sought to the beginning.- Throws:
IOException
-
getFullSliceDescription
protected String getFullSliceDescription(String sliceDescription)
Subclasses call this to get the String for resourceDescription of a slice of thisIndexInput.
-
randomAccessSlice
public RandomAccessInput randomAccessSlice(long offset, long length) throws IOException
Creates a random-access slice of this index input, with the given offset and length.The default implementation calls
slice(java.lang.String, long, long), and it doesn't support random access, it implements absolute reads as seek+read.- Throws:
IOException
-
-