Package org.apache.lucene.store
Class CompoundFileDirectory
- java.lang.Object
-
- org.apache.lucene.store.Directory
-
- org.apache.lucene.store.BaseDirectory
-
- org.apache.lucene.store.CompoundFileDirectory
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class CompoundFileDirectory extends BaseDirectory
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.All files belonging to a segment have the same name with varying extensions. The extensions correspond to the different file formats used by the
Codec. When using the Compound File format these files are collapsed into a single .cfs file (except for theLiveDocsFormat, with a corresponding .cfe file indexing its sub-files.Files:
- .cfs: An optional "virtual" file consisting of all the other index files for systems that frequently run out of file handles.
- .cfe: The "virtual" compound file's entry table holding all entries in the corresponding .cfs file.
Description:
- Compound (.cfs) --> Header, FileData FileCount
- Compound Entry Table (.cfe) --> Header, FileCount, <FileName, DataOffset, DataLength> FileCount
- Header -->
CodecHeader - FileCount -->
VInt - DataOffset,DataLength -->
UInt64 - FileName -->
String - FileData --> raw file data
Notes:
- FileCount indicates how many files are contained in this compound file. The entry table that follows has that many entries.
- Each directory entry contains a long pointer to the start of this file's data section, the files length, and a String with that file's name.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCompoundFileDirectory.FileEntryOffset/Length for a slice inside of a compound file-
Nested classes/interfaces inherited from class org.apache.lucene.store.Directory
Directory.IndexInputSlicer
-
-
Constructor Summary
Constructors Constructor Description CompoundFileDirectory(Directory directory, java.lang.String fileName, IOContext context, boolean openForWrite)Create a new CompoundFileDirectory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the store.IndexOutputcreateOutput(java.lang.String name, IOContext context)Creates a new, empty file in the directory with the given name.Directory.IndexInputSlicercreateSlicer(java.lang.String name, IOContext context)Creates anDirectory.IndexInputSlicerfor the given file name.voiddeleteFile(java.lang.String name)Not implementedbooleanfileExists(java.lang.String name)Returns true iff a file with the given name exists.longfileLength(java.lang.String name)Returns the length of a file in the directory.DirectorygetDirectory()java.lang.StringgetName()java.lang.String[]listAll()Returns an array of strings, one for each file in the directory.LockmakeLock(java.lang.String name)Not implementedIndexInputopenInput(java.lang.String name, IOContext context)Returns a stream reading an existing file, with the specified read buffer size.voidrenameFile(java.lang.String from, java.lang.String to)Not implementedvoidsync(java.util.Collection<java.lang.String> names)Ensure that any writes to these files are moved to stable storage.java.lang.StringtoString()-
Methods inherited from class org.apache.lucene.store.BaseDirectory
clearLock, getLockFactory, setLockFactory
-
-
-
-
Method Detail
-
getDirectory
public Directory getDirectory()
-
getName
public java.lang.String getName()
-
close
public void close() throws java.io.IOExceptionDescription copied from class:DirectoryCloses the store.
-
openInput
public IndexInput openInput(java.lang.String name, IOContext context) throws java.io.IOException
Description copied from class:DirectoryReturns a stream reading an existing file, with the specified read buffer size. The particular Directory implementation may ignore the buffer size. Currently the only Directory implementations that respect this parameter areFSDirectoryandCompoundFileDirectory.- Must throw
FileNotFoundExceptionif the file does not exist (notjava.nio.file.NoSuchFileExceptionof Java 7). - Must throw
-
listAll
public java.lang.String[] listAll()
Returns an array of strings, one for each file in the directory.
-
fileExists
public boolean fileExists(java.lang.String name)
Returns true iff a file with the given name exists.- Specified by:
fileExistsin classDirectory
-
deleteFile
public void deleteFile(java.lang.String name)
Not implemented- Specified by:
deleteFilein classDirectory- Throws:
java.lang.UnsupportedOperationException- always: not supported by CFS
-
renameFile
public void renameFile(java.lang.String from, java.lang.String to)Not implemented- Throws:
java.lang.UnsupportedOperationException- always: not supported by CFS
-
fileLength
public long fileLength(java.lang.String name) throws java.io.IOExceptionReturns the length of a file in the directory.- Specified by:
fileLengthin classDirectory- Parameters:
name- the name of the file for which to return the length.- Throws:
java.io.IOException- if the file does not exist
-
createOutput
public IndexOutput createOutput(java.lang.String name, IOContext context) throws java.io.IOException
Description copied from class:DirectoryCreates a new, empty file in the directory with the given name. Returns a stream writing this file.- Specified by:
createOutputin classDirectory- Throws:
java.io.IOException
-
sync
public void sync(java.util.Collection<java.lang.String> names)
Description copied from class:DirectoryEnsure that any writes to these files are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index.
NOTE: Clients may call this method for same files over and over again, so some impls might optimize for that. For other impls the operation can be a noop, for various reasons.
-
makeLock
public Lock makeLock(java.lang.String name)
Not implemented- Overrides:
makeLockin classBaseDirectory- Parameters:
name- the name of the lock file- Throws:
java.lang.UnsupportedOperationException- always: not supported by CFS
-
createSlicer
public Directory.IndexInputSlicer createSlicer(java.lang.String name, IOContext context) throws java.io.IOException
Description copied from class:DirectoryCreates anDirectory.IndexInputSlicerfor the given file name. IndexInputSlicer allows otherDirectoryimplementations to efficiently open one or more slicedIndexInputinstances from a single file handle. The underlying file handle is kept open until theDirectory.IndexInputSliceris closed.- Must throw
FileNotFoundExceptionif the file does not exist (notjava.nio.file.NoSuchFileExceptionof Java 7).- Overrides:
createSlicerin classDirectory- Throws:
java.io.IOException- if anIOExceptionoccurs
- Must throw
-
-