Class ArchiveUtil

java.lang.Object
org.eclipse.birt.core.archive.ArchiveUtil

public class ArchiveUtil extends Object
  • Field Details

  • Constructor Details

    • ArchiveUtil

      public ArchiveUtil()
  • Method Details

    • getFolderPath

      public static String getFolderPath(String rootPath, 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 String getFilePath(String rootPath, String entryName)
    • getFullPath

      public static String getFullPath(String root, String relative)
      Parameters:
      root - use unix path separator
      relative - use unix path separator
      Returns:
    • split

      public static String[] split(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 String getFilePath(String entryName)
      escape entry name to a valid file path duplicate '/' will be removed
      Parameters:
      name -
      Returns:
    • getEntryName

      public static String getEntryName(String filePath)
      escape entry name to a valid file name
      Parameters:
      filePath - , a relative file path, start with "/"
      Returns:
      entry name
    • getEntryName

      public static String getEntryName(String rootPath, 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 String getRelativePath(String rootPath, String fullPath)
    • generateUniqueFileFolderName

      public static String generateUniqueFileFolderName(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(File fd)
      If the parent folder of the file doesn't exsit, create the parent folder.
    • deleteAllFiles

      public static void deleteAllFiles(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(String tempFolderPath, OutputStream ostream)
    • unzipArchive

      public static void unzipArchive(File zipArchive, String tempFolderPath)
    • copy

      public static void copy(IArchiveFile inArchive, IArchiveFile outArchive) throws IOException
      Throws:
      IOException
    • copy

      public static void copy(IArchiveFile inArchive, IArchiveFile outArchive, Map<String,String> transformations) throws IOException
      Parameters:
      inArchive - Source Archive
      outArchive - Destination Archive
      transformations - 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:
      IOException
    • copy

      public static void copy(IDocArchiveReader reader, IDocArchiveWriter writer) throws IOException
      Throws:
      IOException
    • copy

      public static void copy(IDocArchiveReader reader, IDocArchiveWriter writer, Map<String,String> transformations) throws IOException
      Parameters:
      reader - Source
      writer - Destination
      transformations - Optional Stream Transformations specified using Java regex patterns
      Throws:
      IOException
    • archive

      public static void archive(String folder, String file) throws IOException
      Throws:
      IOException
    • convertFolderArchive

      public static void convertFolderArchive(String folder, String file) throws IOException
      Throws:
      IOException
    • archive

      public static void archive(String folderName, IStreamSorter sorter, String fileName) throws IOException
      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. 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:
      IOException
    • archive

      public static void archive(String folderName, IStreamSorter sorter, String fileName, boolean contentEscape) throws IOException
      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. 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:
      IOException
    • listAllFiles

      public static void listAllFiles(File dir, ArrayList<? super File> fileList)
      Get all the files under the specified folder (including all the files under sub-folders)
      Parameters:
      dir - - the folder to look into
      fileList - - the fileList to be returned
    • expand

      public static void expand(String file, String folder) throws IOException
      Throws:
      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(File file)
    • createReader

      public static final IDocArchiveReader createReader(IDocArchiveWriter writer)