com.h3c.sdn.adm.backup

## Class BackupRestoreUtil

- java.lang.Object
- - com.h3c.sdn.adm.backup.BackupRestoreUtil

-     public class BackupRestoreUtil
      extends Object

  Provides utilities to zip the contents of the specified folder

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BackupRestoreUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static File` | `getHashFile(File zipFile)` Gets the hash file associated with the zipFile.
    `static File` | `pack(String sourceDir, String targetDir, String filter, String zipFileName)` Creates a zip file after zipping the contents of the sourceDir directory based on a specific filter
    `static File` | `packDirectory(String sourceDir, String targetDir, String directoryName, String zipFileName, String pathRemove)` Creates a zip file after zipping the contents of the sourceDir directory based on a specific directory name
    `static File` | `packWithHash(String sourceDir, String targetDir, String filter, String zipFileName)` Creates a zip file of a directory after calculating the MD5 Hash of all the files present in the directory.
    `static File` | `unPack(File zipToUnbundle, String targetDir)` Unzips a zip file, upon its validation, to the specified path
    `static boolean` | `verifyHash(File zipFile, File hashFile)` Verifies the integrity of a file.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BackupRestoreUtil

          public BackupRestoreUtil()

  - ### Method Detail

    - #### pack

          public static File pack(String sourceDir,
                  String targetDir,
                  String filter,
                  String zipFileName)

      Creates a zip file after zipping the contents of the sourceDir directory based on a specific filter
      Parameters:
        `sourceDir` - - The file name of the source folder whose contents are to be zipped
        `targetDir` - - The file name of the directory where the zip files are to be kept on successful zip operation
        `filter` - - The regular expression string which is used as a filter to zip only the required files
        `zipFileName` - - The name of the created zip file
      Returns:
        the zip file on successful zip operation else null

    - #### unPack

          public static File unPack(File zipToUnbundle,
                    String targetDir)
                             throws IOException

      Unzips a zip file, upon its validation, to the specified path
      Parameters:
        `zipToUnbundle` - - The zip file which has to be unzipped
        `targetDir` - - The path where the files are to be unzipped
      Returns:
        the status of 'true' if the unzip operation is successful else false
      Throws:
        `IOException` - throws the IOException during file read/write

    - #### packDirectory

          public static File packDirectory(String sourceDir,
                           String targetDir,
                           String directoryName,
                           String zipFileName,
                           String pathRemove)

      Creates a zip file after zipping the contents of the sourceDir directory based on a specific directory name
      Parameters:
        `sourceDir` - - The file name of the source folder whose contents are to be zipped
        `targetDir` - - The file name of the directory where the zip files are to be kept on successful zip operation
        `directoryName` - - directoryName
        `zipFileName` - - The name of the created zip file
        `pathRemove` - the path to be removed
      Returns:
        the zip file on successful zip operation else null

    - #### packWithHash

          public static File packWithHash(String sourceDir,
                          String targetDir,
                          String filter,
                          String zipFileName)

      Creates a zip file of a directory after calculating the MD5 Hash of all the files present in the directory. The hash values are kept in the files which is packed with all the files. This in turn calls the `pack(java.lang.String, java.lang.String, java.lang.String, java.lang.String)`
      Parameters:
        `sourceDir` - - The file name of the source folder whose contents are to be zipped
        `targetDir` - - The file name of the directory where the zip files are to be kept on successful zip operation
        `filter` - - The regular expression string which is used as a filter to zip only the required files
        `zipFileName` - - The name of the created zip file
      Returns:
        the zip file on successful zip operation else null

    - #### getHashFile

          public static File getHashFile(File zipFile)

      Gets the hash file associated with the zipFile.
      Parameters:
        `zipFile` - the zip `File` of which the hash file is required
      Returns:
        the hash file if it has been successfully created, else null

    - #### verifyHash

          public static boolean verifyHash(File zipFile,
                           File hashFile)

      Verifies the integrity of a file. Hash value of the input file is calculated and compared with the value present in the associated hash file
      Parameters:
        `zipFile` - the zip file of which hash has to be verified
        `hashFile` - the hash file associated with zipFile
      Returns:
        'true' if the hash value mathches which means that the file is untampered else 'false'

Copyright © 2014. All Rights Reserved.