org.qi4j.io
Class Inputs

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

public class Inputs
extends java.lang.Object

Common inputs


Constructor Summary
Inputs()
           
 
Method Summary
static Input<java.nio.ByteBuffer,java.io.IOException> byteBuffer(java.io.File source, int bufferSize)
          Read a file using ByteBuffer of a given size.
static Input<java.nio.ByteBuffer,java.io.IOException> byteBuffer(java.io.InputStream source, int bufferSize)
          Read an inputstream using ByteBuffer of a given size.
static
<T,SenderThrowableType extends java.lang.Throwable>
Input<T,SenderThrowableType>
combine(java.lang.Iterable<Input<T,SenderThrowableType>> inputs)
          Combine many Input into one single Input.
static
<T> Input<T,java.lang.RuntimeException>
iterable(java.lang.Iterable<T> iterable)
          Create an Input that takes its items from the given Iterable.
static Input<java.nio.ByteBuffer,java.io.IOException> output(Visitor<java.io.OutputStream,java.io.IOException> outputVisitor, int bufferSize)
          Create an Input that allows a Visitor to write to an OutputStream.
static Input<java.lang.String,java.io.IOException> text(java.io.File source)
          Read lines from a UTF-8 encoded textfile.
static Input<java.lang.String,java.io.IOException> text(java.io.File source, java.lang.String encoding)
          Read lines from a textfile with the given encoding.
static Input<java.lang.String,java.lang.RuntimeException> text(java.io.Reader source)
          Read lines from a Reader.
static Input<java.lang.String,java.lang.RuntimeException> text(java.lang.String source)
          Read lines from a String.
static Input<java.lang.String,java.io.IOException> text(java.net.URL source)
          Read lines from a textfile at a given URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Inputs

public Inputs()
Method Detail

text

public static Input<java.lang.String,java.lang.RuntimeException> text(java.lang.String source)
Read lines from a String.

Parameters:
source - lines
Returns:
Input that provides lines from the string as strings

text

public static Input<java.lang.String,java.lang.RuntimeException> text(java.io.Reader source)
Read lines from a Reader.

Parameters:
source - lines
Returns:
Input that provides lines from the string as strings

text

public static Input<java.lang.String,java.io.IOException> text(java.io.File source)
Read lines from a UTF-8 encoded textfile. If the filename ends with .gz, then the data is automatically unzipped when read.

Parameters:
source - textfile with lines separated by \n character
Returns:
Input that provides lines from the textfiles as strings

text

public static Input<java.lang.String,java.io.IOException> text(java.io.File source,
                                                               java.lang.String encoding)
Read lines from a textfile with the given encoding. If the filename ends with .gz, then the data is automatically unzipped when read.

Parameters:
source - textfile with lines separated by \n character
encoding - encoding of file, e.g. "UTF-8"
Returns:
Input that provides lines from the textfiles as strings

text

public static Input<java.lang.String,java.io.IOException> text(java.net.URL source)
Read lines from a textfile at a given URL. If the content support gzip encoding, then the data is automatically unzipped when read. The charset in the content-type of the URL will be used for parsing. Default is UTF-8.

Parameters:
source - textfile with lines separated by \n character
Returns:
Input that provides lines from the textfiles as strings

byteBuffer

public static Input<java.nio.ByteBuffer,java.io.IOException> byteBuffer(java.io.File source,
                                                                        int bufferSize)
Read a file using ByteBuffer of a given size. Useful for transferring raw data.

Parameters:
source -
bufferSize -
Returns:

byteBuffer

public static Input<java.nio.ByteBuffer,java.io.IOException> byteBuffer(java.io.InputStream source,
                                                                        int bufferSize)
Read an inputstream using ByteBuffer of a given size.

Parameters:
source -
bufferSize -
Returns:

combine

public static <T,SenderThrowableType extends java.lang.Throwable> Input<T,SenderThrowableType> combine(java.lang.Iterable<Input<T,SenderThrowableType>> inputs)
Combine many Input into one single Input. When a transfer is initiated from it all items from all inputs will be transferred to the given Output.

Type Parameters:
T -
SenderThrowableType -
Parameters:
inputs -
Returns:

iterable

public static <T> Input<T,java.lang.RuntimeException> iterable(java.lang.Iterable<T> iterable)
Create an Input that takes its items from the given Iterable.

Type Parameters:
T -
Parameters:
iterable -
Returns:

output

public static Input<java.nio.ByteBuffer,java.io.IOException> output(Visitor<java.io.OutputStream,java.io.IOException> outputVisitor,
                                                                    int bufferSize)
Create an Input that allows a Visitor to write to an OutputStream. The stream is a BufferedOutputStream, so when enough data has been gathered it will send this in chunks of the given size to the Output it is transferred to. The Visitor does not have to call close() on the OutputStream, but should ensure that any wrapper streams or writers are flushed so that all data is sent.

Parameters:
outputVisitor -
bufferSize -
Returns: