public final class IOUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static BufferedReader |
buffer(Reader maybeBuffered)
Wraps its argument in
BufferedReader if not already one. |
static BufferedReader |
bufferStream(InputStream in) |
static GZIPOutputStream |
buildGZIPOutputStream(File file) |
static GZIPOutputStream |
buildGZIPOutputStream(OutputStream delegate) |
static Writer |
buildGZIPWriter(File file) |
static Writer |
buildGZIPWriter(OutputStream delegate) |
static void |
copyStreamToFile(InputStream in,
File file) |
static void |
copyURLToFile(URL url,
File file) |
static boolean |
deleteRecursively(File dir)
Attempts to recursively delete a directory.
|
static boolean |
isGZIPFileEmpty(File f) |
static InputStream |
openMaybeDecompressing(File file)
Opens an
InputStream to the file. |
static Reader |
openReaderMaybeDecompressing(File file) |
static <T extends Serializable> |
readObjectFromFile(File f,
Class<T> clazz) |
static String |
readSmallTextFromURL(URL url) |
static String |
urlEncode(String raw) |
static <T extends Serializable> |
writeObjectToFile(File f,
T t)
Serializes an object, with gzip compression, to a given file.
|
public static String urlEncode(String raw)
raw - string to URL-encodepublic static boolean deleteRecursively(File dir)
dir - directory to delete along with contentstrue if all files and dirs were deleted successfullypublic static InputStream openMaybeDecompressing(File file) throws IOException
InputStream to the file. If it appears to be compressed, because its file name ends in
".gz" or ".zip" or ".deflate", then it will be decompressed accordinglyfile - file, possibly compressed, to openInputStream on uncompressed contentsIOException - if the stream can't be opened or is invalid or can't be readpublic static Reader openReaderMaybeDecompressing(File file) throws IOException
file - file, possibly compressed, to openReader on uncompressed contentsIOException - if the stream can't be opened or is invalid or can't be readopenMaybeDecompressing(File)public static void copyStreamToFile(InputStream in, File file) throws IOException
in - stream to read and copyfile - file to write stream's contents toIOException - if the stream can't be read or the file can't be writtenpublic static void copyURLToFile(URL url, File file) throws IOException
url - URL whose contents are to be read and copiedfile - file to write contents toIOException - if the URL can't be read or the file can't be writtenpublic static String readSmallTextFromURL(URL url) throws IOException
url - URL whose contents are to be readIOException - if the URL can't be read or the file can't be writtenpublic static GZIPOutputStream buildGZIPOutputStream(OutputStream delegate) throws IOException
delegate - OutputStream to wrapGZIPOutputStream wrapping the given OutputStream. It attempts to use the new
Java 7 version that actually responds to OutputStream.flush() as expected. If not available,
uses the previous version (GZIPOutputStream.GZIPOutputStream(OutputStream))IOExceptionpublic static GZIPOutputStream buildGZIPOutputStream(File file) throws IOException
IOExceptionbuildGZIPOutputStream(OutputStream)public static Writer buildGZIPWriter(OutputStream delegate) throws IOException
delegate - OutputStream to wrapbuildGZIPOutputStream(OutputStream) as a Writer that encodes
using UTF-8 encodingIOExceptionpublic static Writer buildGZIPWriter(File file) throws IOException
IOExceptionbuildGZIPWriter(OutputStream)public static BufferedReader buffer(Reader maybeBuffered)
BufferedReader if not already one.public static BufferedReader bufferStream(InputStream in)
BufferedReader on the stream, using UTF-8 encodingpublic static boolean isGZIPFileEmpty(File f) throws IOException
IOException - if the file is not a gzip file or can't be readpublic static <T extends Serializable> T readObjectFromFile(File f, Class<T> clazz) throws IOException
IOExceptionpublic static <T extends Serializable> void writeObjectToFile(File f, T t) throws IOException
IOExceptionCopyright © 2012-2013 Myrrix Ltd. All Rights Reserved.