org.qi4j.api.io
Class Outputs

java.lang.Object
  extended by org.qi4j.api.io.Outputs

public class Outputs
extends Object

Utility methods for creating standard Outputs


Constructor Summary
Outputs()
           
 
Method Summary
static
<T> Output<ByteBuffer,IOException>
byteBuffer(File file)
          Write ByteBuffer data to a file.
static
<T> Output<ByteBuffer,IOException>
byteBuffer(OutputStream stream)
          Write ByteBuffer data to an OutputStream.
static
<T> Output<byte[],IOException>
bytes(File file, int bufferSize)
          Write byte array data to a file.
static
<T> Output<T,RuntimeException>
collection(Collection<T> collection)
          Add items to a collection
static
<T> Output<T,RuntimeException>
noop()
          Do nothing.
static Output<Object,RuntimeException> systemOut()
          Write objects to System.out.println.
static Output<String,IOException> text(File file)
          Write lines to a text file with UTF-8 encoding.
static Output<String,IOException> text(File file, String encoding)
          Write lines to a text file.
static
<T,ReceiverThrowableType extends Throwable>
Output<T,ReceiverThrowableType>
withReceiver(Receiver<T,ReceiverThrowableType> receiver)
          Use given receiver as Output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Outputs

public Outputs()
Method Detail

text

public static Output<String,IOException> text(File file)
Write lines to a text file with UTF-8 encoding. Separate each line with a newline ("\n" character). If the writing or sending fails, the file is deleted.

If the filename ends with .gz, then the data is automatically GZipped.

Parameters:
file - the file to save the text to
Returns:
an Output for storing text in a file

text

public static Output<String,IOException> text(File file,
                                              String encoding)
Write lines to a text file. Separate each line with a newline ("\n" character). If the writing or sending fails, the file is deleted.

If the filename ends with .gz, then the data is automatically GZipped.

Parameters:
file - the file to save the text to
Returns:
an Output for storing text in a file

byteBuffer

public static <T> Output<ByteBuffer,IOException> byteBuffer(File file)
Write ByteBuffer data to a file. If the writing or sending of data fails the file will be deleted.

Type Parameters:
T -
Parameters:
file -
Returns:

byteBuffer

public static <T> Output<ByteBuffer,IOException> byteBuffer(OutputStream stream)
Write ByteBuffer data to an OutputStream.

Type Parameters:
T -
Parameters:
stream -
Returns:

bytes

public static <T> Output<byte[],IOException> bytes(File file,
                                                   int bufferSize)
Write byte array data to a file. If the writing or sending of data fails the file will be deleted.

Type Parameters:
T -
Parameters:
file -
bufferSize -
Returns:

noop

public static <T> Output<T,RuntimeException> noop()
Do nothing. Use this if you have all logic in filters and/or specifications

Type Parameters:
T -
Returns:

withReceiver

public static <T,ReceiverThrowableType extends Throwable> Output<T,ReceiverThrowableType> withReceiver(Receiver<T,ReceiverThrowableType> receiver)
Use given receiver as Output. Use this if there is no need to create a "transaction" for each transfer, and no need to do batch writes or similar.

Type Parameters:
T -
Parameters:
receiver - receiver for this Output
Returns:

systemOut

public static Output<Object,RuntimeException> systemOut()
Write objects to System.out.println.

Returns:

collection

public static <T> Output<T,RuntimeException> collection(Collection<T> collection)
Add items to a collection