ezvcard.util
Class IOUtils

java.lang.Object
  extended by ezvcard.util.IOUtils

public class IOUtils
extends Object

I/O helper classes.

Author:
Michael Angstadt

Method Summary
static void closeQuietly(Closeable closeable)
          Closes a closeable resource, catching its IOException.
static String getFileContents(File file)
          Reads the contents of a text file.
static String getFileContents(File file, String charset)
          Reads the contents of a text file.
static String getFileExtension(File file)
          Gets the extension off a file's name.
static byte[] toByteArray(InputStream in)
          Reads all the bytes from an input stream.
static byte[] toByteArray(InputStream in, boolean close)
          Reads all the bytes from an input stream.
static Reader utf8Reader(File file)
          Creates a reader whose character encoding is set to "UTF-8".
static Reader utf8Reader(InputStream in)
          Creates a reader whose character encoding is set to "UTF-8".
static Writer utf8Writer(File file)
          Creates a writer whose character encoding is set to "UTF-8".
static Writer utf8Writer(File file, boolean append)
          Creates a writer whose character encoding is set to "UTF-8".
static Writer utf8Writer(OutputStream out)
          Creates a writer whose character encoding is set to "UTF-8".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFileExtension

public static String getFileExtension(File file)
Gets the extension off a file's name.

Parameters:
file - the file
Returns:
its extension (e.g. "jpg") or null if it doesn't have one

toByteArray

public static byte[] toByteArray(InputStream in)
                          throws IOException
Reads all the bytes from an input stream.

Parameters:
in - the input stream
Returns:
the bytes
Throws:
IOException - if there's a problem reading from the input stream

toByteArray

public static byte[] toByteArray(InputStream in,
                                 boolean close)
                          throws IOException
Reads all the bytes from an input stream.

Parameters:
in - the input stream
close - true to close the input stream when done, false not to
Returns:
the bytes
Throws:
IOException - if there's a problem reading from the input stream

getFileContents

public static String getFileContents(File file)
                              throws IOException
Reads the contents of a text file.

Parameters:
file - the file to read
Returns:
the file contents
Throws:
IOException - if there's a problem reading the file

getFileContents

public static String getFileContents(File file,
                                     String charset)
                              throws IOException
Reads the contents of a text file.

Parameters:
file - the file to read
charset - the character encoding of the file
Returns:
the file contents
Throws:
IOException - if there's a problem reading the file

closeQuietly

public static void closeQuietly(Closeable closeable)
Closes a closeable resource, catching its IOException.

Parameters:
closeable - the resource to close (can be null)

utf8Writer

public static Writer utf8Writer(OutputStream out)
Creates a writer whose character encoding is set to "UTF-8".

Parameters:
out - the output stream to write to
Returns:
the writer

utf8Writer

public static Writer utf8Writer(File file)
                         throws FileNotFoundException
Creates a writer whose character encoding is set to "UTF-8".

Parameters:
file - the file to write to
Returns:
the writer
Throws:
FileNotFoundException - if the file cannot be written to

utf8Writer

public static Writer utf8Writer(File file,
                                boolean append)
                         throws FileNotFoundException
Creates a writer whose character encoding is set to "UTF-8".

Parameters:
file - the file to write to
append - true to append to the end of the file, false to overwrite it
Returns:
the writer
Throws:
FileNotFoundException - if the file cannot be written to

utf8Reader

public static Reader utf8Reader(InputStream in)
Creates a reader whose character encoding is set to "UTF-8".

Parameters:
in - the input stream to read from
Returns:
the reader

utf8Reader

public static Reader utf8Reader(File file)
                         throws FileNotFoundException
Creates a reader whose character encoding is set to "UTF-8".

Parameters:
file - the file to read from
Returns:
the reader
Throws:
FileNotFoundException - if the file can't be read


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.