net.sf.asyncobjects.io
Class IOUtils

java.lang.Object
  extended by net.sf.asyncobjects.io.IOUtils

public class IOUtils
extends Object

IO Utilties

Author:
const

Field Summary
static int UNLIMITED
          an unlmited value
 
Constructor Summary
IOUtils()
           
 
Method Summary
static
<D extends BatchedData<D>>
Promise<Integer>
compare(AInput<D> in1, AInput<D> in2, int readSize)
          Compare inputs.
static
<D extends BatchedData<D>>
Promise<Long>
discard(AInput<D> in, long length, int readDataSize)
          Discard specified amount of elements from input.
static
<D extends BatchedData<D>>
Promise<Long>
forward(AInput<D> in, AOutput<D> out, long length, int readDataSize)
          Forward data from input to output
static
<D extends BatchedData<D>>
Promise<Long>
forward(AInput<D> in, AOutput<D> out, long length, int readDataSize, boolean autoflush)
          Forward data from input to output
static Promise<BinaryData> readAll(AByteInput in, int limit)
          Read all data from the stream.
static Promise<TextData> readAll(ATextInput in, int limit)
          Read all data from the stream.
static
<D extends BatchedData<D>>
Promise<D>
readAll(D initial, AInput<D> in, int limit)
          Read all data from the stream.
static Promise<BinaryData> readFully(AByteInput in, int amount)
          Read exactly specified amount data from byte input
static Promise<TextData> readFully(ATextInput in, int amount)
          Read exactly specified amount data from text input
static
<D extends BatchedData<D>>
Promise<D>
readFully(D empty, AInput<D> in, int amount)
          Read exactly specified amount data from byte input
static
<D extends BatchedData<D>>
Promise<Long>
repeat(AOutput<D> out, D data, long length)
          Write specified binary data repeating it until length bytes are written.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNLIMITED

public static final int UNLIMITED
an unlmited value

See Also:
Constant Field Values
Constructor Detail

IOUtils

public IOUtils()
Method Detail

discard

public static <D extends BatchedData<D>> Promise<Long> discard(AInput<D> in,
                                                               long length,
                                                               int readDataSize)
Discard specified amount of elements from input. Discard process also finishes when EOF is encountered.

Type Parameters:
D - a batched data type
Parameters:
in - an input
length - a length to discard, UNLIMITED means discard until EOF
readDataSize - a portion that is used to discard
Returns:
a promise that resolves to amount of discarded elments (as Long). Note that amount is counted using long's + operation. So for very large datasets amount will be invalid.

repeat

public static <D extends BatchedData<D>> Promise<Long> repeat(AOutput<D> out,
                                                              D data,
                                                              long length)
Write specified binary data repeating it until length bytes are written. The data is truncated if lengh is not mulitpliy of data.length().

Type Parameters:
D - a batched data type
Parameters:
out - an output stream
data - data
length - length to be written. if UNLIMITED, data is being written infinitely until exception is encountered.
Returns:
a promise that resolves to amount of written bytes (as Long). Note that amount is counted using long's + operation. So for very large datasets amount will be invalid.

readFully

public static Promise<BinaryData> readFully(AByteInput in,
                                            int amount)
Read exactly specified amount data from byte input

Parameters:
in - a byte input to read from
amount - an amount to read
Returns:
promise for read data or exception

readFully

public static Promise<TextData> readFully(ATextInput in,
                                          int amount)
Read exactly specified amount data from text input

Parameters:
in - a byte input to read from
amount - an amount to read
Returns:
promise for read data or exception

readFully

public static <D extends BatchedData<D>> Promise<D> readFully(D empty,
                                                              AInput<D> in,
                                                              int amount)
Read exactly specified amount data from byte input

Type Parameters:
D - a data type
Parameters:
empty - an empty data
in - a byte input to read from
amount - an amount to read
Returns:
promise for read data or exception

forward

public static final <D extends BatchedData<D>> Promise<Long> forward(AInput<D> in,
                                                                     AOutput<D> out,
                                                                     long length,
                                                                     int readDataSize)
Forward data from input to output

Type Parameters:
D - a batched data type
Parameters:
in - a data source
out - a data destination
length - a length to copy (UNLIMITED means until eof)
readDataSize - a portion to use during copying process
Returns:
a promise that resolves to amount of discarded bytes (as Long). Note that amount is counted using long's + operation. So for very large datasets amount will be invalid.

forward

public static final <D extends BatchedData<D>> Promise<Long> forward(AInput<D> in,
                                                                     AOutput<D> out,
                                                                     long length,
                                                                     int readDataSize,
                                                                     boolean autoflush)
Forward data from input to output

Type Parameters:
D - a batched data type
Parameters:
in - a data source
out - a data destination
length - a length to copy (UNLIMITED means until eof)
readDataSize - a portion to use during copying process
autoflush - if true, autoflush after each write
Returns:
a promise that resolves to amount of discarded bytes (as Long). Note that amount is counted using long's + operation. So for very large datasets amount will be invalid.

compare

public static <D extends BatchedData<D>> Promise<Integer> compare(AInput<D> in1,
                                                                  AInput<D> in2,
                                                                  int readSize)
Compare inputs. Two stream are being read and compared. If the

Type Parameters:
D - a batched data type
Parameters:
in1 - first input
in2 - second input
readSize - max amount to read during single iteration of comparison
Returns:
a comparison result (see BinaryData for comparison algorithm)

readAll

public static <D extends BatchedData<D>> Promise<D> readAll(D initial,
                                                            AInput<D> in,
                                                            int limit)
Read all data from the stream. This utility should be used with a great care since it has an obvious resource managment issues.

Type Parameters:
D - a data
Parameters:
initial - intial data, the next read data is appended to it
in - input stream
limit - a limit for individual read operations
Returns:
all data from the stream

readAll

public static Promise<BinaryData> readAll(AByteInput in,
                                          int limit)
Read all data from the stream. This utility should be used with a great care since it has an obvious resource managment issues.

Parameters:
in - input stream
limit - a limit for individual read operations
Returns:
all data from the stream

readAll

public static Promise<TextData> readAll(ATextInput in,
                                        int limit)
Read all data from the stream. This utility should be used with a great care since it has an obvious resource managment issues.

Parameters:
in - input stream
limit - a limit for individual read operations
Returns:
all data from the stream


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.