NIOHandler

public class NIOHandler

NIOHandler provides some convenient methods for handling some basic input and output funtions which has adopted the features of java NIO package. Creation Date: 5/10/2006

Author:Twinsen

See also: hk.hku.cecid.piazza.commons.io.IOHandler, java.nio.ByteBuffer, java.nio.MappedByteBuffer, java.nio.channels.Channels

Fields

DEFAULT_PAGE_SIZE

public static final int DEFAULT_PAGE_SIZE

The default page size for memory mapped stream.

MAX_BUFFER_SIZE

public static final int MAX_BUFFER_SIZE

The max buffer size of ByteBuffer is 10mb.

Methods

pipe

public static void pipe(FileInputStream fins, OutputStream out)

Pipes an file input stream to an output stream.

Parameters:
  • fins – the file input stream to be read.
  • out – the output stream to be written.
Throws:
  • IOException – if there is IO error occurred during the operation.

pipe

public static void pipe(FileInputStream fins, OutputStream out, int startPosition, long size)

Pipes an file input stream to an output stream.

Parameters:
  • fins – the file input stream to be read.
  • out – the output stream to be written.
Throws:
  • IOException – if there is IO error occurred during the operation.

pipe

public static void pipe(InputStream ins, OutputStream out)

Pipes an input stream to an output stream.

Parameters:
  • ins – the input stream to be read.
  • out – the output stream to be written.
Throws:
  • IOException – if there is IO error occurred during the operation.

readByteBuffer

public static ByteBuffer readByteBuffer(InputStream ins)

Reads an array of bytes from an input stream.

Parameters:
  • ins – the input stream to be read.
Throws:
  • IOException – if there is IO error occurred during the operation.
Returns:

a bytes buffer read from the specified input stream.

readBytes

public static byte[] readBytes(InputStream ins)

Reads an array of bytes from an input stream.

Parameters:
  • ins – the input stream to be read.
Throws:
  • IOException – if there is IO error occurred during the operation.
Returns:

an array of bytes read from the specified input stream.

writeBytes

public static void writeBytes(byte[] bytes, OutputStream out)

Writes an array of bytes to an output stream.

Parameters:
  • bytes – an array of bytes to write.
  • out – the output stream to be written.
Throws:
  • IOException – if there is IO error occurred during the operation.

writeBytes

public static void writeBytes(ByteBuffer src, OutputStream out)

Writes a byte buffer to an output stream.

Parameters:
  • src – a byte buffer to write.
  • out – the output stream to be written.
Throws:
  • IOException – if there is IO error occurred during the operation.