|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.pf.file.FileUtil
public class FileUtil
This class provides helper methods for file and stream handling. It's an add-on to the java.io package. The service is implemented as a singleton, so use the FileUtil.current() method to get the sole instance.
| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_TEMP_FILE_PREFIX
The constant that contains the default prefix for temporary file. |
static java.lang.String |
DEFAULT_URL_STR_ENCODING
Contains the default URL string encoding used in this class: "UTF-8" |
static java.lang.String |
LINE_SEPARATOR
The lines.separator from the system properties as a constant |
| Method Summary | |
|---|---|
Classpath |
calculateClasspath()
Returns the current classpath. |
boolean |
close(java.io.InputStream stream)
Close the given stream ignoring any exception. |
boolean |
close(java.io.OutputStream stream)
Close the given stream ignoring any exception. |
boolean |
close(java.io.Reader reader)
Close the given reader ignoring any exception. |
boolean |
close(java.io.Writer writer)
Close the given writer ignoring any exception. |
boolean |
close(java.util.zip.ZipFile zipFile)
Close the given ZIP file ignoring any exception. |
java.io.File |
convertFromURLSyntax(java.io.File file)
Converts the given file from URL syntax to normal file system syntax. |
java.lang.String |
convertFromURLSyntax(java.lang.String filename)
Converts the given filename from URL syntax to normal file system syntax. |
java.lang.String |
convertToURLSyntax(java.lang.String filename)
Converts the given filename to URL syntax. |
void |
copyFile(java.io.File sourceFile,
java.io.File destFile)
Copies the whole contents of the file specified by sourceFile to the file specified by destFile. |
void |
copyFile(java.io.File sourceFile,
java.io.File destFile,
boolean preserveTimestamp)
Copies the whole contents of the file specified by sourceFile to the file specified by destFile. |
void |
copyFile(FileLocator sourceFile,
java.io.File destFile,
boolean preserveTimestamp)
Copies the whole contents of the file specified by sourceFile to the file specified by destFile. |
void |
copyFile(java.lang.String sourceFilename,
java.lang.String destFilename)
Copies the whole contents of the file specified by sourceFilename to the file specified by destFilename. |
void |
copyFile(java.lang.String sourceFilename,
java.lang.String destFilename,
boolean preserveTimestamp)
Copies the whole contents of the file specified by sourceFilename to the file specified by destFilename. |
void |
copyFile(java.net.URL source,
java.io.File destFile)
Copies the whole contents of the file specified by source URL to the file specified by destFile. |
void |
copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream)
Copies all data from the input stream to the output stream using a buffer with the default size (1024 bytes). |
void |
copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream,
int bufSize)
Copies all data from the iniput stream to the output stream using a buffer of the given size in bytes. |
void |
copyText(java.io.Reader reader,
java.io.StringWriter writer)
Copies all text lines from the specified reader to the given writer. |
java.io.File |
copyToTempFile(java.io.InputStream inStream)
Copies the contents of the given inStream to a temporary file and returns this temporary file. |
java.io.File |
copyToTempFile(java.io.InputStream inStream,
java.lang.String filePrefix)
Copies the contents of the given inStream to a temporary file and returns this temporary file. |
java.io.File |
copyToTempFile(java.io.InputStream inStream,
java.lang.String filePrefix,
java.lang.String fileSuffix)
Copies the contents of the given inStream to a temporary file and returns this temporary file. |
java.io.File |
copyToTempFile(java.io.InputStream inStream,
java.lang.String filePrefix,
java.lang.String fileSuffix,
boolean deleteOnExit)
Copies the contents of the given inStream to a temporary file and returns this temporary file. |
java.io.File |
copyToTempFile(java.lang.String filename,
java.lang.String filePrefix,
java.lang.String fileSuffix,
boolean deleteOnExit)
Copies the contents of the file specified by filename to a temporary file and returns this temporary file. |
static FileUtil |
current()
|
java.lang.String |
getClasspath()
Returns the current classpath as String. |
Classpath |
getLookupPath(java.lang.String sysPropName)
Returns a class path that is either the value of the specified system property or the classpath calculated from the current Java environment. |
boolean |
isInsideJavaArchive(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) that is located inside a JAR file. |
boolean |
isLocal(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) on the local file system. |
boolean |
isLocalFileURL(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) on the local file system using the URL syntax such as "file:/usr/bin/run" or "file:\C:\temp\readme.txt. |
boolean |
isRemote(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) on a remote system. |
java.lang.String |
javaFilename(java.lang.String filename)
Returns the given filename in the platform independent way that Java understands. |
java.lang.String[] |
javaFilenames(java.lang.String[] filenames)
Returns a new array of filenames where all backslashes are replaced by forward slashes. |
void |
processTextLines(java.io.InputStream inStream,
LineProcessor processor)
Reads all text lines from the specified input stream and passes them one by one to the given line processor. |
void |
processTextLines(java.io.Reader reader,
LineProcessor processor)
Reads all text lines from the specified reader and passes them one by one to the given line processor. |
void |
processTextLines(java.lang.String filename,
LineProcessor processor)
Reads all text lines from the file with the specified name and passes them one by one to the given line processor. |
java.lang.String |
readTextFrom(java.io.File file)
Reads the whole content of the specified file and returns it as a string. |
java.lang.String |
readTextFrom(FileLocator fileLocator)
Reads the whole content of the specified file and returns it as a string. |
java.lang.String |
readTextFrom(java.io.InputStream inStream)
Reads the whole content of the given input stream and returns it as a string. |
java.lang.String |
readTextFrom(java.lang.String filename)
Reads the whole content of the file with the given name and returns it as a string. |
java.lang.String[] |
readTextLinesFrom(java.io.File file)
Reads all text lines from the specified file into a String array. |
java.lang.String[] |
readTextLinesFrom(FileLocator fileLocator)
Reads all text lines from the specified file location into a String array. |
java.lang.String[] |
readTextLinesFrom(FileLocator fileLocator,
StringFilter filter)
Reads all text lines matching the filter from the specified file location into a String array. |
java.lang.String[] |
readTextLinesFrom(java.io.File file,
StringFilter filter)
Reads all text lines matching the filter from the specified file into a String array. |
java.lang.String[] |
readTextLinesFrom(java.io.InputStream inStream)
Reads all text lines from the specified stream into a String array. |
java.lang.String[] |
readTextLinesFrom(java.io.InputStream inStream,
StringFilter filter)
Reads all text lines matching the filter from the specified stream into a String array. |
java.lang.String[] |
readTextLinesFrom(java.io.Reader reader)
Reads all text lines from the specified reader into a String array. |
java.lang.String[] |
readTextLinesFrom(java.io.Reader reader,
StringFilter filter)
Reads all text lines that match the filter from the specified reader into a String array. |
java.lang.String[] |
readTextLinesFrom(java.lang.String filename)
Reads all text lines from the named file into a String array. |
java.lang.String[] |
readTextLinesFrom(java.lang.String filename,
StringFilter filter)
Reads all text lines from the named file into a String array. |
java.lang.String |
standardize(java.lang.String filename)
Convert the filename to a canonical (see java.io.File.getCanonicalPath()) format and replace any backslashes '\' by slashes ('/'). |
java.lang.String[] |
standardize(java.lang.String[] filenames)
Convert all the given filenames to a canonical (see java.io.File.getCanonicalPath()) format and replace any backslashes '\' by slashes ('/'). |
java.lang.String |
urlDecode(java.lang.String str)
Returns the given string with all %xx placeholders decoded. |
java.lang.String |
urlEncode(java.lang.String str)
Returns the given string with all characters that are not allowed directly in URLs encoded as %xx placeholders. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String LINE_SEPARATOR
public static final java.lang.String DEFAULT_TEMP_FILE_PREFIX
public static final java.lang.String DEFAULT_URL_STR_ENCODING
| Method Detail |
|---|
public static FileUtil current()
public void copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream)
throws java.io.IOException
java.io.IOException
public void copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream,
int bufSize)
throws java.io.IOException
java.io.IOException
public void copyFile(java.io.File sourceFile,
java.io.File destFile,
boolean preserveTimestamp)
throws java.io.IOException
sourceFile - The file to copydestFile - The destination where to copy the file contentpreserveTimestamp - A flag that indicates if destFile must have the same timestamp as sourceFile
java.io.IOException
public void copyFile(FileLocator sourceFile,
java.io.File destFile,
boolean preserveTimestamp)
throws java.io.IOException
sourceFile - The file to copydestFile - The destination where to copy the file contentpreserveTimestamp - A flag that indicates if destFile must have the same timestamp as sourceFile
java.io.IOException
public void copyFile(java.net.URL source,
java.io.File destFile)
throws java.io.IOException
source - An URL that specifies the source file that must be copieddestFile - The destination where to copy the file content
java.io.IOException
public void copyFile(java.io.File sourceFile,
java.io.File destFile)
throws java.io.IOException
sourceFile - The file to copydestFile - The destination where to copy the file content
java.io.IOException
public void copyFile(java.lang.String sourceFilename,
java.lang.String destFilename,
boolean preserveTimestamp)
throws java.io.IOException
sourceFilename - The file to copydestFilename - The destinition where to copy the file contentpreserveTimestamp - A flag that indicates if destFile must have the same timestamp as sourceFile
java.io.IOException
public void copyFile(java.lang.String sourceFilename,
java.lang.String destFilename)
throws java.io.IOException
sourceFilename - The file to copydestFilename - The destinition where to copy the file content
java.io.IOException
public java.lang.String readTextFrom(java.io.InputStream inStream)
throws java.io.IOException
inStream - The input stream to read
java.io.IOException
public java.lang.String readTextFrom(java.lang.String filename)
throws java.io.IOException
filename - The name of the text containing file
java.io.IOException
public java.lang.String readTextFrom(java.io.File file)
throws java.io.IOException
java.io.IOException
public java.lang.String readTextFrom(FileLocator fileLocator)
throws java.io.IOException
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.lang.String filename)
throws java.io.IOException
filename - The name of the file from which to read the text lines
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.File file)
throws java.io.IOException
file - The file from which to read the text lines
java.io.IOException
public java.lang.String[] readTextLinesFrom(FileLocator fileLocator)
throws java.io.IOException
fileLocator - The file from which to read the text lines
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.InputStream inStream)
throws java.io.IOException
inStream - The stream from which to read the text lines
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.Reader reader)
throws java.io.IOException
reader - The reader which provides the text
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.lang.String filename,
StringFilter filter)
throws java.io.IOException
filename - The name of the file from which to read the text linesfilter - A filter that defines which lines to return (may be null -> all lines)
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.File file,
StringFilter filter)
throws java.io.IOException
file - The file from which to read the text linesfilter - A filter that defines which lines to return (may be null -> all lines)
java.io.IOException
public java.lang.String[] readTextLinesFrom(FileLocator fileLocator,
StringFilter filter)
throws java.io.IOException
fileLocator - The file from which to read the text linesfilter - A filter that defines which lines to return (may be null -> all lines)
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.InputStream inStream,
StringFilter filter)
throws java.io.IOException
inStream - The stream from which to read the text linesfilter - A filter that defines which lines to return (may be null -> all lines)
java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.Reader reader,
StringFilter filter)
throws java.io.IOException
reader - The reader which provides the textfilter - A filter that defines which lines to return (may be null -> all lines)
java.io.IOException
public void copyText(java.io.Reader reader,
java.io.StringWriter writer)
throws java.io.IOException
reader - The reader which provides the text to copywriter - The writer to which the text will be copied
java.io.IOException
public void processTextLines(java.lang.String filename,
LineProcessor processor)
throws java.io.IOException
filename - The name of the text file to readprocessor - The processor that receives the lines from the text
java.io.IOException
public void processTextLines(java.io.InputStream inStream,
LineProcessor processor)
throws java.io.IOException
inStream - The input stream that contains the textprocessor - The processor that receives the lines from the text
java.io.IOException
public void processTextLines(java.io.Reader reader,
LineProcessor processor)
throws java.io.IOException
reader - The reader that contains a text streamprocessor - The processor that receives the lines from the text
java.io.IOExceptionpublic boolean close(java.io.InputStream stream)
public boolean close(java.io.OutputStream stream)
public boolean close(java.io.Reader reader)
public boolean close(java.io.Writer writer)
public boolean close(java.util.zip.ZipFile zipFile)
public java.lang.String standardize(java.lang.String filename)
filename - The filename which has to be standardized
public java.lang.String[] standardize(java.lang.String[] filenames)
filenames - The file names which have to be standardized
public java.lang.String javaFilename(java.lang.String filename)
filename - The name to be modifiedpublic java.lang.String[] javaFilenames(java.lang.String[] filenames)
filenames - The file names to be modified
public java.lang.String getClasspath()
public Classpath calculateClasspath()
getClasspath()public Classpath getLookupPath(java.lang.String sysPropName)
If the given system property has a lookup path set it will be scanned for ${xxx} placeholders which will be replaced by values of the corresponding system properties.
sysPropName - A system property name of null
public java.io.File copyToTempFile(java.io.InputStream inStream)
throws java.io.IOException
inStream - The stream to copy into the temporary file
java.io.IOExceptioncopyToTempFile(InputStream, String),
copyToTempFile(InputStream, String, String),
copyToTempFile(InputStream, String, String, boolean)
public java.io.File copyToTempFile(java.io.InputStream inStream,
java.lang.String filePrefix)
throws java.io.IOException
inStream - The stream to copy into the temporary filefilePrefix - The prefix to be used for the temp file name (must not be null)
java.io.IOExceptioncopyToTempFile(InputStream),
copyToTempFile(InputStream, String, String),
copyToTempFile(InputStream, String, String, boolean)
public java.io.File copyToTempFile(java.io.InputStream inStream,
java.lang.String filePrefix,
java.lang.String fileSuffix)
throws java.io.IOException
inStream - The stream to copy into the temporary filefilePrefix - The prefix to be used for the temp file name (must not be null)fileSuffix - The prefix to be used for the temp file name (may be null)
java.io.IOExceptionFile.createTempFile(java.lang.String, java.lang.String),
copyToTempFile(InputStream),
copyToTempFile(InputStream, String),
copyToTempFile(InputStream, String, String, boolean)
public java.io.File copyToTempFile(java.io.InputStream inStream,
java.lang.String filePrefix,
java.lang.String fileSuffix,
boolean deleteOnExit)
throws java.io.IOException
inStream - The stream to copy into the temporary filefilePrefix - The prefix to be used for the temp file name (must not be null)fileSuffix - The prefix to be used for the temp file name (may be null)deleteOnExit - If true the temporary file will be deleted when the VM terminates
java.io.IOExceptionFile.createTempFile(java.lang.String, java.lang.String),
copyToTempFile(InputStream),
copyToTempFile(InputStream, String),
copyToTempFile(InputStream, String, String)
public java.io.File copyToTempFile(java.lang.String filename,
java.lang.String filePrefix,
java.lang.String fileSuffix,
boolean deleteOnExit)
throws java.io.IOException
filename - The name of the file which to copy into the temporary filefilePrefix - The prefix to be used for the temp file name (must not be null)fileSuffix - The prefix to be used for the temp file name (may be null)deleteOnExit - If true the temporary file will be deleted when the VM terminates
java.io.IOException
java.lang.IllegalArgumentException - If any input parameter is not okFile.createTempFile(java.lang.String, java.lang.String)public boolean isLocalFileURL(java.lang.String filename)
public boolean isLocal(java.lang.String filename)
public boolean isRemote(java.lang.String filename)
public boolean isInsideJavaArchive(java.lang.String filename)
public java.lang.String convertToURLSyntax(java.lang.String filename)
Examples:
"/path/name" -> "file:/path/name"
"C:\path\name" -> "file:/C:/path/name"
"path/name" -> "file:path/name"
"C:\\folder name\\filename{v1}" -> "file:/C:/folder%20name/filename%7bv1%7d"
filename - The filename to convertpublic java.lang.String convertFromURLSyntax(java.lang.String filename)
Examples:
"file:/path/name" -> "/path/name"
"file:\C:\path\name" -> "C:\path\name"
"path/name" -> "path/name"
"file:/C:/Program+Files/settings.ini" -> "C:\Program Files\settings.ini"
filename - The filename to convertpublic java.io.File convertFromURLSyntax(java.io.File file)
Examples:
"file:/path/name" -> "/path/name"
"file:\C:\path\name" -> "C:\path\name"
"path/name" -> "path/name"
file - The file to convertpublic java.lang.String urlDecode(java.lang.String str)
str - The string to decode
public java.lang.String urlEncode(java.lang.String str)
str - The string to encode
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||