org.pf.file
Class FileUtil

java.lang.Object
  extended by org.pf.file.FileUtil

public class FileUtil
extends java.lang.Object

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.

Version:
1.8
Author:
Manfred Duchrow

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

LINE_SEPARATOR

public static final java.lang.String LINE_SEPARATOR
The lines.separator from the system properties as a constant


DEFAULT_TEMP_FILE_PREFIX

public static final java.lang.String DEFAULT_TEMP_FILE_PREFIX
The constant that contains the default prefix for temporary file. It is "PFFU" (Programmer's Friend FileUtil).

See Also:
Constant Field Values

DEFAULT_URL_STR_ENCODING

public static final java.lang.String DEFAULT_URL_STR_ENCODING
Contains the default URL string encoding used in this class: "UTF-8"

See Also:
Constant Field Values
Method Detail

current

public static FileUtil current()

copyStream

public void copyStream(java.io.InputStream inStream,
                       java.io.OutputStream outStream)
                throws java.io.IOException
Copies all data from the input stream to the output stream using a buffer with the default size (1024 bytes). After all data is copied both streams will be closed !

Throws:
java.io.IOException

copyStream

public void copyStream(java.io.InputStream inStream,
                       java.io.OutputStream outStream,
                       int bufSize)
                throws java.io.IOException
Copies all data from the iniput stream to the output stream using a buffer of the given size in bytes. After all data is copied both streams will be closed !

Throws:
java.io.IOException

copyFile

public void copyFile(java.io.File sourceFile,
                     java.io.File destFile,
                     boolean preserveTimestamp)
              throws java.io.IOException
Copies the whole contents of the file specified by sourceFile to the file specified by destFile. If destFile already exists, it will be overwritten without warning! If preservetimestamp is true, the last modified time of the destFile will be set to that of the sourceFile. Otherwise it will be the current date.

Parameters:
sourceFile - The file to copy
destFile - The destination where to copy the file content
preserveTimestamp - A flag that indicates if destFile must have the same timestamp as sourceFile
Throws:
java.io.IOException

copyFile

public void copyFile(FileLocator sourceFile,
                     java.io.File destFile,
                     boolean preserveTimestamp)
              throws java.io.IOException
Copies the whole contents of the file specified by sourceFile to the file specified by destFile. If destFile already exists, it will be overwritten without warning! If preservetimestamp is true, the last modified time of the destFile will be set to that of the sourceFile. Otherwise it will be the current date.

Parameters:
sourceFile - The file to copy
destFile - The destination where to copy the file content
preserveTimestamp - A flag that indicates if destFile must have the same timestamp as sourceFile
Throws:
java.io.IOException

copyFile

public void copyFile(java.net.URL source,
                     java.io.File destFile)
              throws java.io.IOException
Copies the whole contents of the file specified by source URL to the file specified by destFile. If destFile already exists, it will be overwritten without warning!

Parameters:
source - An URL that specifies the source file that must be copied
destFile - The destination where to copy the file content
Throws:
java.io.IOException

copyFile

public void copyFile(java.io.File sourceFile,
                     java.io.File destFile)
              throws java.io.IOException
Copies the whole contents of the file specified by sourceFile to the file specified by destFile. If destFile already exists, it will be overwritten without warning! The modification timestamp of destFile will be the current date.

Parameters:
sourceFile - The file to copy
destFile - The destination where to copy the file content
Throws:
java.io.IOException

copyFile

public void copyFile(java.lang.String sourceFilename,
                     java.lang.String destFilename,
                     boolean preserveTimestamp)
              throws java.io.IOException
Copies the whole contents of the file specified by sourceFilename to the file specified by destFilename. If destFilename already exists, it will be overwritten without warning! If preservetimestamp is true, the last modified time of the destFilename will be set to that of the sourceFilename. Otherwise it will be the current date.

Parameters:
sourceFilename - The file to copy
destFilename - The destinition where to copy the file content
preserveTimestamp - A flag that indicates if destFile must have the same timestamp as sourceFile
Throws:
java.io.IOException

copyFile

public void copyFile(java.lang.String sourceFilename,
                     java.lang.String destFilename)
              throws java.io.IOException
Copies the whole contents of the file specified by sourceFilename to the file specified by destFilename. If destFilename already exists, it will be overwritten without warning! The modification timestamp of destFilename will be the current date.

Parameters:
sourceFilename - The file to copy
destFilename - The destinition where to copy the file content
Throws:
java.io.IOException

readTextFrom

public java.lang.String readTextFrom(java.io.InputStream inStream)
                              throws java.io.IOException
Reads the whole content of the given input stream and returns it as a string. The stream will be closed after calling this method. Even if an exception occured!

Parameters:
inStream - The input stream to read
Returns:
The text content of the given stream
Throws:
java.io.IOException

readTextFrom

public java.lang.String readTextFrom(java.lang.String filename)
                              throws java.io.IOException
Reads the whole content of the file with the given name and returns it as a string.

Parameters:
filename - The name of the text containing file
Throws:
java.io.IOException

readTextFrom

public java.lang.String readTextFrom(java.io.File file)
                              throws java.io.IOException
Reads the whole content of the specified file and returns it as a string.

Throws:
java.io.IOException

readTextFrom

public java.lang.String readTextFrom(FileLocator fileLocator)
                              throws java.io.IOException
Reads the whole content of the specified file and returns it as a string.

Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.lang.String filename)
                                     throws java.io.IOException
