com.myjavatools.lib
Class Files

java.lang.Object
  extended bycom.myjavatools.lib.Objects
      extended bycom.myjavatools.lib.Strings
          extended bycom.myjavatools.lib.Files
Direct Known Subclasses:
Web

public class Files
extends Strings


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.myjavatools.lib.Strings
_FALSE_, _TRUE_, _UNDEF_, ESCAPED, ESCAPEE
 
Constructor Summary
Files()
           
 
Method Summary
static int adjustSizeByMooreLaw(int size, int thisYear)
           
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)
          copy copies a file or a directory to another
static boolean copy(java.io.File from, java.io.File to, java.lang.String what)
          copy copies a file or a directory from one directory to another
static boolean copy(java.lang.String from, java.lang.String to)
          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 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 byte[] readBytesFromStream(java.io.InputStream is, int size)
           
static java.lang.String readString(java.io.Reader reader)
           
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.myjavatools.lib.Strings
asProperties, countChar, countLeadingSpaces, countTrailingSpaces, crc32, crcreport, crcreport, decode, decode, decodeJavaString, encode, extractValue, fill, findDiff, format, format, format, grep, grep, hasAlpha, hexDump, hexDump, hexDump, htmlEncode, indexOf, indexOf, indexOf, indexOf, isAlmostEmpty, isAlpha, isTrue, isVowel, join, join, lastIndexOf, needsEncoding, needsEncoding, oneOf, oneOf, oneOf, pack, replace, sgmlEntity, split, startsWith, textHeight, textWidth, toBoolean, toCEncoding, toCEncoding, toHex, toHex, toHex, toHex, toHex, toHexReadable, toHexReadable, toHexReadable, toHexReadable, toJavaEncoding, toJavaEncoding, toJavaEncoding, toJavaEncoding, toJavaEncoding, toJavaEncoding, toJavaHexEncoding, toJavaHexEncoding, toJavaOctalEncoding, toPropertiesEncoding, toPropertiesEncoding, toReadable, toReadable, toSgmlEncoding, toSgmlEncoding, toString, toStrings, unpack, unzip, unzip, unzip, wordCount, write, zip, zip2bytes, zip8bit
 
Methods inherited from class com.myjavatools.lib.Objects
asMap, cat, compose, crc32, crc32, getList, getMap, getMap, getSet, indexOf, indexOf, indexOf, indexOf, inverse, isEmpty, map, map, map, map, map, reallocate, toBytes, toBytes, toChars, toMap, toMap, toMap, toMap, toSet, union
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIND_FILE

public static final int FIND_FILE
See Also:
Constant Field Values

FIND_DIRECTORY

public static final int FIND_DIRECTORY
See Also:
Constant Field Values

FIND_ALL

public static final int FIND_ALL
See Also:
Constant Field Values

directoryFilter

public static java.io.FileFilter directoryFilter
directoryFilter is a FileFilter that accepts directories

Constructor Detail

Files

public Files()
Method Detail

getFullPath

public static final java.lang.String getFullPath(java.io.File file)
Calculates full path of a file

Parameters:
file -
Returns:
full path

getFullPath

public static final java.lang.String getFullPath(java.lang.String path)
Calculates full path of a file by its path

Parameters:
path -
Returns:
full path

relPath

public static java.lang.String relPath(java.lang.String dir,
                                       java.lang.String path)
Calculates relative path

Parameters:
dir - directory path that is expected to start the file path
path - file path, relativer or not
Returns:
if path starts with dir, then the rest of the path, else path

