public class IoUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static long |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copies bytes from an InputStream to an OutputStream.
|
static long |
copy(java.io.Reader in,
java.io.Writer out)
Copy characters from a Reader to a Writer.
|
static void |
createParentDirectory(java.io.File file)
Creates parent directories, if necessary.
|
static void |
delete(java.io.File file)
Deletes a file or directory.
|
static void |
mkdirs(java.io.File dir)
Creates the directory named by this abstract pathname, including any necessary
but nonexistent parent directories.
|
static java.io.BufferedReader |
newBufferedReader(java.io.InputStream stream)
Creates a buffering character-input stream that uses default character set.
|
static java.io.BufferedReader |
newBufferedReader(java.io.InputStream stream,
int bufferSize)
Creates a buffering character-input stream that uses an input buffer of the specified size
and the default character set.
|
static java.io.BufferedReader |
newBufferedReader(java.lang.String fileName,
int bufferSize)
Creates a buffering character-input stream that uses an input buffer of the specified size
and the default character set.
|
static java.io.BufferedWriter |
newBufferedWriter(java.io.File file)
Creates a buffered character-output stream that uses a default-sized
output buffer and default character encoding.
|
static java.io.BufferedWriter |
newBufferedWriter(java.lang.String fileName)
Creates a buffered character-output stream that uses a default-sized
output buffer and default character encoding.
|
static java.io.BufferedWriter |
newBufferedWriter(java.lang.String dir,
java.lang.String fileName)
Creates a buffered character-output stream that uses a default-sized
output buffer and default character encoding.
|
static java.io.BufferedReader |
newUtf8BufferedReader(java.io.File file)
Creates a buffering character-input stream that uses UTF-8 character set.
|
static java.io.BufferedReader |
newUtf8BufferedReader(java.io.InputStream stream)
Creates a buffering character-input stream that uses UTF-8 character set.
|
static java.io.BufferedReader |
newUtf8BufferedReader(java.lang.String fileName)
Creates a buffering character-input stream that uses UTF-8 character set.
|
static java.io.BufferedWriter |
newUtf8BufferedWriter(java.io.File file)
Creates a buffered character-output stream that uses a default-sized
output buffer and UTF-8 character encoding.
|
static java.io.BufferedWriter |
newUtf8BufferedWriter(java.io.File file,
boolean append)
Creates a buffered character-output stream that uses a default-sized
output buffer and UTF-8 character encoding.
|
static java.io.BufferedWriter |
newUtf8BufferedWriter(java.lang.String fileName)
Creates a buffered character-output stream that uses a default-sized
output buffer and UTF-8 character encoding.
|
static java.io.BufferedWriter |
newUtf8BufferedWriter(java.lang.String fileName,
boolean append)
Creates a buffered character-output stream that uses a default-sized
output buffer and UTF-8 character encoding.
|
static java.lang.String |
readAndTrimFile(java.lang.String filename)
Read the file with the specified name using UTF-8 encoding,
remove trailing blanks from every line, and return the resulting
contents as one String.
|
static java.lang.String |
readFile(java.io.File file)
Returns the contents of a specified text file as one String using default encoding.
|
static java.lang.String |
readFile(java.lang.String filename)
Returns the contents of a specified text file as one String using default encoding.
|
static java.lang.String |
readFile(java.lang.String filename,
java.lang.String encoding)
Returns the contents of a specified text file as one String using given encoding.
|
static java.lang.String |
readMessage(java.io.InputStream stream)
Transforms a specified InputStream into a String using default encoding.
|
static java.lang.String |
readMessage(java.io.InputStream stream,
java.lang.String endOfMsg)
Transforms a specified InputStream into a String using default encoding.
|
static java.lang.String |
readStream(java.io.InputStream stream)
Transforms a specified InputStream to a String using default encoding.
|
static java.lang.String |
readStream(java.io.Reader stream)
Returns the contents of a specified Reader as one String.
|
static java.lang.String |
readUtf8File(java.lang.String filename)
Returns the contents of a specified text file as one String using UTF-8 encoding.
|
static void |
stderrln(java.lang.String line)
Print out a line to standard error
|
static void |
stdoutln()
Print out line feed to standard output
|
static void |
stdoutln(java.lang.String line)
Print out a line to standard output
|
static void |
stdoutprn(java.lang.String text)
Print out text to standard output
|
static java.lang.String |
toString(java.io.InputStream in)
Get the contents of an InputStream as a String
using the UTF-8 character encoding.
|
static void |
writeFile(java.io.File file,
byte[] data)
Writes byte array to a file.
|
static void |
writeFile(java.lang.String filename,
java.lang.String str)
Writes an UTF-8 converted string to a file.
|
static void |
writeFile(java.lang.String filename,
java.lang.String str,
boolean createParentDirs)
Writes an UTF-8 converted string to a file.
|
static void |
writeFileCrLf(java.lang.String filename,
java.lang.String text)
Writes the specified text to a file.
|
static void |
writeFileCrLf(java.lang.String filename,
java.lang.String text,
boolean createParentDirs)
Writes the specified text to a file.
|
public static java.lang.String readFile(java.lang.String filename) throws java.io.IOException
filename
- a file namejava.io.IOException
- if an I/O error occurspublic static java.lang.String readFile(java.io.File file) throws java.io.IOException
file
- the filejava.io.IOException
- if an I/O error occurspublic static java.lang.String readUtf8File(java.lang.String filename) throws java.io.IOException
filename
- a file namejava.io.IOException
- if an I/O error occurspublic static java.lang.String readFile(java.lang.String filename, java.lang.String encoding) throws java.io.IOException
filename
- a file nameencoding
- character encodingjava.io.IOException
- if an I/O error occurspublic static java.lang.String readStream(java.io.InputStream stream) throws java.io.IOException
stream
- an open InputStreamjava.io.IOException
- if an I/O error occurspublic static java.lang.String readStream(java.io.Reader stream) throws java.io.IOException
stream
- an open Readerjava.io.IOException
- if an I/O error occurspublic static java.lang.String readMessage(java.io.InputStream stream, java.lang.String endOfMsg) throws java.io.IOException
stream
- an open streamendOfMsg
- end-of-msg markerjava.io.IOException
- if an I/O error occurspublic static java.lang.String readMessage(java.io.InputStream stream) throws java.io.IOException
stream
- an open streamjava.io.IOException
- if an I/O error occurspublic static java.lang.String readAndTrimFile(java.lang.String filename) throws FndException
filename
- a file nameFndException
public static void writeFileCrLf(java.lang.String filename, java.lang.String text) throws java.io.IOException
filename
- file nametext
- file contentsjava.io.IOException
- if an I/O error occurspublic static void writeFileCrLf(java.lang.String filename, java.lang.String text, boolean createParentDirs) throws java.io.IOException
filename
- file nametext
- file contentscreateParentDirs
- if true creates parent directories if not existjava.io.IOException
- if an I/O error occurspublic static void writeFile(java.lang.String filename, java.lang.String str) throws java.io.IOException
filename
- file namestr
- file contentsjava.io.IOException
public static void writeFile(java.lang.String filename, java.lang.String str, boolean createParentDirs) throws java.io.IOException
filename
- file namestr
- file contentscreateParentDirs
- if true creates parent directories if not existjava.io.IOException
public static void writeFile(java.io.File file, byte[] data) throws java.io.IOException
file
- file to writedata
- byte array to be writtenjava.io.IOException
public static void createParentDirectory(java.io.File file) throws java.io.IOException
file
- java.io.IOException
public static java.io.BufferedReader newBufferedReader(java.lang.String fileName, int bufferSize) throws java.io.FileNotFoundException
fileName
- File namebufferSize
- Input-buffer sizejava.io.FileNotFoundException
public static java.io.BufferedReader newBufferedReader(java.io.InputStream stream) throws java.io.FileNotFoundException
stream
- An input streamjava.io.FileNotFoundException
public static java.io.BufferedReader newBufferedReader(java.io.InputStream stream, int bufferSize) throws java.io.FileNotFoundException
stream
- An input streambufferSize
- Input-buffer sizejava.io.FileNotFoundException
public static java.io.BufferedReader newUtf8BufferedReader(java.lang.String fileName) throws java.io.FileNotFoundException
fileName
- File name of the file to be opened for readingjava.io.FileNotFoundException
public static java.io.BufferedReader newUtf8BufferedReader(java.io.File file) throws java.io.FileNotFoundException
file
- The file to be opened for readingjava.io.FileNotFoundException
public static java.io.BufferedReader newUtf8BufferedReader(java.io.InputStream stream) throws java.io.FileNotFoundException
stream
- An input streamjava.io.FileNotFoundException
public static java.io.BufferedWriter newBufferedWriter(java.lang.String fileName) throws java.io.FileNotFoundException
fileName
- File name of the file to be opened for writingjava.io.FileNotFoundException
public static java.io.BufferedWriter newBufferedWriter(java.lang.String dir, java.lang.String fileName) throws java.io.FileNotFoundException
dir
- The parent pathname stringfileName
- File name of the file to be opened for writingjava.io.FileNotFoundException
public static java.io.BufferedWriter newBufferedWriter(java.io.File file) throws java.io.FileNotFoundException
file
- the file to be opened for writingjava.io.FileNotFoundException
public static java.io.BufferedWriter newUtf8BufferedWriter(java.lang.String fileName) throws java.io.FileNotFoundException
fileName
- File name of the file to be opened for writingjava.io.FileNotFoundException
public static java.io.BufferedWriter newUtf8BufferedWriter(java.lang.String fileName, boolean append) throws java.io.FileNotFoundException
fileName
- File name of the file to be opened for writingappend
- If true, then bytes will be written to the end of the file rather than the beginningjava.io.FileNotFoundException
public static java.io.BufferedWriter newUtf8BufferedWriter(java.io.File file) throws java.io.FileNotFoundException
file
- the file to be opened for writingjava.io.FileNotFoundException
public static java.io.BufferedWriter newUtf8BufferedWriter(java.io.File file, boolean append) throws java.io.FileNotFoundException
file
- the file to be opened for writingappend
- if true, then bytes will be written to the end of the file rather than the beginningjava.io.FileNotFoundException
public static long copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the InputStream
to read fromout
- the OutputStream
to write tojava.lang.NullPointerException
- if the input or output is nulljava.io.IOException
- if an I/O error occurspublic static long copy(java.io.Reader in, java.io.Writer out) throws java.io.IOException
in
- the Reader
to read fromout
- the Writer
to write tojava.lang.NullPointerException
- if the input or output is nulljava.io.IOException
- if an I/O error occurspublic static java.lang.String toString(java.io.InputStream in) throws java.io.IOException
in
- the InputStream
to read fromjava.lang.NullPointerException
- if the input is nulljava.io.IOException
- if an I/O error occurspublic static void stdoutprn(java.lang.String text)
text
- public static void stdoutln()
public static void stdoutln(java.lang.String line)
line
- line to printpublic static void stderrln(java.lang.String line)
line
- line to printpublic static void mkdirs(java.io.File dir) throws java.io.IOException
dir
- File denoted directory to be createdjava.io.IOException
public static void delete(java.io.File file) throws java.io.IOException
file
- file or directory to deletejava.io.IOException
- if the specified file/directory has not been successfully deleted