Class FilePacker
java.lang.Object
org.apache.jackrabbit.oak.index.indexer.document.tree.store.utils.FilePacker
A utility class that allows converting the files of a tree store into one
file (pack the files), and back from a file to a list of files (unpack the
files). This is a bit similar to a zip file, however
- each entry is already compressed, so no additional compression is needed;
- only files in the same directory can be processed;
- the pack file starts with a header that contains the list of files;
- while packing, the files are (optionally) deleted, so that this doesn't require twice the disk space;
- while unpacking, the pack file is (optionally) truncated, also to conserve disk space.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isPackFile
(File file) Check whether the file starts with the magic header.static void
static void
Packs all the files in the source directory into a target file.static ArrayList<FilePacker.FileEntry>
readDirectoryListing
(File sourceFile, RandomAccessFile source) static void
Unpack a target file target file.
-
Field Details
-
PACK_HEADER
The header of pack files ("PACK").- See Also:
-
-
Constructor Details
-
FilePacker
public FilePacker()
-
-
Method Details
-
main
- Throws:
IOException
-
isPackFile
Check whether the file starts with the magic header.- Parameters:
file
-- Returns:
- if this is a pack file
-
pack
public static void pack(File sourceDirectory, String fileNameRegex, File targetFile, boolean deleteSource) throws IOException Packs all the files in the source directory into a target file.- Parameters:
sourceDirectory
- the source directoryfileNameRegex
- the file name regular expressiondeleteSource
- whether the source files are deleted while copying- Throws:
IOException
-
unpack
public static void unpack(File sourceFile, File targetDirectory, boolean deleteSource) throws IOException Unpack a target file target file. The target directory is created if needed. Existing files are overwritten.- Parameters:
sourceFile
- the pack filetargetDirectory
- the target directorydeleteSource
- whether the source file is truncated while copying, and finally deleted.- Throws:
IOException
-
readDirectoryListing
public static ArrayList<FilePacker.FileEntry> readDirectoryListing(File sourceFile, RandomAccessFile source) throws IOException - Throws:
IOException
-