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
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 class
CompoundFileDirectory.FileEntry
Offset/Length for a slice inside of a compound file-
Nested classes/interfaces inherited from class org.apache.lucene.store.Directory
Directory.IndexInputSlicer
-
-
Field Summary
Fields Modifier and Type Field Description protected int
readBufferSize
-
Fields inherited from class org.apache.lucene.store.BaseDirectory
isOpen, lockFactory
-
-
Constructor Summary
Constructors Constructor Description CompoundFileDirectory(Directory directory, String fileName, IOContext context, boolean openForWrite)
Create a new CompoundFileDirectory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the store.IndexOutput
createOutput(String name, IOContext context)
Creates a new, empty file in the directory with the given name.Directory.IndexInputSlicer
createSlicer(String name, IOContext context)
Creates anDirectory.IndexInputSlicer
for the given file name.void
deleteFile(String name)
Not implementedboolean
fileExists(String name)
Returns true iff a file with the given name exists.long
fileLength(String name)
Returns the length of a file in the directory.Directory
getDirectory()
String
getName()
String[]
listAll()
Returns an array of strings, one for each file in the directory.Lock
makeLock(String name)
Not implementedIndexInput
openInput(String name, IOContext context)
Returns a stream reading an existing file, with the specified read buffer size.void
renameFile(String from, String to)
Not implementedvoid
sync(Collection<String> names)
Ensure that any writes to these files are moved to stable storage.String
toString()
-
Methods inherited from class org.apache.lucene.store.BaseDirectory
clearLock, ensureOpen, getLockFactory, setLockFactory
-
-
-
-
Constructor Detail
-
CompoundFileDirectory
public CompoundFileDirectory(Directory directory, String fileName, IOContext context, boolean openForWrite) throws IOException
Create a new CompoundFileDirectory.- Throws:
IOException
-
-
Method Detail
-
getDirectory
public Directory getDirectory()
-
getName
public String getName()
-
close
public void close() throws IOException
Description copied from class:Directory
Closes the store.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classDirectory
- Throws:
IOException
-
openInput
public IndexInput openInput(String name, IOContext context) throws IOException
Description copied from class:Directory
Returns 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 areFSDirectory
andCompoundFileDirectory
.- Must throw
FileNotFoundException
if the file does not exist (notjava.nio.file.NoSuchFileException
of Java 7).- Specified by:
openInput
in classDirectory
- Throws:
IOException
- Must throw
-
listAll
public String[] listAll()
Returns an array of strings, one for each file in the directory.
-
fileExists
public boolean fileExists(String name)
Returns true iff a file with the given name exists.- Specified by:
fileExists
in classDirectory
-
deleteFile
public void deleteFile(String name)
Not implemented- Specified by:
deleteFile
in classDirectory
- Throws:
UnsupportedOperationException
- always: not supported by CFS
-
renameFile
public void renameFile(String from, String to)
Not implemented- Throws:
UnsupportedOperationException
- always: not supported by CFS
-
fileLength
public long fileLength(String name) throws IOException
Returns the length of a file in the directory.- Specified by:
fileLength
in classDirectory
- Parameters:
name
- the name of the file for which to return the length.- Throws:
IOException
- if the file does not exist
-
createOutput
public IndexOutput createOutput(String name, IOContext context) throws IOException
Description copied from class:Directory
Creates a new, empty file in the directory with the given name. Returns a stream writing this file.- Specified by:
createOutput
in classDirectory
- Throws:
IOException
-
sync
public void sync(Collection<String> names)
Description copied from class:Directory
Ensure 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(String name)
Not implemented- Overrides:
makeLock
in classBaseDirectory
- Parameters:
name
- the name of the lock file- Throws:
UnsupportedOperationException
- always: not supported by CFS
-
createSlicer
public Directory.IndexInputSlicer createSlicer(String name, IOContext context) throws IOException
Description copied from class:Directory
Creates anDirectory.IndexInputSlicer
for the given file name. IndexInputSlicer allows otherDirectory
implementations to efficiently open one or more slicedIndexInput
instances from a single file handle. The underlying file handle is kept open until theDirectory.IndexInputSlicer
is closed.- Must throw
FileNotFoundException
if the file does not exist (notjava.nio.file.NoSuchFileException
of Java 7).- Overrides:
createSlicer
in classDirectory
- Throws:
IOException
- if anIOException
occurs
- Must throw
-
-