public final class FileUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_BUFFER_SIZE
The maximum size of a file buffer array.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canRead(java.io.File file)
Check if a
File exists and can be read. |
static boolean |
canReadAndIsDir(java.io.File file)
Check if a
File exists, is a directory, and can be read. |
static boolean |
canReadAndIsDir(java.nio.file.Path path)
Check if a
Path exists, is a directory, and can be read. |
static boolean |
canReadAndIsFile(java.io.File file)
Check if a
File exists, is a regular file, and can be read. |
static boolean |
canReadAndIsFile(java.nio.file.Path path)
Check if a
Path exists, is a regular file, and can be read. |
static void |
checkCanReadAndIsDir(java.io.File file)
Check if a
File exists, is a directory, and can be read. |
static void |
checkCanReadAndIsFile(java.io.File file)
Check if a
File exists, is a regular file, and can be read. |
static void |
checkCanReadAndIsFile(java.nio.file.Path path)
Check if a
Path exists, is a regular file, and can be read. |
static boolean |
closeDirectByteBuffer(java.nio.ByteBuffer byteBuffer,
LogNode log)
Close a
DirectByteBuffer -- in particular, will unmap a MappedByteBuffer. |
static java.lang.String |
currDirPath()
Get the current directory (only looks at the current directory the first time it is called, then caches this
value for future reads).
|
static java.lang.String |
getParentDirPath(java.lang.String path)
Get the parent dir path.
|
static java.lang.String |
getParentDirPath(java.lang.String path,
char separator)
Get the parent dir path.
|
static boolean |
isClassfile(java.lang.String path)
Check if the path ends with a ".class" extension, ignoring case.
|
static java.lang.String |
sanitizeEntryPath(java.lang.String path,
boolean removeInitialSlash,
boolean removeFinalSlash)
Sanitize relative paths against "zip slip" vulnerability, by removing path segments if ".." is found in the
URL, but without allowing navigation above the path hierarchy root.
|
public static final int MAX_BUFFER_SIZE
Integer.MAX_VALUE, since some VMs
reserve header words in arrays.public static java.lang.String currDirPath()
public static java.lang.String sanitizeEntryPath(java.lang.String path,
boolean removeInitialSlash,
boolean removeFinalSlash)
path - The path to sanitize.removeInitialSlash - If true, remove any '/' character(s) from the beginning of the returned path.removeFinalSlash - If true, remove any '/' character(s) from the end of the returned path.public static boolean isClassfile(java.lang.String path)
path - A file path.public static boolean canRead(java.io.File file)
File exists and can be read.file - A File.public static boolean canReadAndIsFile(java.io.File file)
File exists, is a regular file, and can be read.file - A File.public static boolean canReadAndIsFile(java.nio.file.Path path)
Path exists, is a regular file, and can be read.path - A Path.public static void checkCanReadAndIsFile(java.io.File file)
throws java.io.IOException
File exists, is a regular file, and can be read.file - A File.java.io.IOException - if the file does not exist, is not a regular file, or cannot be read.public static void checkCanReadAndIsFile(java.nio.file.Path path)
throws java.io.IOException
Path exists, is a regular file, and can be read.path - A Path.java.io.IOException - if the path does not exist, is not a regular file, or cannot be read.public static boolean canReadAndIsDir(java.io.File file)
File exists, is a directory, and can be read.file - A File.public static boolean canReadAndIsDir(java.nio.file.Path path)
Path exists, is a directory, and can be read.path - A Path.public static void checkCanReadAndIsDir(java.io.File file)
throws java.io.IOException
File exists, is a directory, and can be read.file - A File.java.io.IOException - if the file does not exist, is not a directory, or cannot be read.public static java.lang.String getParentDirPath(java.lang.String path,
char separator)
path - the pathseparator - the separatorpublic static java.lang.String getParentDirPath(java.lang.String path)
path - the pathpublic static boolean closeDirectByteBuffer(java.nio.ByteBuffer byteBuffer,
LogNode log)
DirectByteBuffer -- in particular, will unmap a MappedByteBuffer.byteBuffer - The ByteBuffer to close/unmap.log - The log.