Class IndexInput
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Cloneable
- Direct Known Subclasses:
BufferedIndexInput
,ByteBuffersIndexInput
,ChecksumIndexInput
,FilterIndexInput
Directory
. A random-access input stream.
Used for all Lucene index input operations.
IndexInput
may only be used from one thread, because it is not thread safe (it keeps
internal state like file position). To allow multithreaded use, every IndexInput
instance
must be cloned before it is used in another thread. Subclasses must therefore implement clone()
, returning a new IndexInput
which operates on the same underlying resource, but
positioned independently.
Warning: Lucene never closes cloned IndexInput
s, it will only call close()
on the original object.
If you access the cloned IndexInput after closing the original object, any readXXX
methods will throw AlreadyClosedException
.
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
IndexInput
(String resourceDescription) resourceDescription should be a non-null, opaque string describing this resource; it's returned fromtoString()
. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this stream.abstract void
close()
Closes the stream to further operations.abstract long
Returns the current position in this file, where the next read will occur.protected String
getFullSliceDescription
(String sliceDescription) Subclasses call this to get the String for resourceDescription of a slice of thisIndexInput
.isLoaded()
Returns a hint whether all the contents of this input are resident in physical memory.abstract long
length()
The number of bytes in the file.void
prefetch
(long offset, long length) Optional method: Give a hint to this input that some bytes will be read in the near future.randomAccessSlice
(long offset, long length) Creates a random-access slice of this index input, with the given offset and length.abstract void
seek
(long pos) Sets current position in this file, where the next read will occur.void
skipBytes
(long numBytes) Skip overnumBytes
bytes.abstract IndexInput
Creates a slice of this index input, with the given description, offset, and length.slice
(String sliceDescription, long offset, long length, ReadAdvice readAdvice) Create a slice with a specificReadAdvice
.toString()
void
updateReadAdvice
(ReadAdvice readAdvice) Optional method: Give a hint to this input about the change in read access pattern.Methods inherited from class org.apache.lucene.store.DataInput
readByte, readBytes, readBytes, readFloats, readGroupVInt, readInt, readInts, readLong, readLongs, readMapOfStrings, readSetOfStrings, readShort, readString, readVInt, readVLong, readZInt, readZLong
-
Constructor Details
-
IndexInput
resourceDescription should be a non-null, opaque string describing this resource; it's returned fromtoString()
.
-
-
Method Details
-
close
Closes the stream to further operations.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getFilePointer
public abstract long getFilePointer()Returns the current position in this file, where the next read will occur.- See Also:
-
seek
Sets current position in this file, where the next read will occur. If this is beyond the end of the file then this will throwEOFException
and then the stream is in an undetermined state.- Throws:
IOException
- See Also:
-
skipBytes
Skip overnumBytes
bytes. 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, negativenumBytes
are not supported.Behavior is functionally equivalent to seeking to
getFilePointer() + numBytes
.- Specified by:
skipBytes
in classDataInput
- Throws:
IOException
- See Also:
-
length
public abstract long length()The number of bytes in the file. -
toString
-
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
IndexInput
s, it will only callclose()
on the original object.If you access the cloned IndexInput after closing the original object, any
readXXX
methods will throwAlreadyClosedException
.This method is NOT thread safe, so if the current
IndexInput
is being used by one thread whileclone
is 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
-
slice
public IndexInput slice(String sliceDescription, long offset, long length, ReadAdvice readAdvice) throws IOException Create a slice with a specificReadAdvice
. This is typically used byCompoundFormat
implementations to honor theReadAdvice
of each file within the compound file.NOTE: it is only legal to call this method if this
IndexInput
has been open withReadAdvice.NORMAL
. However, this method accepts anyReadAdvice
value butnull
as a read advice for the slice.The default implementation delegates to
slice(String, long, long)
and ignores theReadAdvice
.- Throws:
IOException
-
getFullSliceDescription
Subclasses call this to get the String for resourceDescription of a slice of thisIndexInput
. -
randomAccessSlice
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
-
prefetch
Optional method: Give a hint to this input that some bytes will be read in the near future. IndexInput implementations may take advantage of this hint to start fetching pages of data immediately from storage.The default implementation is a no-op.
- Parameters:
offset
- start offsetlength
- the number of bytes to prefetch- Throws:
IOException
-
updateReadAdvice
Optional method: Give a hint to this input about the change in read access pattern. IndexInput implementations may take advantage of this hint to optimize reads from storage.The default implementation is a no-op.
- Throws:
IOException
-
isLoaded
Returns a hint whether all the contents of this input are resident in physical memory. It's a hint because the operating system may have paged out some of the data by the time this method returns. If the optional is true, then it's likely that the contents of this input are resident in physical memory. A value of false does not imply that the contents are not resident in physical memory. An empty optional is returned if it is not possible to determine.This runs in linear time with the
length()
of this input / page size.The default implementation returns an empty optional.
-