Please note that this documentation is not final and is subject to change.


DRAFT-b102

java.io
Class Inputs

java.lang.Object
  extended by java.io.Inputs

public final class Inputs
extends Object

This class consists exclusively of static methods that operate on input sources.

The methods to read lines of text defined by this class recognize the following as Unicode line terminators:

Since:
1.7

Method Summary
Modifier and Type Method and Description
static byte[] readAllBytes(FileRef source)
          Read all bytes from the specified file.
static byte[] readAllBytes(InputStream source)
          Read all bytes from the specified input stream.
static List<String> readAllLines(FileRef source)
          Read all lines from the specified file.
static List<String> readAllLines(FileRef source, String csn)
          Read all lines from the specified file.
static List<String> readAllLines(InputStream source)
          Read all lines from the specified input stream.
static List<String> readAllLines(InputStream source, String csn)
          Read all lines from the specified input stream.
static List<String> readAllLines(Readable source)
          Read all lines from the from the specified source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readAllBytes

public static byte[] readAllBytes(FileRef source)
                           throws IOException
Read all bytes from the specified file. When all bytes have been read, or an I/O error occurs, then the file is closed.

Usage Example: Suppose we want to read all bytes from a file, represented by a java.io.File:

   File f = ...
   byte[] content = Inputs.readAllBytes(f.toPath());
 

Parameters:
source - the data source
Returns:
a byte array containing the bytes read from the file
Throws:
IOException - if an I/O error occurs
OutOfMemoryError - if the required array size is too large

readAllBytes

public static byte[] readAllBytes(InputStream source)
                           throws IOException
Read all bytes from the specified input stream.

On return, the input stream will be at end of stream.

Parameters:
source - the data source
Returns:
a byte array containing the bytes read from the source
Throws:
IOException - if an I/O error occurs
OutOfMemoryError - if the required array size is too large

readAllLines

public static List<String> readAllLines(FileRef source,
                                        String csn)
                                 throws IOException
Read all lines from the specified file. Bytes from the file are converted into characters using the specified Charset. When all lines have been read, or an I/O error occurs, then the file is closed.

Parameters:
source - the data source
csn - the name of the charset to be used
Returns:
an unmodifiable list of the lines read from the file
Throws:
IllegalArgumentException - if the charset name is illegal or not available in this instance of the Java virtual machine
CharacterCodingException - if the file contains a malformed or unmappable byte sequence for the charset
IOException - if an I/O error occurs

readAllLines

public static List<String> readAllLines(FileRef source)
                                 throws IOException
Read all lines from the specified file. Bytes from the file are converted into characters using the underlying platform's default charset. When all lines have been read, or an I/O error occurs, then the file is closed.

Parameters:
source - the data source
Returns:
an unmodifiable list of the lines read from the file
Throws:
CharacterCodingException - if the file contains a malformed or unmappable byte sequence for the default charset
IOException - if an I/O error occurs

readAllLines

public static List<String> readAllLines(InputStream source,
                                        String csn)
                                 throws IOException
Read all lines from the specified input stream. Bytes from the stream are converted into characters using the specified Charset.

On return, the input stream will be at end of stream.

Parameters:
source - the input stream to read from
csn - the name of the charset to be used
Returns:
an unmodifiable list of the lines read from the input stream
Throws:
IllegalArgumentException - if the charset name is illegal or not available in this instance of the Java virtual machine
CharacterCodingException - if the input contains a malformed or unmappable byte sequence for the charset
IOException - if an I/O error occurs

readAllLines

public static List<String> readAllLines(InputStream source)
                                 throws IOException
Read all lines from the specified input stream. Bytes from the stream are converted into characters using the underlying platform's default charset.

On return, the input stream will be at end of stream.

Parameters:
source - the input stream to read from
Returns:
an unmodifiable list of the lines read from the input stream
Throws:
CharacterCodingException - if the input contains a malformed or unmappable byte sequence for the default charset
IOException - if an I/O error occurs

readAllLines

public static List<String> readAllLines(Readable source)
                                 throws IOException
Read all lines from the from the specified source.

On return, the source will be at its end.

Parameters:
source - The source to read from
Returns:
An unmodifiable list of the lines read from source
Throws:
IOException - If an I/O error occurs


DRAFT-b102