Package net.lingala.zip4j.util
Class Zip4jUtil
- java.lang.Object
-
- net.lingala.zip4j.util.Zip4jUtil
-
public class Zip4jUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description Zip4jUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkArrayListTypes(ArrayList sourceList, int type)
Checks to see if all the elements in the arraylist match the given typestatic boolean
checkFileExists(File file)
static boolean
checkFileExists(String path)
static boolean
checkFileReadAccess(String path)
static boolean
checkFileWriteAccess(String path)
static boolean
checkOutputFolder(String path)
static byte[]
convertCharset(String str)
static String
decodeFileName(byte[] data, boolean isUTF8)
Decodes file name based on encoding.static String
detectCharSet(String str)
Detects the encoding charset for the input stringstatic long
dosToJavaTme(int dosTime)
Converts time in dos format to Java formatstatic String
getAbsoluteFilePath(String filePath)
Returns an absoulte path for the given file pathstatic long[]
getAllHeaderSignatures()
static String
getCp850EncodedString(byte[] data)
Returns a string in Cp850 encoding from the input bytes.static int
getEncodedStringLength(String str)
returns the length of the string by wrapping it in a byte buffer with the appropriate charset of the input string and returns the limit of the byte bufferstatic int
getEncodedStringLength(String str, String charset)
returns the length of the string in the input encodingstatic FileHeader
getFileHeader(ZipModel zipModel, String fileName)
static FileHeader
getFileHeaderWithExactMatch(ZipModel zipModel, String fileName)
static long
getFileLengh(File file)
static long
getFileLengh(String file)
static String
getFileNameFromFilePath(File file)
static ArrayList
getFilesInDirectoryRec(File path, boolean readHiddenFiles)
static int
getIndexOfFileHeader(ZipModel zipModel, FileHeader fileHeader)
static long
getLastModifiedFileTime(File file, TimeZone timeZone)
static String
getRelativeFileName(String file, String rootFolderInZip, String rootFolderPath)
static ArrayList
getSplitZipFiles(ZipModel zipModel)
static String
getZipFileNameWithoutExt(String zipFile)
static boolean
isStringNotNullAndNotEmpty(String str)
static boolean
isSupportedCharset(String charset)
Checks if the input charset is supportedstatic boolean
isWindows()
static long
javaToDosTime(long time)
Converts input time from Java to DOS formatstatic void
setFileArchive(File file)
static void
setFileHidden(File file)
static void
setFileReadOnly(File file)
static void
setFileSystemMode(File file)
-
-
-
Method Detail
-
isStringNotNullAndNotEmpty
public static boolean isStringNotNullAndNotEmpty(String str)
-
checkOutputFolder
public static boolean checkOutputFolder(String path) throws ZipException
- Throws:
ZipException
-
checkFileReadAccess
public static boolean checkFileReadAccess(String path) throws ZipException
- Throws:
ZipException
-
checkFileWriteAccess
public static boolean checkFileWriteAccess(String path) throws ZipException
- Throws:
ZipException
-
checkFileExists
public static boolean checkFileExists(String path) throws ZipException
- Throws:
ZipException
-
checkFileExists
public static boolean checkFileExists(File file) throws ZipException
- Throws:
ZipException
-
isWindows
public static boolean isWindows()
-
setFileReadOnly
public static void setFileReadOnly(File file) throws ZipException
- Throws:
ZipException
-
setFileHidden
public static void setFileHidden(File file) throws ZipException
- Throws:
ZipException
-
setFileArchive
public static void setFileArchive(File file) throws ZipException
- Throws:
ZipException
-
setFileSystemMode
public static void setFileSystemMode(File file) throws ZipException
- Throws:
ZipException
-
getLastModifiedFileTime
public static long getLastModifiedFileTime(File file, TimeZone timeZone) throws ZipException
- Throws:
ZipException
-
getFileNameFromFilePath
public static String getFileNameFromFilePath(File file) throws ZipException
- Throws:
ZipException
-
getFileLengh
public static long getFileLengh(String file) throws ZipException
- Throws:
ZipException
-
getFileLengh
public static long getFileLengh(File file) throws ZipException
- Throws:
ZipException
-
javaToDosTime
public static long javaToDosTime(long time)
Converts input time from Java to DOS format- Parameters:
time
-- Returns:
- time in DOS format
-
dosToJavaTme
public static long dosToJavaTme(int dosTime)
Converts time in dos format to Java format- Parameters:
dosTime
-- Returns:
- time in java format
-
getFileHeader
public static FileHeader getFileHeader(ZipModel zipModel, String fileName) throws ZipException
- Throws:
ZipException
-
getFileHeaderWithExactMatch
public static FileHeader getFileHeaderWithExactMatch(ZipModel zipModel, String fileName) throws ZipException
- Throws:
ZipException
-
getIndexOfFileHeader
public static int getIndexOfFileHeader(ZipModel zipModel, FileHeader fileHeader) throws ZipException
- Throws:
ZipException
-
getFilesInDirectoryRec
public static ArrayList getFilesInDirectoryRec(File path, boolean readHiddenFiles) throws ZipException
- Throws:
ZipException
-
getZipFileNameWithoutExt
public static String getZipFileNameWithoutExt(String zipFile) throws ZipException
- Throws:
ZipException
-
convertCharset
public static byte[] convertCharset(String str) throws ZipException
- Throws:
ZipException
-
decodeFileName
public static String decodeFileName(byte[] data, boolean isUTF8)
Decodes file name based on encoding. If file name is UTF 8 encoded returns an UTF8 encoded string, else return Cp850 encoded String. If appropriate charset is not supported, then returns a System default charset encoded String- Parameters:
data
-isUTF8
-- Returns:
- String
-
getCp850EncodedString
public static String getCp850EncodedString(byte[] data)
Returns a string in Cp850 encoding from the input bytes. If this encoding is not supported, then String with the default encoding is returned.- Parameters:
data
-- Returns:
- String
-
getAbsoluteFilePath
public static String getAbsoluteFilePath(String filePath) throws ZipException
Returns an absoulte path for the given file path- Parameters:
filePath
-- Returns:
- String
- Throws:
ZipException
-
checkArrayListTypes
public static boolean checkArrayListTypes(ArrayList sourceList, int type) throws ZipException
Checks to see if all the elements in the arraylist match the given type- Parameters:
sourceList
- - list to be checkedtype
- - type of elements to be present in the list (ex: File, String, etc)- Returns:
- true if all elements match the given type, if not returns false
- Throws:
ZipException
-
detectCharSet
public static String detectCharSet(String str) throws ZipException
Detects the encoding charset for the input string- Parameters:
str
-- Returns:
- String - charset for the String
- Throws:
ZipException
- - if input string is null. In case of any other exception this method returns default System charset
-
getEncodedStringLength
public static int getEncodedStringLength(String str) throws ZipException
returns the length of the string by wrapping it in a byte buffer with the appropriate charset of the input string and returns the limit of the byte buffer- Parameters:
str
-- Returns:
- length of the string
- Throws:
ZipException
-
getEncodedStringLength
public static int getEncodedStringLength(String str, String charset) throws ZipException
returns the length of the string in the input encoding- Parameters:
str
-charset
-- Returns:
- int
- Throws:
ZipException
-
isSupportedCharset
public static boolean isSupportedCharset(String charset) throws ZipException
Checks if the input charset is supported- Parameters:
charset
-- Returns:
- boolean
- Throws:
ZipException
-
getSplitZipFiles
public static ArrayList getSplitZipFiles(ZipModel zipModel) throws ZipException
- Throws:
ZipException
-
getRelativeFileName
public static String getRelativeFileName(String file, String rootFolderInZip, String rootFolderPath) throws ZipException
- Throws:
ZipException
-
getAllHeaderSignatures
public static long[] getAllHeaderSignatures()
-
-