|
|||||||||
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 String |
LINE_SEPARATOR
The lines.separator from the system properties as a constant |
Method Summary | |
---|---|
boolean |
close(InputStream stream)
Close the given stream ignoring any exception. |
boolean |
close(OutputStream stream)
Close the given stream ignoring any exception. |
void |
copyStream(InputStream inStream,
OutputStream outStream)
Copies all data from the iniput stream to the output stream using a buffer with the default size (1024 bytes). |
void |
copyStream(InputStream inStream,
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(InputStream inStream,
StringWriter writer)
|
void |
copyText(Reader reader,
StringWriter writer)
Copies all text lines from the specified reader to the given writer. |
static FileUtil |
current()
|
protected int |
indexOfPreceedingNotNullElement(String[] elements,
int start)
|
String |
javaFilename(String filename)
Returns the given filename in the platform independent way that Java understands. |
void |
processTextLines(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(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(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. |
String |
readTextFrom(File file)
Reads the whole content of the specified file and returns it as a string. |
String |
readTextFrom(InputStream inStream)
Reads the whole content of the given input stream and returns it as a string. |
String |
readTextFrom(String filename)
Reads the whole content of the file with the given name and returns it as a string. |
String |
standardize(String filename)
Convert the filename to a canonical (see java.io.File.getCanonicalPath()) format and replace any backslashes '\' by slashes ('/'). |
protected String |
standardizeFilename(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 String LINE_SEPARATOR
protected static final int DEFAULT_BUFFER_SIZE
Method Detail |
---|
public static FileUtil current()
public void copyStream(InputStream inStream, OutputStream outStream) throws IOException
IOException
public void copyStream(InputStream inStream, OutputStream outStream, int bufSize) throws IOException
IOException
public String readTextFrom(InputStream inStream) throws IOException
inStream
- The input stream to read
IOException
public String readTextFrom(String filename) throws IOException
filename
- The name of the text containing file
IOException
public String readTextFrom(File file) throws IOException
IOException
public void copyText(Reader reader, StringWriter writer) throws IOException
reader
- The reader which provides the text to copywriter
- The writer to which the text will be copied
IOException
public void processTextLines(String filename, LineProcessor processor) throws IOException
filename
- The name of the text file to readprocessor
- The processor that receives the lines from the text
IOException
public void processTextLines(InputStream inStream, LineProcessor processor) throws IOException
inStream
- The input stream that contains the textprocessor
- The processor that receives the lines from the text
IOException
public void processTextLines(Reader reader, LineProcessor processor) throws IOException
reader
- The reader that contains a text streamprocessor
- The processor that receives the lines from the text
IOException
public boolean close(InputStream stream)
public boolean close(OutputStream stream)
public String standardize(String filename)
filename
- The filename which has to be standardized
public String javaFilename(String filename)
filename
- The name to be modifiedprotected void copyText(InputStream inStream, StringWriter writer) throws IOException
IOException
protected String standardizeFilename(String filename)
protected int indexOfPreceedingNotNullElement(String[] elements, int start)
protected StringUtil str()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |