|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 | |
---|---|
protected static int |
DEFAULT_BUFFER_SIZE
|
static java.lang.String |
LINE_SEPARATOR
The lines.separator from the system properties as a constant |
Method Summary | |
---|---|
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. |
void |
copyStream(java.io.InputStream inStream,
java.io.OutputStream outStream)
Copies all data from the iniput 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. |
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. |
static FileUtil |
current()
|
protected int |
indexOfPreceedingNotNullElement(java.lang.String[] elements,
int start)
|
java.lang.String |
javaFilename(java.lang.String filename)
Returns the given filename in the platform independent way that Java understands. |
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(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 |
standardize(java.lang.String filename)
Convert the filename 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()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String LINE_SEPARATOR
protected static final int DEFAULT_BUFFER_SIZE
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 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 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.IOException
public boolean close(java.io.InputStream stream)
public boolean close(java.io.OutputStream stream)
public java.lang.String standardize(java.lang.String filename)
filename
- The filename which has to be standardized
public java.lang.String javaFilename(java.lang.String filename)
filename
- The name to be modifiedprotected void copyText(java.io.InputStream inStream, 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 StringUtil str()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |