public class FileUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASSPATH_PREFIX
Defines the prefix that specifies that the remaining part of the
string with that prefix is a file name that must be looked-up
using the current classloader: "classpath:".
|
static int |
DEFAULT_BUFFER_SIZE |
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"
|
protected static StringPattern |
DRIVE_LETTER_PATTERN_1 |
protected static StringPattern |
DRIVE_LETTER_PATTERN_2 |
protected static java.lang.String |
FILE_PROTOCOL_INDICATOR |
static FileUtil |
FU |
protected static StringPattern |
JAR_PATTERN |
static java.lang.String |
LINE_SEPARATOR
The lines.separator from the system properties as a constant
|
protected static StringPattern |
LOCAL_PATTERN |
protected static java.lang.Long |
NO_LIMIT |
protected static StringPattern |
REMOTE_PATTERN |
protected static StringPattern |
WINDOWS_DRIVE_PATTERN_1 |
protected static StringPattern |
WINDOWS_DRIVE_PATTERN_2 |
Modifier | Constructor and Description |
---|---|
protected |
FileUtil()
Initialize the new instance with default values.
|
|
FileUtil(java.lang.ClassLoader classLoader)
Create a new instance with with an external classloader.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendClasspathEntriesFrom(java.util.Collection<java.lang.String> elements,
java.lang.Object bundleLoader) |
protected void |
assertArgumentNotNull(java.lang.String argName,
java.lang.Object arg) |
Classpath |
calculateClasspath()
Returns the current classpath.
|
protected Classpath |
calculateEclipseClasspath() |
protected java.lang.String |
classpathFromManifest(java.lang.String jarFilename)
Returns the classpath definition from the manifest file in the specified
JAR or null if not found.
|
long |
cleanDirectory(java.io.File dir)
Deletes all files and sub-directories in the given directory.
|
long |
cleanDirectory(java.io.File dir,
boolean filesOnly)
Deletes all files (and optionally sub-directories) in the given directory.
|
boolean |
close(java.io.Closeable closeable)
Close the given closeable ignoring any exception and checking for null before closing.
|
boolean |
close(java.util.zip.ZipFile zipFile)
Close the given ZIP file ignoring any exception.
|
boolean |
closeEntry(java.util.zip.ZipInputStream zipInStream)
Close the current entry in the given ZIP input stream ignoring any exception.
|
boolean |
closeEntry(java.util.zip.ZipOutputStream zipOutStream)
Close the current entry in the given ZIP output stream ignoring any exception.
|
protected java.lang.String |
constructClasspathFrom(java.lang.String jarFilename) |
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.
|
long |
copyAll(java.io.File sourceFolder,
java.io.File targetFolder)
Copies all files and folders (recursively) from the sourceFolder
to the targetFolder.
|
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 (4096 bytes).
|
void |
copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream,
int bufSize)
Copies all data from the input stream to the output stream using
a buffer of the given size in bytes.
|
void |
copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream,
int bufSize,
java.lang.Long limit)
Copies all data from the input stream to the output stream using
a buffer of the given size in bytes.
|
protected void |
copyText(java.io.InputStream inStream,
java.nio.charset.Charset charset,
java.io.StringWriter writer) |
protected void |
copyText(java.io.InputStream inStream,
CheckedCharsetName charsetName,
java.io.StringWriter writer) |
protected void |
copyText(java.io.InputStream inStream,
java.io.StringWriter writer) |
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.
|
protected java.lang.String |
createClasspathFrom(java.lang.String path) |
void |
createFile(java.io.File file,
byte... content)
Creates the file and writes the given content to it.
|
void |
createFile(java.io.InputStream inStream,
java.io.File file)
Creates the file and writes the given stream to it.
|
void |
createFile(java.io.InputStream inStream,
java.io.File file,
int bufferSize,
java.lang.Long limit)
Creates the file and writes the given stream to it.
|
protected Classpath |
createSystemClasspath() |
static FileUtil |
current()
Returns the default instance of this class.
|
protected Classpath |
determineLookupClasspath(java.lang.String sysPropName) |
boolean |
ensureEmptyFolder(java.io.File folder)
Ensures that the specified folder exists and is empty.
|
boolean |
ensureFolderExists(java.io.File folder)
Ensures that the specified folder exists.
|
void |
extractZipArchive(java.io.File zipFile,
java.io.File destDir)
Copies all files from the given zip archive to the specified
destination directory.
|
void |
extractZipArchive(java.io.File zipFile,
java.io.File destDir,
IZipEntryFilter filter)
Copies all files from the given zip archive that match the given filter to the specified
destination directory.
|
void |
extractZipArchive(java.util.zip.ZipInputStream zipInStream,
java.io.File destDir,
IZipEntryFilter filter)
Copies all files from the given zip archive that match the given filter to the specified
destination directory.
|
java.util.Collection<java.lang.String> |
findZippedFiles(java.io.File zipFile,
IZipEntryFilter filter)
Returns all (full-path) names of file entries in the given zipFile that match the specified filter.
|
java.lang.String |
getClasspath()
Returns the current classpath as String.
|
protected java.lang.String |
getClasspathFromSystemProperty()
Returns the classpath this JVM is using.
|
protected java.lang.ClassLoader |
getCurrentClassLoader() |
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.
|
java.lang.String |
getRelativePath(java.io.File dir,
java.io.File fileBelowDir)
Returns the relative path of the given fileBelowDir in relation to the specified directory.
|
protected void |
handleException(java.lang.Exception ex) |
protected int |
indexOfPreceedingNotNullElement(java.lang.String[] elements,
int start) |
protected IOUtil |
ioUtil() |
boolean |
isExistingFolder(java.io.File folder)
Returns true if the given folder is an existing folder on the file system.
|
boolean |
isExistingFolder(java.lang.String path)
Returns true if the given path is an existing folder on the file system.
|
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.
|
IConfigSettings |
loadNamedValuesFrom(java.lang.String filename)
Loads all properties form the file with the given name.
If the filename contains the prefix "classpath:" then it will be looked-up using the underlying current classloader. |
java.util.Properties |
loadPropertiesFrom(java.lang.String filename)
Loads all properties form the file with the given name.
If the filename contains the prefix "classpath:" the it will be looked-up using the underlying current classloader. |
java.io.InputStream |
openFile(java.lang.String filename)
Opens the file with the given name and returns it as an input stream.
If the filename contains the prefix "classpath:" then it will be looked-up using the underlying current classloader. |
NamedInputStream |
openFileForRead(java.lang.String filename)
Opens the file with the given name and returns it as a named input stream.
If the filename contains the prefix "classpath:" then it will be looked-up using the underlying current classloader. |
void |
processTextLines(java.io.InputStream inStream,
java.nio.charset.Charset charset,
ILineProcessor 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.InputStream inStream,
ICheckedCharset charsetName,
ILineProcessor 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.InputStream inStream,
ILineProcessor 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,
ILineProcessor 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,
ICheckedCharset charsetName,
ILineProcessor processor)
Reads all text lines from the file with the specified name and passes them
one by one to the given line processor.
|
void |
processTextLines(java.lang.String filename,
ILineProcessor 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(java.io.File file,
java.nio.charset.Charset charset)
Reads the whole content of the specified file and returns
it as a string.
|
java.lang.String |
readTextFrom(java.io.File file,
ICheckedCharset charsetName)
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(FileLocator fileLocator,
java.nio.charset.Charset charset)
Reads the whole content of the specified file and returns
it as a string.
|
java.lang.String |
readTextFrom(FileLocator fileLocator,
ICheckedCharset charsetName)
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.io.InputStream inStream,
java.nio.charset.Charset charset)
Reads the whole content of the given input stream and returns
it as a string.
|
java.lang.String |
readTextFrom(java.io.InputStream inStream,
ICheckedCharset charsetName)
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 |
readTextFrom(java.lang.String filename,
java.nio.charset.Charset charset)
Reads the whole content of the file with the given name and returns
it as a string.
|
java.lang.String |
readTextFrom(java.lang.String filename,
ICheckedCharset charsetName)
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(java.io.File file,
java.nio.charset.Charset charset)
Reads all text lines from the specified file into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.io.File file,
java.nio.charset.Charset charset,
IStringFilter filter)
Reads all text lines matching the filter from the specified file into a
String array.
|
java.lang.String[] |
readTextLinesFrom(java.io.File file,
ICheckedCharset charsetName)
Reads all text lines from the specified file into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.io.File file,
ICheckedCharset charsetName,
IStringFilter filter)
Reads all text lines matching the filter from the specified file into a
String array.
|
java.lang.String[] |
readTextLinesFrom(java.io.File file,
IStringFilter filter)
Reads all text lines matching the filter 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,
java.nio.charset.Charset charset,
IStringFilter filter)
Reads all text lines matching the filter from the specified file location
into a String array.
|
java.lang.String[] |
readTextLinesFrom(FileLocator fileLocator,
ICheckedCharset charsetName)
Reads all text lines from the specified file location into a String array.
|
java.lang.String[] |
readTextLinesFrom(FileLocator fileLocator,
ICheckedCharset charsetName,
IStringFilter filter)
Reads all text lines matching the filter from the specified file location
into a String array.
|
java.lang.String[] |
readTextLinesFrom(FileLocator fileLocator,
IStringFilter filter)
Reads all text lines matching the filter from the specified file location
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,
java.nio.charset.Charset charset)
Reads all text lines from the specified stream into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.io.InputStream inStream,
java.nio.charset.Charset charset,
IStringFilter filter)
Reads all text lines matching the filter from the specified stream into a
String array using the specified character encoding.
|
java.lang.String[] |
readTextLinesFrom(java.io.InputStream inStream,
ICheckedCharset charsetName)
Reads all text lines from the specified stream into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.io.InputStream inStream,
ICheckedCharset charsetName,
IStringFilter filter)
Reads all text lines matching the filter from the specified stream into a
String array using the specified character encoding.
|
java.lang.String[] |
readTextLinesFrom(java.io.InputStream inStream,
IStringFilter 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,
IStringFilter 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,
java.nio.charset.Charset charset)
Reads all text lines from the named file into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.lang.String filename,
java.nio.charset.Charset charset,
IStringFilter filter)
Reads all text lines from the named file into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.lang.String filename,
ICheckedCharset charsetName)
Reads all text lines from the named file into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.lang.String filename,
ICheckedCharset charsetName,
IStringFilter filter)
Reads all text lines from the named file into a String array.
|
java.lang.String[] |
readTextLinesFrom(java.lang.String filename,
IStringFilter filter)
Reads all text lines from the named file into a String array.
|
protected ReflectUtil |
reflect() |
long |
removeDirectory(java.io.File dir)
Deletes all files and sub-directories in the given directory and the directory itself.
|
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 ('/').
|
protected java.lang.String |
standardizeFilename(java.lang.String filename) |
protected StringUtil |
str() |
java.lang.String |
urlDecode(java.lang.String str)
Returns the given string with all %xx placeholders decoded.
|
java.lang.String |
urlDecode(java.lang.String str,
ICheckedCharset charsetName)
Returns the given string with all %xx placeholders decoded using the
specified charset encoding.
|
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.
|
java.lang.String |
urlEncode(java.lang.String str,
ICheckedCharset charsetName)
Returns the given string with all characters that are not allowed directly
in URLs encoded as %xx placeholders.
|
public static final FileUtil FU
public static final java.lang.String LINE_SEPARATOR
public static final int DEFAULT_BUFFER_SIZE
public static final java.lang.String DEFAULT_TEMP_FILE_PREFIX
public static final java.lang.String DEFAULT_URL_STR_ENCODING
public static final java.lang.String CLASSPATH_PREFIX
protected static final java.lang.String FILE_PROTOCOL_INDICATOR
protected static final StringPattern LOCAL_PATTERN
protected static final StringPattern REMOTE_PATTERN
protected static final StringPattern JAR_PATTERN
protected static final StringPattern DRIVE_LETTER_PATTERN_1
protected static final StringPattern DRIVE_LETTER_PATTERN_2
protected static final StringPattern WINDOWS_DRIVE_PATTERN_1
protected static final StringPattern WINDOWS_DRIVE_PATTERN_2
protected static final java.lang.Long NO_LIMIT
public FileUtil(java.lang.ClassLoader classLoader)
protected FileUtil()
public static FileUtil current()
public void createFile(java.io.File file, byte... content) throws java.io.IOException
file
- The file to be created (must not be null).content
- The (optional) content to be written to the file.java.io.IOException
public void createFile(java.io.InputStream inStream, java.io.File file) throws java.io.IOException
inStream
- The stream to be written to the file.file
- The file to be created (must not be null).java.io.IOException
public void createFile(java.io.InputStream inStream, java.io.File file, int bufferSize, java.lang.Long limit) throws java.io.IOException
inStream
- The stream to be written to the file.file
- The file to be created (must not be null).bufferSize
- The size of the buffer that is used for the transfer of byte chunks (must be a positive value).limit
- The maximum number of bytes that will be copied. If exceeded an IOException will be thrown.
Setting this parameter to null, zero or a negative value will specify no limit.java.io.IOException
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 copyStream(java.io.InputStream inStream, java.io.OutputStream outStream, int bufSize, java.lang.Long limit) throws java.io.IOException
inStream
- The source stream.outStream
- The target stream.bufSize
- The size of the buffer that is used for the transfer of byte chunks (must be positive value).limit
- The maximum number of bytes that will be copied. If exceeded an IOException will be thrown.
Setting this parameter to null, zero or a negative value will specify no limit.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 sourceFilejava.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 sourceFilejava.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 contentjava.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 contentjava.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 sourceFilejava.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 contentjava.io.IOException
public long copyAll(java.io.File sourceFolder, java.io.File targetFolder)
public java.util.Collection<java.lang.String> findZippedFiles(java.io.File zipFile, IZipEntryFilter filter) throws java.io.IOException
zipFile
- The zip file to look for the matching entries (must not be null).filter
- The filter that defines which names to return (must not be null).java.io.IOException
- In case of errors with the zip file handling.public void extractZipArchive(java.io.File zipFile, java.io.File destDir) throws java.io.IOException
zipFile
- The file to be extracted (must not be null).destDir
- The file directory to which to extract the files (must not be null).java.io.IOException
public void extractZipArchive(java.io.File zipFile, java.io.File destDir, IZipEntryFilter filter) throws java.io.IOException
zipFile
- The file to be extracted (must not be null).destDir
- The file directory to which to extract the files (must not be null).filter
- An optional filter - only matching entries will be extracted (may be null for all matching).java.io.IOException
public void extractZipArchive(java.util.zip.ZipInputStream zipInStream, java.io.File destDir, IZipEntryFilter filter) throws java.io.IOException
zipInStream
- The opened stream on the zip file to be extracted (must not be null).destDir
- The file directory to which to extract the files (must not be null).filter
- An optional filter - only matching entries will be extracted (may be null for all matching).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.io.InputStream inStream, ICheckedCharset charsetName) throws java.io.IOException
inStream
- The input stream to read (must not be null).charsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String readTextFrom(java.io.InputStream inStream, java.nio.charset.Charset charset) throws java.io.IOException
inStream
- The input stream to read (must not be null).charset
- A character set defining the encoding of the stream (must not be null).java.io.IOException
public java.lang.String readTextFrom(java.lang.String filename) throws java.io.IOException
filename
- The name of the text containing filejava.io.IOException
public java.lang.String readTextFrom(java.lang.String filename, java.nio.charset.Charset charset) throws java.io.IOException
filename
- The name of the text containing file (must not be null).charset
- A character set defining the file encoding (must not be null).java.io.IOException
public java.lang.String readTextFrom(java.lang.String filename, ICheckedCharset charsetName) throws java.io.IOException
filename
- The name of the text containing filecharsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String readTextFrom(java.io.File file) throws java.io.IOException
java.io.IOException
public java.lang.String readTextFrom(java.io.File file, ICheckedCharset charsetName) throws java.io.IOException
file
- The text file from which to read (must not be null).charsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String readTextFrom(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
file
- The text file from which to read (must not be null).charset
- A character set defining the file encoding (must not be null).java.io.IOException
public java.lang.String readTextFrom(FileLocator fileLocator) throws java.io.IOException
java.io.IOException
public java.lang.String readTextFrom(FileLocator fileLocator, ICheckedCharset charsetName) throws java.io.IOException
fileLocator
- The locator of the text file to read (must not be null).charsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String readTextFrom(FileLocator fileLocator, java.nio.charset.Charset charset) throws java.io.IOException
fileLocator
- The locator of the text file to read (must not be null).charset
- A character set defining the encoding of the file (must not be null).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 linesjava.io.IOException
public java.lang.String[] readTextLinesFrom(java.lang.String filename, ICheckedCharset charsetName) throws java.io.IOException
filename
- The name of the file from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String[] readTextLinesFrom(java.lang.String filename, java.nio.charset.Charset charset) throws java.io.IOException
filename
- The name of the file from which to read the text lines (must not be null).charset
- A character set defining the encoding of the file (must not be null).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(java.io.File file, ICheckedCharset charsetName) throws java.io.IOException
file
- The file from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
file
- The file from which to read the text lines (must not be null).charset
- A character set defining the encoding of the file (must not be null).java.io.IOException
public java.lang.String[] readTextLinesFrom(FileLocator fileLocator) throws java.io.IOException
fileLocator
- The file from which to read the text linesjava.io.IOException
public java.lang.String[] readTextLinesFrom(FileLocator fileLocator, ICheckedCharset charsetName) throws java.io.IOException
fileLocator
- The file from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).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 linesjava.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.InputStream inStream, ICheckedCharset charsetName) throws java.io.IOException
inStream
- The stream from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.InputStream inStream, java.nio.charset.Charset charset) throws java.io.IOException
inStream
- The stream from which to read the text lines (must not be null).charset
- A character set defining the encoding of the stream (must not be null).java.io.IOException
public java.lang.String[] readTextLinesFrom(java.io.Reader reader) throws java.io.IOException
reader
- The reader which provides the textjava.io.IOException
public java.lang.String[] readTextLinesFrom(java.lang.String filename, IStringFilter 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.lang.String filename, ICheckedCharset charsetName, IStringFilter filter) throws java.io.IOException
filename
- The name of the file from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).filter
- A filter that defines which lines to return (may be null -> all lines)java.io.IOException
public java.lang.String[] readTextLinesFrom(java.lang.String filename, java.nio.charset.Charset charset, IStringFilter filter) throws java.io.IOException
filename
- The name of the file from which to read the text linescharset
- A character set defining the file encoding (must not be null).filter
- 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, IStringFilter 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(java.io.File file, ICheckedCharset charsetName, IStringFilter filter) throws java.io.IOException
file
- The file from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).filter
- 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, java.nio.charset.Charset charset, IStringFilter filter) throws java.io.IOException
file
- The file from which to read the text lines (must not be null).charset
- A character set defining the encoding of the file (must not be null).filter
- A filter that defines which lines to return (may be null -> all lines)java.io.IOException
public java.lang.String[] readTextLinesFrom(FileLocator fileLocator, IStringFilter 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(FileLocator fileLocator, ICheckedCharset charsetName, IStringFilter filter) throws java.io.IOException
fileLocator
- The file from which to read the text linescharsetName
- A charset name already checked to be supported (must not be null).filter
- A filter that defines which lines to return (may be null -> all lines)java.io.IOException
public java.lang.String[] readTextLinesFrom(FileLocator fileLocator, java.nio.charset.Charset charset, IStringFilter filter) throws java.io.IOException
fileLocator
- The file from which to read the text lines (must not be null).charset
- A character set defining the file encoding (must not be null).filter
- 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, IStringFilter 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.InputStream inStream, ICheckedCharset charsetName, IStringFilter filter) throws java.io.IOException
inStream
- The stream from which to read the text lines.charsetName
- A charset name already checked to be supported (must not be null).filter
- 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, java.nio.charset.Charset charset, IStringFilter filter) throws java.io.IOException
inStream
- The stream from which to read the text lines (must not be null).charset
- A character set defining the encoding of the input stream (must not be null).filter
- 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, IStringFilter 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 copiedjava.io.IOException
public void processTextLines(java.lang.String filename, ILineProcessor processor) throws java.io.IOException
filename
- The name of the text file to readprocessor
- The processor that receives the lines from the textjava.io.IOException
public void processTextLines(java.lang.String filename, ICheckedCharset charsetName, ILineProcessor processor) throws java.io.IOException
filename
- The name of the text file to readcharsetName
- A charset name already checked to be supported (must not be null).processor
- The processor that receives the lines from the textjava.io.IOException
public void processTextLines(java.io.InputStream inStream, ILineProcessor processor) throws java.io.IOException
inStream
- The input stream that contains the textprocessor
- The processor that receives the lines from the textjava.io.IOException
public void processTextLines(java.io.InputStream inStream, ICheckedCharset charsetName, ILineProcessor processor) throws java.io.IOException
inStream
- The input stream that contains the text (must not be null).charsetName
- A charset name already checked to be supported (must not be null).processor
- The processor that receives the lines from the text (must not be null).java.io.IOException
public void processTextLines(java.io.InputStream inStream, java.nio.charset.Charset charset, ILineProcessor processor) throws java.io.IOException
inStream
- The input stream that contains the text (must not be null).charset
- A character set defining the encoding of the stream (must not be null).processor
- The processor that receives the lines from the text (must not be null).java.io.IOException
public void processTextLines(java.io.Reader reader, ILineProcessor processor) throws java.io.IOException
reader
- The reader that contains a text streamprocessor
- The processor that receives the lines from the textjava.io.IOException
public boolean close(java.util.zip.ZipFile zipFile)
public boolean closeEntry(java.util.zip.ZipInputStream zipInStream)
public boolean closeEntry(java.util.zip.ZipOutputStream zipOutStream)
public boolean close(java.io.Closeable closeable)
public java.lang.String standardize(java.lang.String filename)
filename
- The filename which has to be standardizedpublic java.lang.String[] standardize(java.lang.String[] filenames)
filenames
- The file names which have to be standardizedpublic 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 modifiedpublic 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 nullpublic java.io.File copyToTempFile(java.io.InputStream inStream) throws java.io.IOException
inStream
- The stream to copy into the temporary filejava.io.IOException
copyToTempFile(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.IOException
copyToTempFile(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.IOException
File.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 terminatesjava.io.IOException
File.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 terminatesjava.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, ICheckedCharset charsetName)
str
- The string to decode.charsetName
- The name of the charset to be used for decoding.public java.lang.String urlDecode(java.lang.String str)
str
- The string to decodepublic java.lang.String urlEncode(java.lang.String str, ICheckedCharset charsetName)
str
- The string to encode.charsetName
- The name of the charset to be used for encoding.public java.lang.String urlEncode(java.lang.String str)
str
- The string to encode.public long removeDirectory(java.io.File dir)
dir
- The directory under which all files must be deleted (must not be null).public long cleanDirectory(java.io.File dir)
dir
- The directory under which all files must be deleted (must not be null).public long cleanDirectory(java.io.File dir, boolean filesOnly)
dir
- The directory under which all files must be deleted (must not be null).filesOnly
- If true only files will be deleted, if false sub-directories will be deleted as well.public java.io.InputStream openFile(java.lang.String filename) throws java.io.FileNotFoundException
Without that prefix it will be treated as normal file on the file system (relative or absolute).
filename
- The file to open (must not be null). It may contain a path (with slashes).java.io.FileNotFoundException
public NamedInputStream openFileForRead(java.lang.String filename) throws java.io.FileNotFoundException
Without that prefix it will be treated as normal file on the file system (relative or absolute).
filename
- The file to open (must not be null). It may contain a path (with slashes).java.io.FileNotFoundException
public java.util.Properties loadPropertiesFrom(java.lang.String filename) throws java.io.IOException
Without that prefix it will be treated as normal file on the file system (relative or absolute).
filename
- The properties file (must not be null). It may contain a path (with slashes).java.io.IOException
public IConfigSettings loadNamedValuesFrom(java.lang.String filename) throws java.io.IOException
Without that prefix it will be treated as normal file on the file system (relative or absolute).
filename
- The properties file (must not be null). It may contain a path (with slashes).java.io.IOException
public boolean ensureEmptyFolder(java.io.File folder)
public boolean ensureFolderExists(java.io.File folder)
public boolean isExistingFolder(java.lang.String path)
public boolean isExistingFolder(java.io.File folder)
public java.lang.String getRelativePath(java.io.File dir, java.io.File fileBelowDir)
dir
- The directory under which the file is supposed to be located (must not be null).fileBelowDir
- The file under the given dir somewhere down the hierarchy of sub-directories (must not be null).protected void copyText(java.io.InputStream inStream, java.io.StringWriter writer) throws java.io.IOException
java.io.IOException
protected void copyText(java.io.InputStream inStream, CheckedCharsetName charsetName, java.io.StringWriter writer) throws java.io.IOException
java.io.IOException
protected void copyText(java.io.InputStream inStream, java.nio.charset.Charset charset, java.io.StringWriter writer) throws java.io.IOException
java.io.IOException
protected java.lang.String standardizeFilename(java.lang.String filename)
protected int indexOfPreceedingNotNullElement(java.lang.String[] elements, int start)
protected java.lang.String classpathFromManifest(java.lang.String jarFilename)
protected java.lang.String constructClasspathFrom(java.lang.String jarFilename)
protected Classpath calculateEclipseClasspath()
protected void appendClasspathEntriesFrom(java.util.Collection<java.lang.String> elements, java.lang.Object bundleLoader)
protected java.lang.String getClasspathFromSystemProperty()
protected Classpath determineLookupClasspath(java.lang.String sysPropName)
protected Classpath createSystemClasspath()
protected java.lang.String createClasspathFrom(java.lang.String path)
protected void assertArgumentNotNull(java.lang.String argName, java.lang.Object arg)
protected java.lang.ClassLoader getCurrentClassLoader()
protected IOUtil ioUtil()
protected StringUtil str()
protected ReflectUtil reflect()
protected void handleException(java.lang.Exception ex)