Examples:
  • 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".

  • path

    public 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

    Parameters:
    currentDir - directory path
    filepath - file path, relative or not
    Returns:
    full file path

    Examples:
  • 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".

  • splitPath

    public static java.lang.String[] splitPath(java.lang.String path)
    Splits a path into directory name and file name

    Parameters:
    path -
    Returns:
    String array consisting of two elements

    Examples:
  • splitPath("/home/zaphod/jbuilder8/samples/welcome") returns {"/home/zaphod/jbuilder8/samples", "welcome"};
  • splitPath("src.java") returns {".", "src.java"};
  • splitPath("MyHome\\dev") returns {"MyHome", "dev"}.

  • dirname

    public static java.lang.String dirname(java.io.File file)
    Calculates directory path for a file (like in Perl)

    Parameters:
    file -
    Returns:
    directory path Unlike java.io.File.getParent(), never returns null (see example 2 below).

    Examples:
  • 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".

  • dirname

    public static java.lang.String dirname(java.lang.String path)
    Calculates directory path by file path (like in Perl)

    Parameters:
    path -
    Returns:
    directory path Unlike java.io.File.getParent(), never returns null (see example 2 below).

    Examples:
  • dirname("/home/zaphod/jbuilder11/samples/welcome") returns "/home/zaphod/jbuilder8/samples";
  • dirname("src.java") returns ".";
  • dirname("MyHome\\dev") returns "MyHome".

  • filename

    public static java.lang.String filename(java.lang.String path)
    Calculates filename by file path (like in Perl)

    Parameters:
    path -
    Returns:
    file name

    Example:
  • filename("/home/zaphod/jbuilder11/samples/welcome") returns "welcome".

  • find

    public static java.util.List find(java.io.File subdir,
                                      java.util.regex.Pattern pattern)
    Lists recursively files and directories with name matching a regexp

    Parameters:
    subdir - where to look
    pattern - to match
    Returns:
    List of absolute filepaths

    Example:
  • find(new File("."), Pattern.compile(".*les\\.java$"))) returns Arrays.asList(new String[] {new File("Files.java").getCanonicalPath()}).

  • find

    public static java.util.List find(java.lang.String subdir,
                                      java.util.regex.Pattern pattern)
    Lists recursively files and directories with name matching a regexp

    Parameters:
    subdir - where to look
    pattern - to match
    Returns:
    List of absolute filepaths

    Example:
  • find(".", Pattern.compile(".*les\\.java$"))) returns Arrays.asList(new String[] {"Files.java"}).

  • find

    public static java.util.List find(java.lang.String subdir,
                                      java.lang.String pattern)
    Lists recursively files and directories with name matching a regexp

    Parameters:
    subdir - where to look
    pattern - to match
    Returns:
    List of absolute filepaths

    Example:
  • find(".", ".*les\\.java$") returns Arrays.asList(new String[] {"Files.java"}).

  • findLatest

    public 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

    Parameters:
    subdir - where to look
    pattern - to match
    whatExactly - can be FIND_FILE or FIND_DIRECTORY or FIND_ALL
    Returns:
    the path found

    findLatest

    public static java.lang.String findLatest(java.lang.String subdir,
                                              java.lang.String pattern)
    Finds latest file or directory which name matches a pattern

    Parameters:
    subdir - where to look
    pattern - to match
    Returns:
    the path found

    findLatestFile

    public static java.lang.String findLatestFile(java.lang.String subdir,
                                                  java.lang.String pattern)
    Finds latest file which name matches a pattern

    Parameters:
    subdir - where to look
    pattern - to match
    Returns:
    the path found

    findLatestDirectory

    public static java.lang.String findLatestDirectory(java.lang.String subdir,
                                                       java.lang.String pattern)
    Finds latest directory which name matches a pattern

    Parameters:
    subdir - where to look
    pattern - to match
    Returns:
    the path found

    listSubdirectories

    public static final java.io.File[] listSubdirectories(java.io.File dir)
    Lists subdirectories of a directory

    Parameters:
    dir - directory name
    Returns:
    an array of subdirectores

    lastModified

    public static final java.lang.String lastModified(java.io.File file)
    Gets file modification date/time as a string

    Parameters:
    file -
    Returns:
    file modification time as a string

    Example:
  • lastModified(new File("src/com/javatools/util/Objects.java")) returns "something".

  • getcwd

    public static java.lang.String getcwd()
    Gets current directory path

    Returns:
    the current directory path

    chdir

    public static java.lang.String chdir(java.lang.String dir)
    Changes current directory

    Parameters:
    dir - to chdir
    Returns:
    previous current directory

    deleteFile

    public static boolean deleteFile(java.lang.String filename)
    Deletes a file or a directory (with all its contents, they say it is dangerous)

    Parameters:
    filename -
    Returns:
    true if successful

    Bad Example:
  • deleteFile("/etc") returns true if the program runs as root.

  • deleteFile

    public static boolean deleteFile(java.io.File file)
    Deletes a file or a directory (with all its contents, they say it is dangerous)

    Parameters:
    file - to delete
    Returns:
    true if successful

    makeFile

    public static java.io.FileOutputStream makeFile(java.lang.String dirname,
                                                    java.lang.String filename,
                                                    boolean append)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten, unless append is true. append determines whether to open in append mode

    Parameters:
    dirname - file location
    filename - the name of the file
    append - true if open in append mode
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.lang.String dir,
                                                    java.lang.String filename)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten.

    Parameters:
    dir - file location
    filename - the name of the file
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.lang.String[] path,
                                                    boolean append)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten, unless append is true. append determines whether to open in append mode

    Parameters:
    path - [0] is directory name, [1] is file name
    append - true if open in append mode
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.lang.String[] path)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten.

    Parameters:
    path - [0] is directory name, [1] is file name
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.lang.String path,
                                                    boolean append)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten, unless append is true. append determines whether to open in append mode

    Parameters:
    path - file path
    append - true if open in append mode
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.lang.String path)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten.

    Parameters:
    path - file path
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.io.File file,
                                                    boolean append)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten, unless append is true. append determines whether to open in append mode

    Parameters:
    file - the file to open
    append - true if open in append mode
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFile

    public static java.io.FileOutputStream makeFile(java.io.File file)
                                             throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten.

    Parameters:
    file - the file to open
    Returns:
    file output stream
    Throws:
    java.io.IOException

    makeFileWriter

    public static final java.io.OutputStreamWriter makeFileWriter(java.lang.String path,
                                                                  java.lang.String encoding)
                                                           throws java.io.IOException
    Creates or opens a file for output. If subdirectories in the path do not exist, they are created too. If the file exists, it is overwritten.

    Parameters:
    path - the file to open
    encoding - the encoding to use
    Returns:
    output stream writer
    Throws:
    java.io.IOException

    readString

    public static final java.lang.String readString(java.io.Reader reader)

    readStringFromFile

    public static final java.lang.String readStringFromFile(java.io.File file)
    Reads the whole file into a string

    Parameters:
    file - the file to read
    Returns:
    file contents as a string, or null if error occurred

    Example:
  • readStringFromFile("../src/com/myjavatools/utils/Files.java") returns a string starting with "/**\r\n * <p>Title: MyJavaTools: Files handling Tools</p>\r\n*".

  • readStringFromFile

    public static final java.lang.String readStringFromFile(java.io.File file,
                                                            java.lang.String encoding)
    Reads the whole file into a string

    Parameters:
    file - the file to read
    encoding - the expected encoding
    Returns:
    file contents as a string, or null if error occurred

    readStringFromFile

    public static final java.lang.String readStringFromFile(java.lang.String filename)
    Reads the whole file into a string

    Parameters:
    filename - the file to read
    Returns:
    file contents as a string, or null if error occurred

    Example:
  • readStringFromFile("../src/com/myjavatools/utils/Files.java") returns a string starting with "/**\r\n * <p>Title: MyJavaTools: Files handling Tools</p>\r\n*".

  • adjustSizeByMooreLaw

    public static final int adjustSizeByMooreLaw(int size,
                                                 int thisYear)

    readBytesFromStream

    public static final byte[] readBytesFromStream(java.io.InputStream is)
    Reads the whole input stream into a byte array

    Parameters:
    is - input stream to read
    Returns:
    file contents as byte array, or null if error occurred

    Example:
  • readBytesFromStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5})) returns new byte[] {1, 2, 3, 4, 5}.

  • readBytesFromStream

    public static final byte[] readBytesFromStream(java.io.InputStream is,
                                                   int size)

    readBytesFromFile

    public static final byte[] readBytesFromFile(java.lang.String filename)
    Reads the whole input stream into a byte array

    Parameters:
    filename - file to read
    Returns:
    file contents as byte array, or null if error occurred

    Example:
  • readBytesFromFile("../src/com/myjavatools/utils/Files.java") returns a byte array starting with {51, 50, 50, 13, 10, 32, 50}.

  • writeToFile

    public static final java.io.File writeToFile(java.lang.CharSequence data,
                                                 java.lang.String fileTo)
    Creates a file and writes a char sequence into it

    Parameters:
    data - the char sequence to write to file
    fileTo - file path
    Returns:
    file

    writeToFile

    public static final java.io.File writeToFile(char[] data,
                                                 java.lang.String fileTo)
    Creates a file and writes chars into it

    Parameters:
    data - array of characters to write to file
    fileTo - file path
    Returns:
    file

    writeToFile

    public static final java.io.File writeToFile(byte[] data,
                                                 java.lang.String fileTo)
    Creates a file and writes bytes into it

    Parameters:
    data - array of bytes to append to the end of file
    fileTo - file path
    Returns:
    file

    writeBytesToFile

    public static final java.io.File writeBytesToFile(byte[] data,
                                                      java.lang.String fileTo)
    Writes bytes to a file

    Returns:
    file
    See Also:
    #writeToFIle(byte[],String)

    writeToFile

    public static final java.io.File writeToFile(java.io.InputStream is,
                                                 java.lang.String fileTo)
                                          throws java.io.IOException
    Creates a file and copies into it bytes from an input stream

    Parameters:
    is - input stream
    fileTo - file path
    Returns:
    file
    Throws:
    java.io.IOException

    appendToFile

    public static final java.io.File appendToFile(java.lang.CharSequence data,
                                                  java.lang.String fileTo)
    Appends a char sequence to the end of a file

    Parameters:
    data - char sequence to append to the end of file
    fileTo - file path
    Returns:
    file

    appendToFile

    public static final java.io.File appendToFile(char[] data,
                                                  java.lang.String fileTo)
    Appends chars to the end of a file

    Parameters:
    data - array of characters to append to the end of file
    fileTo - file path
    Returns:
    file

    appendToFile

    public static final java.io.File appendToFile(byte[] data,
                                                  java.lang.String fileTo)
    Appends bytes to the end of a file

    Parameters:
    data - array of characters to append to the end of file
    fileTo - file path
    Returns:
    file

    appendBytesToFile

    public static final java.io.File appendBytesToFile(char[] data,
                                                       java.lang.String fileTo)
    Appends bytes to the end of a file

    Parameters:
    data - chars to append are converted to bytes
    fileTo -
    Returns:
    file

    appendBytesToFile

    public static final java.io.File appendBytesToFile(byte[] data,
                                                       java.lang.String fileTo)
    Appends bytes to a file

    See Also:
    appendToFile(byte[],String)

    getPackageName

    public static final java.lang.String getPackageName(java.lang.String basePath,
                                                        java.lang.String currentPath)
    Calculates a java package name by directory name and base directory name

    Parameters:
    basePath - the base path for code source
    currentPath - the path of current directory
    Returns:
    package name

    Examples:
  • 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.

  • pipe

    public static void pipe(java.io.InputStream in,
                            java.io.OutputStream out,
                            boolean isBlocking,
                            Files.ByteFilter filter)
                     throws java.io.IOException
    pipes data from input stream to output stream, possibly pumping them through the filter (if any)

    Parameters:
    in - InputStream the source of data
    out - OutputStream where the output goes, filtered if filter is present, or unfiltered otherwise
    isBlocking - 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
    Throws:
    java.io.IOException - when input or output fails see the test for examples

    pipe

    public static void pipe(java.io.InputStream in,
                            java.io.OutputStream out,
                            boolean isBlocking)
                     throws java.io.IOException
    pipes data from input stream to output stream

    Parameters:
    in - InputStream the source of data
    out - OutputStream where the output goes, filtered if filter is present, or unfiltered otherwise
    isBlocking - 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)
    Throws:
    java.io.IOException - when input or output fails see the test for examples

    pipe

    public static boolean pipe(java.io.Reader in,
                               java.io.Writer out)
    pipes data from input stream to output stream

    Parameters:
    in - Reader the source of data
    out - Writer where the output goes, filtered if filter is present, or unfiltered otherwise
    Returns:
    boolean true if successful, false otherwise see the test for examples

    copy

    public 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

    Parameters:
    from - directory from where to copy
    to - directory where to copy
    what - what to copy (file or directory, recursively)
    Returns:
    true if successful

    Example:
  • copy("c:\\home\\vlad\\dev", "c:\\home\\vlad\\rtm", "contents.xml")

  • copy

    public static boolean copy(java.io.File from,
                               java.io.File to,
                               java.lang.String what)
    copy copies a file or a directory from one directory to another

    Parameters:
    from - directory from where to copy
    to - directory where to copy
    what - what to copy (file or directory, recursively)
    Returns:
    true if successful

    Example:
  • copy(new File(myHomeDir, "dev"), new File(myHomeDir, "rtm"), "contents.xml")

  • copy

    public static boolean copy(java.lang.String from,
                               java.lang.String to)
    copy copies a file or a directory to another

    Parameters:
    from -
    to -
    Returns:
    true if successful

    Example:
  • copy("c:\\home\\vlad\\dev\\contents.xml", "c:\\home\\vlad\\rtm\\contents.rss")

  • copy

    public static boolean copy(java.io.File from,
                               java.io.File to)
    copy copies a file or a directory to another

    Parameters:
    from -
    to -
    Returns:
    true if successful

    Example:
  • copy(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss")

  • compare

    public static int compare(java.io.File left,
                              java.io.File right)
                       throws java.io.IOException
    Compare two files

    Parameters:
    left -
    right -
    Returns:
    -1 if left file is older or shorter or "smaller" than right 0 if files are equal 1 if right file is older or shorter or "smaller" than left

    Example:
  • copy(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss");
    compare(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss")
    returns -1
  • Throws:
    java.io.IOException

    synchronize

    public static boolean synchronize(java.io.File left,
                                      java.io.File right,
                                      java.lang.String what)
    synchronizes two directories, left/what and right/what

    Parameters:
    left - File first directory that contains directory what
    right - File second directory that contains directory what
    what - 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.

  • synchronize

    public static boolean synchronize(java.io.File left,
                                      java.io.File right)
    synchronizes two directories

    Parameters:
    left - File first directory
    right - File second directory
    Returns:
    boolean true if success

    Example:
  • synchronize(new File(myHomeDir), new File(myBackupDir)) will leave the contents of directories myHomeDIr and myBackupDir absolutely identical.

  • unzip

    public static boolean unzip(java.util.zip.ZipInputStream zis,
                                java.io.File location)
                         throws java.io.IOException
    unzips an input stream to a specified folder

    Parameters:
    zis - ZipInputStream the source of zipped files
    location - File the folder (directory) where to unzip the files
    Returns:
    boolean true if success, false otherwise

    Example:
  • unzip(Web.getUrlInputStream(new URL(synchronize(new File(myHomeDir), new File(myBackupDir)) will leave the contents of directories myHomeDIr and myBackupDir absolutely identical.
  • Throws:
    java.io.IOException - when something went wrong

    install

    public static boolean install(java.lang.Class clazz,
                                  java.lang.String resourceArchiveName,
                                  java.io.File location)
                           throws java.io.IOException
    installs files from a resource archive Reads a specified resource for aspecified class, unzips it to a specified directory

    Parameters:
    clazz - Class the class whose package contains the archive as a resource
    resourceArchiveName - String the name of resource containing the archive
    location - File directory where the archive is unzipped
    Returns:
    boolean true if success, false if failed
    Throws:
    java.io.IOException - if something goes wrong

    install

    public static boolean install(java.lang.Class clazz,
                                  java.lang.String resourceArchiveName,
                                  java.lang.String folderName)
                           throws java.io.IOException
    installs files from a resource archive Reads a specified resource for aspecified class, unzips it to a specified directory

    Parameters:
    clazz - Class the class whose package contains the archive as a resource
    resourceArchiveName - String the name of resource containing the archive
    Returns:
    boolean true if success, false if failed
    Throws:
    java.io.IOException - if something goes wrong