Package org.eclipse.birt.core.archive
Class ArchiveUtil
- java.lang.Object
-
- org.eclipse.birt.core.archive.ArchiveUtil
-
public class ArchiveUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFILE_EXTENSIONTo support file/folder with same name, use the FILE_EXTENSION for files.static charUNIX_SEPARATOR_CHARstatic java.lang.StringUNIX_SEPERATOR
-
Constructor Summary
Constructors Constructor Description ArchiveUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidarchive(java.lang.String folder, java.lang.String file)static voidarchive(java.lang.String folderName, IStreamSorter sorter, java.lang.String fileName)Compound File Format:
1long(stream section position) + 1long(entry number in lookup map) + lookup map section + stream data section
The Lookup map is a hash map.static voidarchive(java.lang.String folderName, IStreamSorter sorter, java.lang.String fileName, boolean contentEscape)Compound File Format:
1long(stream section position) + 1long(entry number in lookup map) + lookup map section + stream data section
The Lookup map is a hash map.static intbytesToInteger(byte[] b)Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.static intbytesToInteger(byte[] b, int off)static longbytesToLong(byte[] b)Assemble eight bytes to an long value, make sure that the passed bytes length larger than 8.static longbytesToLong(byte[] b, int off)static voidconvertFolderArchive(java.lang.String folder, java.lang.String file)static voidcopy(IArchiveFile inArchive, IArchiveFile outArchive)static voidcopy(IArchiveFile inArchive, IArchiveFile outArchive, java.util.Map<java.lang.String,java.lang.String> transformations)static voidcopy(IDocArchiveReader reader, IDocArchiveWriter writer)static voidcopy(IDocArchiveReader reader, IDocArchiveWriter writer, java.util.Map<java.lang.String,java.lang.String> transformations)static voidcreateParentFolder(java.io.File fd)If the parent folder of the file doesn't exsit, create the parent folder.static IDocArchiveReadercreateReader(IDocArchiveWriter writer)static voiddeleteAllFiles(java.io.File dirOrFile)Recursively delete all the files and folders under dirOrFilestatic voidexpand(java.lang.String file, java.lang.String folder)static java.lang.StringgenerateUniqueFileFolderName(java.lang.String originalName)Generate a unique file or folder name which is in the same folder as the originalNamestatic java.lang.StringgetEntryName(java.lang.String filePath)escape entry name to a valid file namestatic java.lang.StringgetEntryName(java.lang.String rootPath, java.lang.String fullPath)convert a folder to entry name.static java.lang.StringgetFilePath(java.lang.String entryName)escape entry name to a valid file path duplicate '/' will be removedstatic java.lang.StringgetFilePath(java.lang.String rootPath, java.lang.String entryName)static java.lang.StringgetFolderPath(java.lang.String rootPath, java.lang.String entryName)static java.lang.StringgetFullPath(java.lang.String root, java.lang.String relative)static java.lang.StringgetRelativePath(java.lang.String rootPath, java.lang.String fullPath)static voidintegerToBytes(int v, byte[] b)static voidintegerToBytes(int v, byte[] b, int off)static voidlistAllFiles(java.io.File dir, java.util.ArrayList<? super java.io.File> fileList)Get all the files under the specified folder (including all the files under sub-folders)static voidlongToBytes(long v, byte[] b)static voidlongToBytes(long v, byte[] b, int off)static booleanremoveFileAndFolder(java.io.File file)static java.lang.String[]split(java.lang.String value, char splitChar)split strings by the character.static voidunzipArchive(java.io.File zipArchive, java.lang.String tempFolderPath)static voidzipFolderToStream(java.lang.String tempFolderPath, java.io.OutputStream ostream)
-
-
-
Field Detail
-
UNIX_SEPARATOR_CHAR
public static final char UNIX_SEPARATOR_CHAR
- See Also:
- Constant Field Values
-
UNIX_SEPERATOR
public static final java.lang.String UNIX_SEPERATOR
- See Also:
- Constant Field Values
-
FILE_EXTENSION
public static final java.lang.String FILE_EXTENSION
To support file/folder with same name, use the FILE_EXTENSION for files.- See Also:
- Constant Field Values
-
-
Method Detail
-
getFolderPath
public static java.lang.String getFolderPath(java.lang.String rootPath, java.lang.String entryName)- Parameters:
rootPath- - the absolute path of the root folder.relativePath- - the relative path.- Returns:
- the absolute path which concats rootPath and relativePath. The returned absolute path can be used directly to locate the file.
-
getFilePath
public static java.lang.String getFilePath(java.lang.String rootPath, java.lang.String entryName)
-
getFullPath
public static java.lang.String getFullPath(java.lang.String root, java.lang.String relative)- Parameters:
root- use unix path separatorrelative- use unix path separator- Returns:
-
split
public static java.lang.String[] split(java.lang.String value, char splitChar)split strings by the character. It implements javascript's behavior as always return count(splitChar)+1 for example, split char is '/':- '/' => ['', '']
- '/abc/' => ['', 'abc', '']
- 'abc' => 'abc'
- Parameters:
value-splitChar-- Returns:
-
getFilePath
public static java.lang.String getFilePath(java.lang.String entryName)
escape entry name to a valid file path duplicate '/' will be removed- Parameters:
name-- Returns:
-
getEntryName
public static java.lang.String getEntryName(java.lang.String filePath)
escape entry name to a valid file name- Parameters:
filePath- , a relative file path, start with "/"- Returns:
- entry name
-
getEntryName
public static java.lang.String getEntryName(java.lang.String rootPath, java.lang.String fullPath)convert a folder to entry name.- Parameters:
rootPath- - the absolute path of the root folder. The path is seperated by system's File seperator.fullString- - the absolute path of the stream. The path is seperated by system's File seperator.- Returns:
- the relative path string. The path is based on Unix syntax and starts with "/".
-
getRelativePath
public static java.lang.String getRelativePath(java.lang.String rootPath, java.lang.String fullPath)
-
generateUniqueFileFolderName
public static java.lang.String generateUniqueFileFolderName(java.lang.String originalName)
Generate a unique file or folder name which is in the same folder as the originalName- Parameters:
originalName- - the original Name. For example, it could be the name of the file archive- Returns:
- a unique file or folder name which is in the same folder as the originalName
-
createParentFolder
public static void createParentFolder(java.io.File fd)
If the parent folder of the file doesn't exsit, create the parent folder.
-
deleteAllFiles
public static void deleteAllFiles(java.io.File dirOrFile)
Recursively delete all the files and folders under dirOrFile- Parameters:
dirOrFile- - the File object which could be either a folder or a file.
-
zipFolderToStream
public static void zipFolderToStream(java.lang.String tempFolderPath, java.io.OutputStream ostream)
-
unzipArchive
public static void unzipArchive(java.io.File zipArchive, java.lang.String tempFolderPath)
-
copy
public static void copy(IArchiveFile inArchive, IArchiveFile outArchive) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static void copy(IArchiveFile inArchive, IArchiveFile outArchive, java.util.Map<java.lang.String,java.lang.String> transformations) throws java.io.IOException
- Parameters:
inArchive- Source ArchiveoutArchive- Destination Archivetransformations- Optional transformations of streams specified via java regex patterns. The map is keyed in by a regex pattern and the value will be the replacement expression which may refer capturing groups in the key. While copying the streams, if any of the key regex patterns matches the current source stream path being copied, the replacement expression is used to transform the source stream path to a target stream path.- Throws:
java.io.IOException
-
copy
public static void copy(IDocArchiveReader reader, IDocArchiveWriter writer) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static void copy(IDocArchiveReader reader, IDocArchiveWriter writer, java.util.Map<java.lang.String,java.lang.String> transformations) throws java.io.IOException
- Parameters:
reader- Sourcewriter- Destinationtransformations- Optional Stream Transformations specified using Java regex patterns- Throws:
java.io.IOException
-
archive
public static void archive(java.lang.String folder, java.lang.String file) throws java.io.IOException- Throws:
java.io.IOException
-
convertFolderArchive
public static void convertFolderArchive(java.lang.String folder, java.lang.String file) throws java.io.IOException- Throws:
java.io.IOException
-
archive
public static void archive(java.lang.String folderName, IStreamSorter sorter, java.lang.String fileName) throws java.io.IOExceptionCompound File Format:
1long(stream section position) + 1long(entry number in lookup map) + lookup map section + stream data section
The Lookup map is a hash map. The key is the relative path of the stram. The entry contains two long number. The first long is the start postion. The second long is the length of the stream.- Parameters:
tempFolder-fileArchiveName- - the file archive name- Throws:
java.io.IOException
-
archive
public static void archive(java.lang.String folderName, IStreamSorter sorter, java.lang.String fileName, boolean contentEscape) throws java.io.IOExceptionCompound File Format:
1long(stream section position) + 1long(entry number in lookup map) + lookup map section + stream data section
The Lookup map is a hash map. The key is the relative path of the stram. The entry contains two long number. The first long is the start postion. The second long is the length of the stream.- Parameters:
tempFolder-fileArchiveName- - the file archive name- Throws:
java.io.IOException
-
listAllFiles
public static void listAllFiles(java.io.File dir, java.util.ArrayList<? super java.io.File> fileList)Get all the files under the specified folder (including all the files under sub-folders)- Parameters:
dir- - the folder to look intofileList- - the fileList to be returned
-
expand
public static void expand(java.lang.String file, java.lang.String folder) throws java.io.IOException- Throws:
java.io.IOException
-
bytesToInteger
public static final int bytesToInteger(byte[] b)
Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.- Parameters:
bytes-- Returns:
- int value of bytes
-
bytesToInteger
public static final int bytesToInteger(byte[] b, int off)
-
bytesToLong
public static final long bytesToLong(byte[] b)
Assemble eight bytes to an long value, make sure that the passed bytes length larger than 8.- Parameters:
bytes-- Returns:
- int value of bytes
-
bytesToLong
public static final long bytesToLong(byte[] b, int off)
-
integerToBytes
public static final void integerToBytes(int v, byte[] b)
-
integerToBytes
public static final void integerToBytes(int v, byte[] b, int off)
-
longToBytes
public static final void longToBytes(long v, byte[] b)
-
longToBytes
public static final void longToBytes(long v, byte[] b, int off)
-
removeFileAndFolder
public static boolean removeFileAndFolder(java.io.File file)
-
createReader
public static final IDocArchiveReader createReader(IDocArchiveWriter writer)
-
-