|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jaxfront.core.util.io.files.Objects
com.jaxfront.core.util.io.files.Strings
com.jaxfront.core.util.io.files.Files
public class Files
| Nested Class Summary | |
|---|---|
static interface |
Files.BufferingFilter
Description: Buffering filter stores some data, and these data can be later retrieved. |
static interface |
Files.ByteFilter
Description: The interface is used to define filters for filtering data in pipes. |
| Field Summary | |
|---|---|
static java.io.FileFilter |
directoryFilter
directoryFilter is a FileFilter that accepts directories |
static int |
FIND_ALL
|
static int |
FIND_DIRECTORY
|
static int |
FIND_FILE
|
| Fields inherited from class com.jaxfront.core.util.io.files.Strings |
|---|
_FALSE_, _TRUE_, _UNDEF_, ESCAPED, ESCAPEE |
| Constructor Summary | |
|---|---|
Files()
|
|
| Method Summary | |
|---|---|
static java.io.File |
appendBytesToFile(byte[] data,
java.lang.String fileTo)
Appends bytes to a file |
static java.io.File |
appendBytesToFile(char[] data,
java.lang.String fileTo)
Appends bytes to the end of a file |
static java.io.File |
appendToFile(byte[] data,
java.lang.String fileTo)
Appends bytes to the end of a file |
static java.io.File |
appendToFile(char[] data,
java.lang.String fileTo)
Appends chars to the end of a file |
static java.io.File |
appendToFile(java.lang.CharSequence data,
java.lang.String fileTo)
Appends a char sequence to the end of a file |
static java.lang.String |
chdir(java.lang.String dir)
Changes current directory |
static int |
compare(java.io.File left,
java.io.File right)
Compare two files |
static boolean |
copy(java.io.File from,
java.io.File to,
boolean overwrite)
copy copies a file or a directory to another |
static boolean |
copy(java.io.File from,
java.io.File to,
java.lang.String what,
boolean overwrite)
copy copies a file or a directory from one directory to another |
static boolean |
copy(java.lang.String from,
java.lang.String to)
|
static boolean |
copy(java.lang.String from,
java.lang.String to,
boolean overwrite)
copy copies a file or a directory to another |
static boolean |
copy(java.lang.String from,
java.lang.String to,
java.lang.String what)
copies a file or a directory from one directory to another |
static boolean |
deleteFile(java.io.File file)
Deletes a file or a directory (with all its contents, they say it is dangerous) |
static boolean |
deleteFile(java.lang.String filename)
Deletes a file or a directory (with all its contents, they say it is dangerous) |
static boolean |
deleteFiles(java.util.List files)
Deletes a file or a directory (with all its contents, they say it is dangerous) |
static java.lang.String |
dirname(java.io.File file)
Calculates directory path for a file (like in Perl) |
static java.lang.String |
dirname(java.lang.String path)
Calculates directory path by file path (like in Perl) |
static java.lang.String |
filename(java.lang.String path)
Calculates filename by file path (like in Perl) |
static java.util.List |
find(java.io.File subdir,
java.util.regex.Pattern pattern)
Lists recursively files and directories with name matching a regexp |
static java.util.List |
find(java.lang.String subdir,
java.util.regex.Pattern pattern)
Lists recursively files and directories with name matching a regexp |
static java.util.List |
find(java.lang.String subdir,
java.lang.String pattern)
Lists recursively files and directories with name matching a regexp |
static java.lang.String |
findLatest(java.lang.String subdir,
java.lang.String pattern)
Finds latest file or directory which name matches a pattern |
static java.lang.String |
findLatest(java.lang.String subdir,
java.lang.String pattern,
int whatExactly)
Finds latest file or directory or one of these which name matches a pattern |
static java.lang.String |
findLatestDirectory(java.lang.String subdir,
java.lang.String pattern)
Finds latest directory which name matches a pattern |
static java.lang.String |
findLatestFile(java.lang.String subdir,
java.lang.String pattern)
Finds latest file which name matches a pattern |
static java.lang.String |
getcwd()
Gets current directory path |
static java.lang.String |
getFullPath(java.io.File file)
Calculates full path of a file |
static java.lang.String |
getFullPath(java.lang.String path)
Calculates full path of a file by its path |
static java.lang.String |
getPackageName(java.lang.String basePath,
java.lang.String currentPath)
Calculates a java package name by directory name and base directory name |
static boolean |
install(java.lang.Class clazz,
java.lang.String resourceArchiveName,
java.io.File location)
installs files from a resource archive Reads a specified resource for aspecified class, unzips it to a specified directory |
static boolean |
install(java.lang.Class clazz,
java.lang.String resourceArchiveName,
java.lang.String folderName)
installs files from a resource archive Reads a specified resource for aspecified class, unzips it to a specified directory |
static java.lang.String |
lastModified(java.io.File file)
Gets file modification date/time as a string |
static java.io.File[] |
listSubdirectories(java.io.File dir)
Lists subdirectories of a directory |
static java.io.FileOutputStream |
makeFile(java.io.File file)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.io.File file,
boolean append)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String path)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String[] path)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String[] path,
boolean append)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String path,
boolean append)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String dir,
java.lang.String filename)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String dirname,
java.lang.String filename,
boolean append)
Creates or opens a file for output. |
static java.io.OutputStreamWriter |
makeFileWriter(java.lang.String path,
java.lang.String encoding)
Creates or opens a file for output. |
static java.lang.String |
path(java.lang.String currentDir,
java.lang.String filepath)
Having a directory and file path (relative or absolute) calculates full path |
static void |
pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean isBlocking)
pipes data from input stream to output stream |
static void |
pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean isBlocking,
Files.ByteFilter filter)
pipes data from input stream to output stream, possibly pumping them through the filter (if any) |
static boolean |
pipe(java.io.Reader in,
java.io.Writer out)
pipes data from input stream to output stream |
static byte[] |
readBytesFromFile(java.lang.String filename)
Reads the whole input stream into a byte array |
static byte[] |
readBytesFromStream(java.io.InputStream is)
Reads the whole input stream into a byte array |
static java.lang.String |
readString(java.io.Reader reader)
Reads the whole reader contents into a string |
static java.lang.String |
readStringFromFile(java.io.File file)
Reads the whole file into a string |
static java.lang.String |
readStringFromFile(java.io.File file,
java.lang.String encoding)
Reads the whole file into a string |
static java.lang.String |
readStringFromFile(java.lang.String filename)
Reads the whole file into a string |
static java.lang.String |
relPath(java.lang.String dir,
java.lang.String path)
Calculates relative path |
static java.lang.String[] |
splitPath(java.lang.String path)
Splits a path into directory name and file name |
static boolean |
synchronize(java.io.File left,
java.io.File right)
synchronizes two directories |
static boolean |
synchronize(java.io.File left,
java.io.File right,
java.lang.String what)
synchronizes two directories, left/what and
right/what |
static boolean |
unzip(java.util.zip.ZipInputStream zis,
java.io.File location)
unzips an input stream to a specified folder |
static java.io.File |
writeBytesToFile(byte[] data,
java.lang.String fileTo)
Writes bytes to a file |
static java.io.File |
writeToFile(byte[] data,
java.lang.String fileTo)
Creates a file and writes bytes into it |
static java.io.File |
writeToFile(char[] data,
java.lang.String fileTo)
Creates a file and writes chars into it |
static java.io.File |
writeToFile(java.lang.CharSequence data,
java.lang.String fileTo)
Creates a file and writes a char sequence into it |
static java.io.File |
writeToFile(java.io.InputStream is,
java.lang.String fileTo)
Creates a file and copies into it bytes from an input stream |
| Methods inherited from class com.jaxfront.core.util.io.files.Objects |
|---|
asMap, compose, crc32, crc32, getMap, getMap, getSet, indexOf, indexOf, indexOf, indexOf, inverse, isEmpty, map, map, map, map, map, reallocate, toBytes, toBytes, toChars, toMap, toMap, toMap, toMap, toSet |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int FIND_FILE
public static final int FIND_DIRECTORY
public static final int FIND_ALL
public static java.io.FileFilter directoryFilter
| Constructor Detail |
|---|
public Files()
| Method Detail |
|---|
public static final java.lang.String getFullPath(java.io.File file)
file -
public static final java.lang.String getFullPath(java.lang.String path)
path -
public static java.lang.String relPath(java.lang.String dir,
java.lang.String path)
dir - directory path that is expected to start the file pathpath - file path, relativer or not
relPath("c:\\MyHome\\dev", "c:\\MyHome\\dev\\src\\java")
returns "src\\java";relPath("/home/zaphod", "/home/zaphod/jbuilder8/samples/welcome")
returns "jbuilder8/samples/welcome";relPath("/home/zaphod", "/home/ford/jbuilder8")
returns "/home/ford/jbuilder8".
public static java.lang.String path(java.lang.String currentDir,
java.lang.String filepath)
currentDir - directory pathfilepath - file path, relative or not
path("c:\\MyHome\\dev", "src\\java") returns
"c:\\MyHome\\dev\\src\\java";path("/root/inetd", "/home/zaphod/jbuilder8/samples/welcome")
returns "/home/zaphod/jbuilder8/samples/welcome";path("\\Program Files", "c:\\MyHome\\dev")
returns "c:\\MyHome\\dev".public static java.lang.String[] splitPath(java.lang.String path)
path -
splitPath("/home/zaphod/jbuilder8/samples/welcome")
returns {"/home/zaphod/jbuilder8/samples", "welcome"};splitPath("src.java") returns {".",
"src.java"};splitPath("MyHome\\dev") returns {"MyHome",
"dev"}.public static java.lang.String dirname(java.io.File file)
file -
dirname(new File("/home/zaphod/jbuilder11/samples/welcome"))
returns "/home/zaphod/jbuilder8/samples";dirname(new File("src.java")) returns ".";dirname(new File("MyHome\\dev")) returns
"MyHome".public static java.lang.String dirname(java.lang.String path)
path -
dirname("/home/zaphod/jbuilder11/samples/welcome")
returns "/home/zaphod/jbuilder8/samples";dirname("src.java") returns ".";dirname("MyHome\\dev") returns "MyHome".public static java.lang.String filename(java.lang.String path)
path -
filename("/home/zaphod/jbuilder11/samples/welcome")
returns "welcome".
public static java.util.List find(java.io.File subdir,
java.util.regex.Pattern pattern)
subdir - where to lookpattern - to match
find(new File("."), Pattern.compile(".*les\\.java$")))
returns Arrays.asList(new String[] {new
File("Files.java").getCanonicalPath()}).
public static java.util.List find(java.lang.String subdir,
java.util.regex.Pattern pattern)
subdir - where to lookpattern - to match
find(".", Pattern.compile(".*les\\.java$")))
returns Arrays.asList(new String[] {"Files.java"}).
public static java.util.List find(java.lang.String subdir,
java.lang.String pattern)
subdir - where to lookpattern - to match
find(".", ".*les\\.java$") returns
Arrays.asList(new String[] {"Files.java"}).
public static java.lang.String findLatest(java.lang.String subdir,
java.lang.String pattern,
int whatExactly)
subdir - where to lookpattern - to matchwhatExactly - can be FIND_FILE or FIND_DIRECTORY or FIND_ALL
public static java.lang.String findLatest(java.lang.String subdir,
java.lang.String pattern)
subdir - where to lookpattern - to match
public static java.lang.String findLatestFile(java.lang.String subdir,
java.lang.String pattern)
subdir - where to lookpattern - to match
public static java.lang.String findLatestDirectory(java.lang.String subdir,
java.lang.String pattern)
subdir - where to lookpattern - to match
public static final java.io.File[] listSubdirectories(java.io.File dir)
dir - directory name
public static final java.lang.String lastModified(java.io.File file)
file -
lastModified(new File("src/com/javatools/util/Objects.java"))
returns "something".public static java.lang.String getcwd()
public static java.lang.String chdir(java.lang.String dir)
dir - to chdir
public static boolean deleteFile(java.lang.String filename)
filename -
deleteFile("/etc") returns true if the
program runs as root.public static boolean deleteFile(java.io.File file)
file - to delete
public static boolean deleteFiles(java.util.List files)
file - to delete
public static java.io.FileOutputStream makeFile(java.lang.String dirname,
java.lang.String filename,
boolean append)
throws java.io.IOException
append is true. append
determines whether to open in append mode
dirname - file locationfilename - the name of the fileappend - true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String dir,
java.lang.String filename)
throws java.io.IOException
dir - file locationfilename - the name of the file
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String[] path,
boolean append)
throws java.io.IOException
append is true. append
determines whether to open in append mode
path - [0] is directory name, [1] is file nameappend - true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String[] path)
throws java.io.IOException
path - [0] is directory name, [1] is file name
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String path,
boolean append)
throws java.io.IOException
append is true. append
determines whether to open in append mode
path - file pathappend - true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String path)
throws java.io.IOException
path - file path
java.io.IOException
public static java.io.FileOutputStream makeFile(java.io.File file,
boolean append)
throws java.io.IOException
append is true. append
determines whether to open in append mode
file - the file to openappend - true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.io.File file)
throws java.io.IOException
file - the file to open
java.io.IOException
public static final java.io.OutputStreamWriter makeFileWriter(java.lang.String path,
java.lang.String encoding)
throws java.io.IOException
path - the file to openencoding - the encoding to use
java.io.IOExceptionpublic static final java.lang.String readString(java.io.Reader reader)
reader - the reader to read
public static final java.lang.String readStringFromFile(java.io.File file)
file - the file to read
readStringFromFile("../src/com/myjavatools/utils/Files.java")
returns a string starting with "/**\r\n * <p>Title:
MyJavaTools: Files handling Tools</p>\r\n*".
public static final java.lang.String readStringFromFile(java.io.File file,
java.lang.String encoding)
file - the file to readencoding - the expected encoding
public static final java.lang.String readStringFromFile(java.lang.String filename)
filename - the file to read
readStringFromFile("../src/com/myjavatools/utils/Files.java")
returns a string starting with "/**\r\n * <p>Title:
MyJavaTools: Files handling Tools</p>\r\n*".public static final byte[] readBytesFromStream(java.io.InputStream is)
is - input stream to read
readBytesFromStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}))
returns new byte[] {1, 2, 3, 4, 5}.public static final byte[] readBytesFromFile(java.lang.String filename)
filename - file to read
readBytesFromFile("../src/com/myjavatools/utils/Files.java")
returns a byte array starting with {51, 50, 50, 13, 10, 32, 50}.
public static final java.io.File writeToFile(java.lang.CharSequence data,
java.lang.String fileTo)
data - the char sequence to write to filefileTo - file path
public static final java.io.File writeToFile(char[] data,
java.lang.String fileTo)
data - array of characters to write to filefileTo - file path
public static final java.io.File writeToFile(byte[] data,
java.lang.String fileTo)
data - array of bytes to append to the end of filefileTo - file path
public static final java.io.File writeBytesToFile(byte[] data,
java.lang.String fileTo)
#writeToFIle(byte[],String)
public static final java.io.File writeToFile(java.io.InputStream is,
java.lang.String fileTo)
throws java.io.IOException
is - input streamfileTo - file path
java.io.IOException
public static final java.io.File appendToFile(java.lang.CharSequence data,
java.lang.String fileTo)
data - char sequence to append to the end of filefileTo - file path
public static final java.io.File appendToFile(char[] data,
java.lang.String fileTo)
data - array of characters to append to the end of filefileTo - file path
public static final java.io.File appendToFile(byte[] data,
java.lang.String fileTo)
data - array of characters to append to the end of filefileTo - file path
public static final java.io.File appendBytesToFile(char[] data,
java.lang.String fileTo)
data - chars to append are converted to bytesfileTo -
public static final java.io.File appendBytesToFile(byte[] data,
java.lang.String fileTo)
appendToFile(byte[],String)
public static final java.lang.String getPackageName(java.lang.String basePath,
java.lang.String currentPath)
basePath - the base path for code sourcecurrentPath - the path of current directory
getPackageName("c:\\home\\myjavatools\\src", "c:\\home\\myjavatools\\src\\com\\myjavatools\\util")
returns "com.myjavatools.util".getPackageName("c:\\home\\myjavatools\\src\\java", "c:\\home\\myjavatools\\src\\com\\myjavatools\\util")
returns null.
public static void pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean isBlocking,
Files.ByteFilter filter)
throws java.io.IOException
in - InputStream the source of dataout - OutputStream where the output goes, filtered if filter is
present, or unfiltered otherwiseisBlocking - boolean whether input is blocking (in this case the maximum
amount is read in one operation; for nonblocking
in.available() determines how many bytes can be read)filter - ByteFilter the filter that applies to data; can be null
java.io.IOException - when input or output fails see the test for examples
public static void pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean isBlocking)
throws java.io.IOException
in - InputStream the source of dataout - OutputStream where the output goes, filtered if filter is
present, or unfiltered otherwiseisBlocking - boolean whether input is blocking (in this case the maximum
amount is read in one operation; for nonblocking
in.available() determines how many bytes can be read)
java.io.IOException - when input or output fails see the test for examples
public static boolean pipe(java.io.Reader in,
java.io.Writer out)
in - Reader the source of dataout - Writer where the output goes, filtered if filter is present,
or unfiltered otherwise
public static boolean copy(java.lang.String from,
java.lang.String to,
java.lang.String what)
from - directory from where to copyto - directory where to copywhat - what to copy (file or directory, recursively)
copy("c:\\home\\vlad\\dev", "c:\\home\\vlad\\rtm", "contents.xml")
public static boolean copy(java.io.File from,
java.io.File to,
java.lang.String what,
boolean overwrite)
from - directory from where to copyto - directory where to copywhat - what to copy (file or directory, recursively)
copy(new File(myHomeDir, "dev"), new File(myHomeDir, "rtm"), "contents.xml")
public static boolean copy(java.lang.String from,
java.lang.String to,
boolean overwrite)
from - to -
copy("c:\\home\\vlad\\dev\\contents.xml", "c:\\home\\vlad\\rtm\\contents.rss")
public static boolean copy(java.lang.String from,
java.lang.String to)
public static boolean copy(java.io.File from,
java.io.File to,
boolean overwrite)
from - to -
copy(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss")
public static int compare(java.io.File left,
java.io.File right)
throws java.io.IOException
left - right -
copy(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss");
compare(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss")
returns -1 java.io.IOException
public static boolean synchronize(java.io.File left,
java.io.File right,
java.lang.String what)
left/what and
right/what
left - File first directory that contains directory whatright - File second directory that contains directory whatwhat - String name of directory which contents is being synchronized
- Returns:
- boolean true if success
Example:
synchronize(new File(myHomeDir), new File(mySite), "myjavatools.com")
will leave subdirectories named myjavatools.com in these two directories absolutely identical.
public static boolean synchronize(java.io.File left,
java.io.File right)
left - File first directoryright - File second directory
synchronize(new File(myHomeDir), new File(myBackupDir))
will leave the contents of directories myHomeDIr and myBackupDir
absolutely identical.
public static boolean unzip(java.util.zip.ZipInputStream zis,
java.io.File location)
throws java.io.IOException
zis - ZipInputStream the source of zipped fileslocation - File the folder (directory) where to unzip the files
unzip(Web.getUrlInputStream(new URL(synchronize(new File(myHomeDir), new File(myBackupDir))
will leave the contents of directories myHomeDIr and myBackupDir
absolutely identical.java.io.IOException - when something went wrong
public static boolean install(java.lang.Class clazz,
java.lang.String resourceArchiveName,
java.io.File location)
throws java.io.IOException
clazz - Class the class whose package contains the archive as a
resourceresourceArchiveName - String the name of resource containing the archivelocation - File directory where the archive is unzipped
java.io.IOException - if something goes wrong
public static boolean install(java.lang.Class clazz,
java.lang.String resourceArchiveName,
java.lang.String folderName)
throws java.io.IOException
clazz - Class the class whose package contains the archive as a
resourceresourceArchiveName - String the name of resource containing the archivelocation - String name of directory where the archive is unzipped
java.io.IOException - if something goes wrong
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||