Package com.bytedesk.core.utils
Class BdFileUtils
java.lang.Object
com.bytedesk.core.utils.BdFileUtils
File utilities.
- Author:
- johnniang
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckDirectoryTraversal(String parentPath, String pathToCheck) Checks directory traversal vulnerability.static voidcheckDirectoryTraversal(Path parentPath, String pathToCheck) Checks directory traversal vulnerability.static voidcheckDirectoryTraversal(Path parentPath, Path pathToCheck) Checks directory traversal vulnerability.static voidcloseQuietly(InputStream inputStream) Closes input stream quietly.static voidcloseQuietly(ZipInputStream zipInputStream) Closes zip input stream quietly.static voidcopyFolder(Path source, Path target) Copies folder.static voidcreateIfAbsent(Path path) Creates directories if absent.static boolean删除文件或者文件夹static voiddeleteFolder(Path deletingPath) Deletes folder recursively.static voiddeleteFolderQuietly(Path deletingPath) Deletes folder quietly.static booleanChecks if the given path is empty.static booleanisExcelFile(String fileName) 判断文件是否为Excel文件static voidmustBeEmpty(Path path) The given path must be empty.static PathskipZipParentFolder(Path unzippedPath) Skips zip parent folder.static voidunzip(ZipInputStream zis, Path targetPath) Unzip content to the target path.static StringuploadFile(String url, File file) 上传文件
-
Constructor Details
-
BdFileUtils
public BdFileUtils()
-
-
Method Details
-
uploadFile
上传文件- Parameters:
url-file-- Returns:
- Throws:
org.apache.http.client.ClientProtocolExceptionIOException
-
copyFolder
Copies folder.- Parameters:
source- source path must not be nulltarget- target path must not be null- Throws:
IOException
-
deleteFolder
Deletes folder recursively.- Parameters:
deletingPath- deleting path must not be null- Throws:
IOException
-
unzip
Unzip content to the target path.- Parameters:
zis- zip input stream must not be nulltargetPath- target path must not be null and not empty- Throws:
IOException
-
skipZipParentFolder
Skips zip parent folder. (Go into base folder)- Parameters:
unzippedPath- unzipped path must not be null- Returns:
- path containing base files
- Throws:
IOException
-
createIfAbsent
Creates directories if absent.- Parameters:
path- path must not be null- Throws:
IOException
-
isEmpty
Checks if the given path is empty.- Parameters:
path- path must not be null- Returns:
- true if the given path is empty; false otherwise
- Throws:
IOException
-
mustBeEmpty
The given path must be empty.- Parameters:
path- path must not be null- Throws:
IOException
-
checkDirectoryTraversal
Checks directory traversal vulnerability.- Parameters:
parentPath- parent path must not be null.pathToCheck- path to check must not be null
-
checkDirectoryTraversal
Checks directory traversal vulnerability.- Parameters:
parentPath- parent path must not be null.pathToCheck- path to check must not be null
-
checkDirectoryTraversal
Checks directory traversal vulnerability.- Parameters:
parentPath- parent path must not be null.pathToCheck- path to check must not be null
-
closeQuietly
Closes input stream quietly.- Parameters:
inputStream- input stream
-
closeQuietly
Closes zip input stream quietly.- Parameters:
zipInputStream- zip input stream
-
deleteFolderQuietly
Deletes folder quietly.- Parameters:
deletingPath- deleting path
-
del
删除文件或者文件夹- Parameters:
path- path- Returns:
- boolean
- Throws:
Exception- IORuntimeException
-
isExcelFile
判断文件是否为Excel文件- Parameters:
fileName- 文件名- Returns:
- 如果是Excel文件返回true,否则返回false
-