Reads all text lines from the named file into a String array.

Parameters:
filename - The name of the file from which to read the text lines
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.io.File file)
                                     throws java.io.IOException
Reads all text lines from the specified file into a String array.

Parameters:
file - The file from which to read the text lines
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(FileLocator fileLocator)
                                     throws java.io.IOException
Reads all text lines from the specified file location into a String array.

Parameters:
fileLocator - The file from which to read the text lines
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.io.InputStream inStream)
                                     throws java.io.IOException
Reads all text lines from the specified stream into a String array. After that the stream will be closed. Even if an exception occurs.

Parameters:
inStream - The stream from which to read the text lines
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.io.Reader reader)
                                     throws java.io.IOException
Reads all text lines from the specified reader into a String array. After that the reader will be closed. Even if an exception occurs.

Parameters:
reader - The reader which provides the text
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.lang.String filename,
                                            StringFilter filter)
                                     throws java.io.IOException
Reads all text lines from the named file into a String array.

Parameters:
filename - The name of the file from which to read the text lines
filter - A filter that defines which lines to return (may be null -> all lines)
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.io.File file,
                                            StringFilter filter)
                                     throws java.io.IOException
Reads all text lines matching the filter from the specified file into a String array.

Parameters:
file - The file from which to read the text lines
filter - A filter that defines which lines to return (may be null -> all lines)
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(FileLocator fileLocator,
                                            StringFilter filter)
                                     throws java.io.IOException
Reads all text lines matching the filter from the specified file location into a String array.

Parameters:
fileLocator - The file from which to read the text lines
filter - A filter that defines which lines to return (may be null -> all lines)
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.io.InputStream inStream,
                                            StringFilter filter)
                                     throws java.io.IOException
Reads all text lines matching the filter from the specified stream into a String array. After that the stream will be closed. Even if an exception occurs.

Parameters:
inStream - The stream from which to read the text lines
filter - A filter that defines which lines to return (may be null -> all lines)
Throws:
java.io.IOException

readTextLinesFrom

public java.lang.String[] readTextLinesFrom(java.io.Reader reader,
                                            StringFilter filter)
                                     throws java.io.IOException
Reads all text lines that match the filter from the specified reader into a String array. If the filter is null all lines will be returned. After that the reader will be closed. Even if an exception occurs.

Parameters:
reader - The reader which provides the text
filter - A filter that defines which lines to return (may be null -> all lines)
Throws:
java.io.IOException

copyText

public void copyText(java.io.Reader reader,
                     java.io.StringWriter writer)
              throws java.io.IOException
Copies all text lines from the specified reader to the given writer. After that the reader will be closed. Even if an exception occurs.

Parameters:
reader - The reader which provides the text to copy
writer - The writer to which the text will be copied
Throws:
java.io.IOException

processTextLines

public void processTextLines(java.lang.String filename,
                             LineProcessor processor)
                      throws java.io.IOException
Reads all text lines from the file with the specified name and passes them one by one to the given line processor. The processing will be terminated, if the end of the text is reached or if the processor returns false.

