Class FilePacker
- java.lang.Object
-
- org.apache.jackrabbit.oak.index.indexer.document.tree.store.utils.FilePacker
-
public class FilePacker extends Object
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 Modifier and Type Class Description static class
FilePacker.FileEntry
-
Field Summary
Fields Modifier and Type Field Description static String
PACK_HEADER
The header of pack files ("PACK").
-
Constructor Summary
Constructors Constructor Description FilePacker()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isPackFile(File file)
Check whether the file starts with the magic header.static void
main(String... args)
static void
pack(File sourceDirectory, String fileNameRegex, File targetFile, boolean deleteSource)
Packs all the files in the source directory into a target file.static ArrayList<FilePacker.FileEntry>
readDirectoryListing(File sourceFile, RandomAccessFile source)
static void
unpack(File sourceFile, File targetDirectory, boolean deleteSource)
Unpack a target file target file.
-
-
-
Field Detail
-
PACK_HEADER
public static final String PACK_HEADER
The header of pack files ("PACK").- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(String... args) throws IOException
- Throws:
IOException
-
isPackFile
public static boolean isPackFile(File file)
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
-
-