| java.lang.Object | |
| ↳ | com.pnfsoftware.jeb.util.IO |
This utility class contains useful static file manipulation routines.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| IO() | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| static boolean |
compressFolder(String folderPath, String zipfilePath)
Compress a folder and its contents to a zip archive.
| ||||||||||
| static boolean |
createDirectory(String path)
Create a directory.
| ||||||||||
| static boolean |
createDirectory(File f)
Create a directory.
| ||||||||||
| static File |
createTempFolder(String name)
Create a directory in the default temporary-file directory.
| ||||||||||
| static boolean |
deleteDirectory(File dir)
Delete a directory and its contents recursively.
| ||||||||||
| static boolean |
deleteDirectory(String path)
Delete a directory and its contents recursively.
| ||||||||||
| static void |
deleteDirectoryOnExit(File dir)
Delete a folder and all its contents recursively, when the virtual machine terminates.
| ||||||||||
| static String |
expandPath(String path)
Perform expansion of certain shell artifacts used in path names.
| ||||||||||
| static void |
extractToFolder(File inputZipFile, File outputFolder)
Extract the contents of a zip archive to a target folder.
| ||||||||||
| static byte |
getFirstByte(String path)
Get the first byte of a file.
| ||||||||||
| static int |
getFirstIntLE(String path)
Get the first 4-byte of a file, read as a little-endian integer.
| ||||||||||
| static short |
getFirstShortLE(String path)
Get the first 2-byte of a file, read as a little-endian short.
| ||||||||||
| static File |
getParentFile2(File file)
A safer implementation of
getParentFile(). | ||||||||||
| static boolean |
isFile(String path)
Determine if a path refers to an existing file.
| ||||||||||
| static boolean |
isZIPFile(String path)
Determine whether a file appears to be a ZIP archive.
| ||||||||||
| static List<String> |
listFiles(String path)
Recursively do a directory listing.
| ||||||||||
| static byte[] |
readFile(File file)
Read the contents of a binary files.@return
| ||||||||||
| static byte[] |
readFile(File file, long maxAllowedSize)
Read the contents of a binary file.@return
| ||||||||||
| static byte[] |
readFile(String path)
Read the contents of a binary file.@return
| ||||||||||
| static byte[] |
readFileSafe(File file)
Read a binary file safely.
| ||||||||||
| static String |
readInputLineSafe()
Read a line from the standard input.
| ||||||||||
| static byte[] |
readInputStream(InputStream in)
Read and reliably return all bytes of an input stream.
| ||||||||||
| static List<String> |
readLines(File file, Charset encoding)
Read the lines of a text file.
| ||||||||||
| static List<String> |
readLines(File file)
Read the lines of a UTF8 encoded text file.
| ||||||||||
| static List<String> |
readLines(InputStream input, Charset encoding)
Read the contents of a stream as a line of strings.
| ||||||||||
| static List<String> |
readLines(InputStream input)
Read the contents of a stream as a text buffer of UTF-8 encoded strings.@return
| ||||||||||
| static void |
writeFile(File file, byte[] data, boolean createDirs)
Write data to a file whose containing directory structure may not exist.
| ||||||||||
| static void |
writeFile(File file, byte[] data)
Write data to a file.
| ||||||||||
| static void |
writeFile(File file, byte[] data, int offset, int size, boolean createDirs)
Write data to a file whose containing directory structure may not exist.
| ||||||||||
| static void |
writeFile(File file, byte[] data, int offset, int size)
Write data to a file.
| ||||||||||
| static boolean |
writeFileSafe(File file, byte[] data, int offset, int size, boolean createDirs)
Write a binary file safely.
| ||||||||||
| static boolean |
writeFileSafe(File file, byte[] data, boolean createDirs)
Write a binary file safely.
| ||||||||||
| static void |
writeLines(OutputStream output, List<? extends CharSequence> lines)
Write strings, encoded in UT8.
| ||||||||||
| static void |
writeLines(OutputStream output, List<? extends CharSequence> lines, Charset encoding)
Write strings.
| ||||||||||
| static boolean |
writeLines(File file, List<? extends CharSequence> lines, Charset encoding)
Write strings to a text file.
| ||||||||||
| static boolean |
writeLines(File file, List<? extends CharSequence> lines)
Write strings to a text file, encoded as UTF8.
| ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Compress a folder and its contents to a zip archive.
| folderPath | input folder |
|---|---|
| zipfilePath | output zip file path |
Create a directory.
Create a directory.
Create a directory in the default temporary-file directory.
| name | folder name prefix |
|---|
| IOException | if an IO exception happened |
|---|
Delete a directory and its contents recursively.
Delete a directory and its contents recursively.
Delete a folder and all its contents recursively, when the virtual machine terminates.
| dir | folder to be deleted |
|---|
Perform expansion of certain shell artifacts used in path names.
Currently, the expansions performed are:
Extract the contents of a zip archive to a target folder.
| inputZipFile | input zip file path |
|---|---|
| outputFolder | output folder directory |
| IOException | if an error occurred; the current state of extraction within the target folder is not erased |
|---|
Get the first byte of a file. This method never throws exceptions. If an error occurs, 0 is returned. It is up to the client to handle that special case.
Get the first 4-byte of a file, read as a little-endian integer. This method never throws exceptions. If an error occurs, 0 is returned. It is up to the client to handle that special case.
| path | file path |
|---|
Get the first 2-byte of a file, read as a little-endian short. This method never throws exceptions. If an error occurs, 0 is returned. It is up to the client to handle that special case.
A safer implementation of getParentFile(). If the input file is a single-level
relative path (eg, "abc"), this method will first retrieve the absolute path (relative to the
current folder) before trying to retrieve the parent folder.
| file | file or folder |
|---|
Determine if a path refers to an existing file.
Determine whether a file appears to be a ZIP archive. This method never throws exceptions.
Recursively do a directory listing. The list returned is a list of true files (not directories).
Read the contents of a binary files.@return
| IOException |
|---|
Read the contents of a binary file.@return
| maxAllowedSize | specify a maximum read size |
|---|
| IOException | on IO error, or if the read size exceeds |
|---|
Read the contents of a binary file.@return
| IOException |
|---|
Read a binary file safely. If any error happens, an empty array is returned.
| file | input file |
|---|
Read a line from the standard input. This method is safe to use; it does not raise, instead returning a null string on error.
Read and reliably return all bytes of an input stream. The caller is responsible for closing the input stream after reading.@return
| IOException |
|---|
Read the lines of a text file.
Read the lines of a UTF8 encoded text file.
Read the contents of a stream as a line of strings.
| input | the input stream |
|---|---|
| encoding | the stream encoding |
| IOException | on IO error |
|---|
Read the contents of a stream as a text buffer of UTF-8 encoded strings.@return
| IOException |
|---|
Write data to a file whose containing directory structure may not exist. Existing file contents will be overwritten.
| IOException |
|---|
Write data to a file. Existing file contents will be overwritten.
| file | destination file |
|---|---|
| data | binary data to write |
| IOException | on error |
|---|
Write data to a file whose containing directory structure may not exist. Existing file contents will be overwritten.
| createDirs | create the intermediate directories if need be |
|---|
| IOException |
|---|
Write data to a file. Existing file contents will be overwritten.
| IOException |
|---|
Write a binary file safely.
Write a binary file safely.
Write strings, encoded in UT8.
| IOException |
|---|
Write strings.
| IOException |
|---|
Write strings to a text file.
Write strings to a text file, encoded as UTF8.