Parameters:
filename - The name of the text file to read
processor - The processor that receives the lines from the text
Throws:
java.io.IOException

processTextLines

public void processTextLines(java.io.InputStream inStream,
                             LineProcessor processor)
                      throws java.io.IOException
Reads all text lines from the specified input stream and passes them one by one to the given line processor. The processing will be terminated, if the end of the text is reached or if the processor returns false.
The given input stream will be closed after the execution of this method. Even if an exception occured.

Parameters:
inStream - The input stream that contains the text
processor - The processor that receives the lines from the text
Throws:
java.io.IOException

processTextLines

public void processTextLines(java.io.Reader reader,
                             LineProcessor processor)
                      throws java.io.IOException
Reads all text lines from the specified reader and passes them one by one to the given line processor. The processing will be terminated, if the end of the text is reached or if the processor returns false.

Parameters:
reader - The reader that contains a text stream
processor - The processor that receives the lines from the text
Throws:
java.io.IOException

close

public boolean close(java.io.InputStream stream)
Close the given stream ignoring any exception. Returns true, if the stream was closed successfully, false otherwise


close

public boolean close(java.io.OutputStream stream)
Close the given stream ignoring any exception. Returns true, if the stream was closed successfully, false otherwise


close

public boolean close(java.io.Reader reader)
Close the given reader ignoring any exception. Returns true, if the reader was closed successfully, false otherwise


close

public boolean close(java.io.Writer writer)
Close the given writer ignoring any exception. Returns true, if the writer was closed successfully, false otherwise


close

public boolean close(java.util.zip.ZipFile zipFile)
Close the given ZIP file ignoring any exception. Returns true, if the ZIP file was closed successfully, false otherwise


standardize

public 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 ('/'). If possible all "." and ".." elements in the path are eliminated.

Parameters:
filename - The filename which has to be standardized
Returns:
An absolute filename that uses slashes to separate its elements

standardize

public 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 ('/'). If possible all "." and ".." elements in the path are eliminated.

Parameters:
filenames - The file names which have to be standardized
Returns:
An new array containing absolute filenames that uses slashes to separate its elements

javaFilename

public java.lang.String javaFilename(java.lang.String filename)
Returns the given filename in the platform independent way that Java understands. That is all elements are separated by a forward slash rather than back slashes.

Parameters:
filename - The name to be modified

javaFilenames

public java.lang.String[] javaFilenames(java.lang.String[] filenames)
Returns a new array of filenames where all backslashes are replaced by forward slashes.

Parameters:
filenames - The file names to be modified
Returns:
The same file names but with forward slashes only

getClasspath

public java.lang.String getClasspath()
Returns the current classpath as String. If this is called from within an Eclipse plug-in the classpath is created from the plug-in dependencies. Otherwise the classpath is taken from the system property "java.class.path" or the manifest file if the application was started with option -jar.


calculateClasspath

public Classpath calculateClasspath()
Returns the current classpath. If this is called from within an Eclipse plug-in the classpath is created from the plug-in dependencies. Otherwise the classpath is taken from the system property "java.class.path" or the manifest file if the application was started with option -jar.

See Also:
getClasspath()

getLookupPath

public 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.

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.

Parameters:
sysPropName - A system property name of null

copyToTempFile

public java.io.File copyToTempFile(java.io.InputStream inStream)
                            throws java.io.IOException
Copies the contents of the given inStream to a temporary file and returns this temporary file. When the VM terminates the temporary file will automatically be deleted if it still exists. The name of the temporary file starts with the default prefix "PFFU" and ends with the default suffix ".tmp".

Parameters:
inStream - The stream to copy into the temporary file
Throws:
java.io.IOException
See Also:
copyToTempFile(InputStream, String), copyToTempFile(InputStream, String, String), copyToTempFile(InputStream, String, String, boolean)

copyToTempFile

public java.io.File copyToTempFile(java.io.InputStream inStream,
                                   java.lang.String filePrefix)
                            throws java.io.IOException
Copies the contents of the given inStream to a temporary file and returns this temporary file. When the VM terminates the temporary file will automatically be deleted if it still exists. The name of the temporary file starts with the given prefix and ends with the default ".tmp".

Parameters:
inStream - The stream to copy into the temporary file
filePrefix - The prefix to be used for the temp file name (must not be null)
Throws:
java.io.IOException
See Also:
copyToTempFile(InputStream), copyToTempFile(InputStream, String, String), copyToTempFile(InputStream, String, String, boolean)

