org.ChinaVO.FITSManager.Util
Class FileUtil

java.lang.Object
  extended by org.ChinaVO.FITSManager.Util.FileUtil

public class FileUtil
extends java.lang.Object

some utilitiy functions for file operation.

Version:
v1.0.0 2010-3-13 10:23:48
Author:
Fany

Constructor Summary
FileUtil()
           
 
Method Summary
static java.lang.String fileSize2String(long len)
          Format a filesize with unit B,KB,MB,GB,TB.
static java.lang.String getFileCRC32String(java.io.File f)
          Return a file's CRC32 string.
static java.lang.String getFileMD5String(java.io.File f)
          Get a file's md5 string.
static java.lang.String getFileSuffix(java.io.File f)
          Find the last '.' of the file's filename, and return the suffix string.
static boolean gzip(java.io.File f, java.io.File out)
          Compress a file to a gz file.
static boolean isSystemFile(java.io.File f)
          In windows OS,according to the FileSystemView.getSystemTypeDescription(), if a file's type is "System Folder", return true, else return false.
static java.lang.String path2URL(java.lang.String strPath, java.lang.String protocol)
          encoding the file path to be an URL.
exmaple:FileUtil.path2URL("D:/fits files/1.fit","file:/") return file:/D:/ftis%20files/1.fit
static boolean tar(java.io.File[] fs, java.io.File out)
          Pack files into a tar file.
static boolean targz(java.io.File[] fs, java.io.File out)
          tar files in to a tar package and then compress the package by gz.
static boolean zip(java.io.File[] fs, java.io.File out)
          compress files in to a zip file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

isSystemFile

public static boolean isSystemFile(java.io.File f)
In windows OS,according to the FileSystemView.getSystemTypeDescription(), if a file's type is "System Folder", return true, else return false. In linux always return false.

Parameters:
f - a File instance.
Returns:
linux will always return false. In windows, if the file's type is "System Folder", return true, else return false.

getFileSuffix

public static java.lang.String getFileSuffix(java.io.File f)
Find the last '.' of the file's filename, and return the suffix string. If '.' does not exists return an empty string "".

Parameters:
f - a File instance
Returns:
the suffix of f.

fileSize2String

public static java.lang.String fileSize2String(long len)
Format a filesize with unit B,KB,MB,GB,TB.

Parameters:
len - a file's size by bytes.
Returns:
a string describe the size with unit

path2URL

public static java.lang.String path2URL(java.lang.String strPath,
                                        java.lang.String protocol)
encoding the file path to be an URL.
exmaple:FileUtil.path2URL("D:/fits files/1.fit","file:/") return file:/D:/ftis%20files/1.fit

Parameters:
strPath - path of a file
protocol - the protocol used to visit the file, such as file:/,http:/,ftp:/ etc.
Returns:
the encoding URL

getFileMD5String

public static java.lang.String getFileMD5String(java.io.File f)
Get a file's md5 string.

Parameters:
f - file instance
Returns:
file's MD5 hash code

getFileCRC32String

public static java.lang.String getFileCRC32String(java.io.File f)
Return a file's CRC32 string.

Parameters:
f - File instance.
Returns:
file's CRC32 string

zip

public static boolean zip(java.io.File[] fs,
                          java.io.File out)
compress files in to a zip file

Parameters:
fs - file array(file in fs could be a folder, program will search all sub files and sub folders in the folder)
out - the output zip file's instance
Returns:
if success retur true, else false.

gzip

public static boolean gzip(java.io.File f,
                           java.io.File out)
Compress a file to a gz file.

Parameters:
f - file instance
out - gz file instance
Returns:
success return true, else false

tar

public static boolean tar(java.io.File[] fs,
                          java.io.File out)
Pack files into a tar file.

Parameters:
fs - file arrat,include folder.
out - tar file instance
Returns:
success return true, else return false

targz

public static boolean targz(java.io.File[] fs,
                            java.io.File out)
tar files in to a tar package and then compress the package by gz.

Parameters:
fs - file array, include folder.
out - tar.gz file's instance
Returns:
success return true, else return false.