|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.cert.cc.util.IOUtils
public final class IOUtils
IOUtils includes helper methods. All methods are thread safe, and most are null safe.
© 2009 Carnegie Mellon University
Field Summary | |
---|---|
static String |
NEW_LINE
|
Method Summary | |
---|---|
static boolean |
canRead(String path)
Returns if a file can be read. |
static boolean |
canWrite(String path)
Returns if a file can be written to. |
static void |
close(Closeable c)
Closes an Closeable object quietly. |
static void |
delete(String path)
Deletes an existing file. |
static boolean |
exists(String path)
Returns if a file already exists. |
static byte[] |
getRawData(InputStream is)
Extract all of the data from the InputStream is and returns the data. |
static File |
mkdir(String parent,
String child)
Makes a new directory. |
static String |
read(InputStream is)
Reads in data from is and returns a String
representation of the data. |
static String |
read(Reader reader)
Reads in data provided by the reader and returns a String
representation of the data. |
static String |
read(String path)
Reads in data from the path and returns a String
representation of the data. |
static void |
write(File file,
String contents)
Writes out the contents to the path specified. |
static void |
write(String filePath,
String contents)
Writes out the contents to the path specified. |
static void |
write(Writer writer,
String contents)
Writes out the contents to the Writer . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String NEW_LINE
Method Detail |
---|
public static byte[] getRawData(InputStream is) throws IOException
InputStream
is
and returns the data.
The InputStream
is
will be left open.
is
- InputStream
to be harvested
InputStream
's data
IOException
- If unable to retrieve the datapublic static String read(InputStream is) throws IOException
is
and returns a String
representation of the data. Should only be used for textual data.
Not null safe
is
- InputStream
is
's data
IOException
- If unable to read the datapublic static String read(String path) throws IOException
path
and returns a String
representation of the data. Should only be used for textual data.
Not null safe
path
- Path to a text file
IOException
- If unable to read the datapublic static String read(Reader reader) throws IOException
reader
and returns a String
representation of the data. Should only be used for textual data. The reader
is closed when the reading is completed.
The data is read into memory, so it is possible to overload the JVM's memory
Not null safe
reader
- Reader
IOException
- If unable to read the datapublic static void write(File file, String contents) throws IOException
file
- File
objectcontents
- contents to be written
IOException
- If unable to write the contentspublic static void write(String filePath, String contents) throws IOException
filePath
- file pathcontents
- contents to be written
IOException
- If unable to write the contentspublic static void write(Writer writer, String contents) throws IOException
Writer
. The Writer
is
closed upon the completion of the writing
writer
- Writer
contents
- contents to be written
IOException
- If unable to write the contentspublic static void close(Closeable c)
Closeable
object quietly.
c
- Closeable
objectpublic static boolean exists(String path)
path
- path to the file
public static File mkdir(String parent, String child) throws IOException
File
object to the created directory.
Unlike File.mkdir()
:
IOException
is thrown if unable to create the new directory.
parent
- Parent directorychild
- Child directory to be created under the parent
File
object.
IOException
- If unable to create the new directory.File.mkdir()
public static boolean canRead(String path)
path
- path to the file
public static boolean canWrite(String path)
path
- path to the file
public static void delete(String path) throws IOException
path
- path to the file
IOException
- If unable to delete an existing file
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |