gate.creole.annic.apache.lucene.index
Class CompoundFileWriter

java.lang.Object
  extended by gate.creole.annic.apache.lucene.index.CompoundFileWriter

final class CompoundFileWriter
extends Object

Combines multiple files into a single compound file. The file format:

The fileCount integer indicates how many files are contained in this compound file. The {directory} that follows has that many entries. Each directory entry contains an encoding identifier, an long pointer to the start of this file's data section, and a UTF String with that file's extension.

Version:
$Id: CompoundFileWriter.java 529 2004-10-05 11:55:26Z niraj $
Author:
Dmitry Serebrennikov

Nested Class Summary
private static class CompoundFileWriter.FileEntry
           
 
Field Summary
private  Directory directory
           
private  LinkedList entries
           
private  String fileName
           
private  HashSet ids
           
private  boolean merged
           
 
Constructor Summary
CompoundFileWriter(Directory dir, String name)
          Create the compound stream in the specified file.
 
Method Summary
 void addFile(String file)
          Add a source stream.
 void close()
          Merge files with the extensions added up to now.
private  void copyFile(CompoundFileWriter.FileEntry source, OutputStream os, byte[] buffer)
          Copy the contents of the file with specified extension into the provided output stream.
 Directory getDirectory()
          Returns the directory of the compound file.
 String getName()
          Returns the name of the compound file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

directory

private Directory directory

fileName

private String fileName

ids

private HashSet ids

entries

private LinkedList entries

merged

private boolean merged
Constructor Detail

CompoundFileWriter

public CompoundFileWriter(Directory dir,
                          String name)
Create the compound stream in the specified file. The file name is the entire name (no extensions are added).

Method Detail

getDirectory

public Directory getDirectory()
Returns the directory of the compound file.


getName

public String getName()
Returns the name of the compound file.


addFile

public void addFile(String file)
Add a source stream. If sourceDir is null, it is set to the same value as the directory where this compound stream exists. The id is the string by which the sub-stream will be know in the compound stream. The caller must ensure that the ID is unique. If the id is null, it is set to the name of the source file.


close

public void close()
           throws IOException
Merge files with the extensions added up to now. All files with these extensions are combined sequentially into the compound stream. After successful merge, the source files are deleted.

Throws:
IOException

copyFile

private void copyFile(CompoundFileWriter.FileEntry source,
                      OutputStream os,
                      byte[] buffer)
               throws IOException
Copy the contents of the file with specified extension into the provided output stream. Use the provided buffer for moving data to reduce memory allocation.

Throws:
IOException