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:
Closeable,AutoCloseable
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 the LiveDocsFormat, 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 ClassesModifier and TypeClassDescriptionstatic final classOffset/Length for a slice inside of a compound fileNested classes/interfaces inherited from class org.apache.lucene.store.Directory
Directory.IndexInputSlicer -
Constructor Summary
ConstructorsConstructorDescriptionCompoundFileDirectory(Directory directory, String fileName, IOContext context, boolean openForWrite) Create a new CompoundFileDirectory. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the store.createOutput(String name, IOContext context) Creates a new, empty file in the directory with the given name.createSlicer(String name, IOContext context) Creates anDirectory.IndexInputSlicerfor the given file name.voiddeleteFile(String name) Not implementedbooleanfileExists(String name) Returns true iff a file with the given name exists.longfileLength(String name) Returns the length of a file in the directory.getName()String[]listAll()Returns an array of strings, one for each file in the directory.Not implementedReturns a stream reading an existing file, with the specified read buffer size.voidrenameFile(String from, String to) Not implementedvoidsync(Collection<String> names) Ensure that any writes to these files are moved to stable storage.toString()Methods inherited from class org.apache.lucene.store.BaseDirectory
clearLock, getLockFactory, setLockFactory
-
Constructor Details
-
CompoundFileDirectory
public CompoundFileDirectory(Directory directory, String fileName, IOContext context, boolean openForWrite) throws IOException Create a new CompoundFileDirectory.- Throws:
IOException
-
-
Method Details
-
getDirectory
-
getName
-
close
Description copied from class:DirectoryCloses the store.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classDirectory- Throws:
IOException
-
openInput
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).- Specified by:
openInputin classDirectory- Throws:
IOException
- Must throw
-
listAll
Returns an array of strings, one for each file in the directory. -
fileExists
Returns true iff a file with the given name exists.- Specified by:
fileExistsin classDirectory
-
deleteFile
Not implemented- Specified by:
deleteFilein classDirectory- Throws:
UnsupportedOperationException- always: not supported by CFS
-
renameFile
Not implemented- Throws:
UnsupportedOperationException- always: not supported by CFS
-
fileLength
Returns 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:
IOException- if the file does not exist
-
createOutput
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:
IOException
-
sync
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
Not implemented- Overrides:
makeLockin classBaseDirectory- Parameters:
name- the name of the lock file- Throws:
UnsupportedOperationException- always: not supported by CFS
-
createSlicer
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:
IOException- if anIOExceptionoccurs
- Must throw
-
toString
-