copyToTempFile

public java.io.File copyToTempFile(java.io.InputStream inStream,
                                   java.lang.String filePrefix,
                                   java.lang.String fileSuffix)
                            throws java.io.IOException
Copies the contents of the given inStream to a temporary file and returns this temporary file. When the VM terminates the temporary file will automatically be deleted if it still exists. The name of the temporary file starts with the given prefix and ends with the given suffix.

Parameters:
inStream - The stream to copy into the temporary file
filePrefix - 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)
Throws:
java.io.IOException
See Also:
File.createTempFile(java.lang.String, java.lang.String), copyToTempFile(InputStream), copyToTempFile(InputStream, String), copyToTempFile(InputStream, String, String, boolean)

copyToTempFile

public java.io.File copyToTempFile(java.io.InputStream inStream,
                                   java.lang.String filePrefix,
                                   java.lang.String fileSuffix,
                                   boolean deleteOnExit)
                            throws java.io.IOException
Copies the contents of the given inStream to a temporary file and returns this temporary file. The name of the temporary file starts with the given prefix and ends with the given suffix.

Parameters:
inStream - The stream to copy into the temporary file
filePrefix - 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
Throws:
java.io.IOException
See Also:
File.createTempFile(java.lang.String, java.lang.String), copyToTempFile(InputStream), copyToTempFile(InputStream, String), copyToTempFile(InputStream, String, String)

copyToTempFile

public java.io.File copyToTempFile(java.lang.String filename,
                                   java.lang.String filePrefix,
                                   java.lang.String fileSuffix,
                                   boolean deleteOnExit)
                            throws java.io.IOException
Copies the contents of the file specified by filename to a temporary file and returns this temporary file. The name of the temporary file starts with the given prefix and ends with the given suffix.

Parameters:
filename - The name of the file which to copy into the temporary file
filePrefix - 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
Returns:
The newly created temporary file or null if the input file (filename) cannot be found
Throws:
java.io.IOException
java.lang.IllegalArgumentException - If any input parameter is not ok
See Also:
File.createTempFile(java.lang.String, java.lang.String)

isLocalFileURL

public 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.


isLocal

public boolean isLocal(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) on the local file system. That is, it doesn't contain a protocol prefix such as "http:" or "ftp:".


isRemote

public boolean isRemote(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) on a remote system. That is, it contains a protocol prefix such as "http:" or "ftp:".


isInsideJavaArchive

public boolean isInsideJavaArchive(java.lang.String filename)
Returns true if the given filename specifies a file (or directory) that is located inside a JAR file.


convertToURLSyntax

public java.lang.String convertToURLSyntax(java.lang.String filename)
Converts the given filename to URL syntax. That is, it prepends the scheme "file:" and replaces all illegal URL characters by %xx values. Be aware that this method uses %20 for replacing spaces and not the plus ('+') as the URLEncoder class would do.

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"

Parameters:
filename - The filename to convert

convertFromURLSyntax

public java.lang.String convertFromURLSyntax(java.lang.String filename)
Converts the given filename from URL syntax to normal file system syntax. It removes the scheme and decodes all escaped characters.

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"

Parameters:
filename - The filename to convert

convertFromURLSyntax

public java.io.File convertFromURLSyntax(java.io.File file)
Converts the given file from URL syntax to normal file system syntax.

Examples:
"file:/path/name" -> "/path/name"
"file:\C:\path\name" -> "C:\path\name"
"path/name" -> "path/name"

Parameters:
file - The file to convert

urlDecode

public java.lang.String urlDecode(java.lang.String str)
Returns the given string with all %xx placeholders decoded.

Parameters:
str - The string to decode
Returns:
A UTF-8 string with all %xx placeholders decoded

urlEncode

public 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. In particular it replaces spaces by " %20" rather than '+'! That is reasonable in cases where files in the local file system contain spaces. Such URLs (staring with "file:") cannot open a stream if the URL contains a '+' because the '+' would not be decoded back to a space. That is a bug (or at least an inconsistency) in the URL class implementation.

Parameters:
str - The string to encode
Returns:
A UTF-8 string with all %xx placeholders for invalid URL characters