|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectinfo.monitorenter.util.FileUtil
public class FileUtil
| Constructor Summary | |
|---|---|
FileUtil()
Defcon. |
|
| Method Summary | |
|---|---|
static Map.Entry |
cutDirectoryInformation(String path)
Cuts the path information of the String that is interpreted as a filename into the directory part and the file part. |
static Map.Entry |
cutDirectoryInformation(URL path)
Cuts all path information of the String representation of the given URL. |
static Map.Entry |
cutExtension(String filename)
Cuts a String into the part before the last dot and after the last dot. |
static String |
getDefaultFileName(String name)
Finds a filename based on the given name. |
static boolean |
isAllASCII(File f)
Tests wether the given file only contains ASCII characters if interpreted by reading bytes (16 bit). |
static boolean |
isAllASCII(InputStream in)
Tests wether the given input stream only contains ASCII characters if interpreted by reading bytes (16 bit). |
static boolean |
isEqual(File document,
Charset a,
Charset b)
Tests, wether the content of the given file is identical at character level, when it is opened with both different Charsets. |
static InputStream |
readCache(File f)
Invokes readRAM(File), but decorates the result with a
ByteArrayInputStream. |
static byte[] |
readRAM(File f)
Reads the content of the given File into an array. |
static byte[] |
readRAM(InputStream in)
Reads all bytes of content of the given InputStream into an
array. |
static byte[] |
readRAM(InputStream in,
int length)
Reads length of bytes of content of the given
InputStream into an array. |
static void |
removeDuplicateLineBreaks(File f)
Be careful with big files: In order to avoid having to write a tmpfile (cannot read and directly write to the same file) a StringBuffer is used for manipulation. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static void removeDuplicateLineBreaks(File f)
public static String getDefaultFileName(String name)
Else:
"myFile.out" --> "myFile_0.out" "myFile_0.out" --> "myFile_1.out" "myFile_1.out" --> "myFile_2.out" ....
The potential extension is preserved, but a number is appended to the prefix name.
name - A desired file name.
public static Map.Entry cutExtension(String filename)
Map.Entry entry = FileUtil.getPotentialExtension("A.Very.Strange.Name.txt");
String prefix = (String)entry.getKey(); // prefix is "A.Very.Strange.Name".
String suffix = (String)entry.getValue(); // suffix is "txt";
entry = FileUtil.getPotentialExtension(".profile");
String prefix = (String)entry.getKey(); // prefix is ".profile".
String suffix = (String)entry.getValue(); // suffix is "";
entry = FileUtil.getPotentialExtension("bash");
String prefix = (String)entry.getKey(); // prefix is "bash".
String suffix = (String)entry.getValue(); // suffix is "";
filename - A String that is interpreted to be a file name: The last dot ('.')
is interpreted to be the extension delimiter.
public static Map.Entry cutDirectoryInformation(String path)
"c:/work/programming/anyfile.jar --> Map.Entry("c:/work/programming/","anyfile.jar");
"anyfile.jar" --> Map.Entry(new File(".").getAbsolutePath(),"anyfile.jar");
"c:/directory1/directory2/" --> Map.Entry("c:/directory1/directory2/","");
"c:/directory1/directory2" --> Map.Entry("c:/directory1/directory2/",""); // directory2 is a dir!
"c:/directory1/file2" --> Map.Entry("c:/directory1/","file2"); // file2 is a file!
"c:/" --> Map.Entry("c:/","");
Assuming, that '/' is the current file separator character.
If your string is retrieved from an URL instance, use cutDirectoryInformation(URL path) instead, because URL's do not depend on the operating systems file separator!
path - the absolute file path you want the mere file name of.
Map.Entry consisting of path information
and file name.public static Map.Entry cutDirectoryInformation(URL path)
"file//c:/work/programming/anyfile.jar --> "anyfile.jar"
"http://jamwg.de" --> "" // No file part.
"ftp://files.com/directory2/ --> "" // File part of URL denotes a directory.
Assuming, that '/' is the current file separator character.
path - the absolute file path you want the mere file name of.
Map.Entry consisting of path information
and file name.
public static byte[] readRAM(File f)
throws IOException
This method currently does not check for maximum length and might cause a java.lang.OutOfMemoryError. It is only intended for performance-measurements of data-based algorithms that want to exclude I/O-usage.
Warning: This method will fail for big files to to memory problems or an
carry overflow when downcasting long of file.length() to
int.
IOException
public static byte[] readRAM(InputStream in,
int length)
throws IOException
length of bytes of content of the given
InputStream into an array.
This method currently does not check for maximum length and might cause a java.lang.OutOfMemoryError. It is only intended for performance-measurements of data-based algorithms that want to exclude I/O-usage.
in - the input stream to read.length - the amount of bytes to read from the input stream.
IOException - if sth goes wrong.
public static byte[] readRAM(InputStream in)
throws IOException
InputStream into an
array.
This method currently does not check for maximum length and might cause a java.lang.OutOfMemoryError. It is only intended for performance-measurements of data-based algorithms that want to exclude I/O-usage.
If you know the amount of bytes in the given
prefer invoking
InputStream as it performs much
better. This implementation first as to use a buffer that grows dynamically
and then allocate an array and copy all content as the length is unknown.
readRAM(InputStream, int)
in - the input stream to read.
IOException - if something goes wrong.readRAM(InputStream, int)
public static InputStream readCache(File f)
throws IOException
readRAM(File), but decorates the result with a
ByteArrayInputStream.
This means: The complete content of the given File has been loaded before using the returned InputStream. There are no IO-delays afterwards but OutOfMemoryErrors may occur.
f - the file to cache.
IOException
public static boolean isAllASCII(File f)
throws IOException
This does not mean that the file is really an ASCII text file. It just might be viewed with an editor showing only valid ASCII characters.
f - the file to test.
IOException - on a bad day.
public static boolean isAllASCII(InputStream in)
throws IOException
This does not mean that the underlying content is really an ASCII text file. It just might be viewed with an editor showing only valid ASCII characters.
in - the stream to test.
IOException - on a bad day.
public static boolean isEqual(File document,
Charset a,
Charset b)
throws IOException
This is most often the case, if the given file only contains ASCII codes but may also occur, when both codepages cover common ranges and the document only contains values m_out of those ranges (like the EUC-CN charset contains all mappings from BIG5).
document - the file to test.a - the first character set to interpret the document in.b - the 2nd character set to interpret the document in.
IOException - if sth. goes wrong.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||