net.sf.zig_project.gpl.common.io
Class Transfer

java.lang.Object
  extended bynet.sf.zig_project.gpl.common.io.Transfer

public abstract class Transfer
extends Object

The Transfer class provides a library of functions that may be called to simplify routine IO operations.

Version:
September 5, 2004
Author:
Frank Ziglar

Field Summary
static int SUGGESTED_CHUNK_SIZE
          Suggested size for a buffer in order to perform bulk operations
 
Constructor Summary
Transfer()
           
 
Method Summary
static void byteTransfer(InputStream is, OutputStream os)
          Transfers data from the InputStream to the OutputStream, one byte at a time.
static byte[] loadFileBytes(File src)
          Convenience method to load an entire file into a single byte[] buffer.
static String loadTextFile(File src)
          Convenience method to load an entire text file into memory, and return the complete contents as a single String (using the platforms default encoding).
static void shutDown(InputStream is, IOExceptionHandler handler)
          Convenience method to attempt to close an InputStream.
static void shutDown(OutputStream os, IOExceptionHandler handler)
          Convenience method to attempt to close an OutputStream.
static void skip(InputStream is, long n)
          This version of skip always skips n bytes, or throws an IOException if the skip can not be fully completed.
static void skip(Reader r, long n)
          This version of skip always skips n bytes, or throws an IOException if the skip can not be fully completed.
static void transfer(InputStream is, OutputStream os)
          Convenience method for a bulk transfer operation.
static void transfer(InputStream is, OutputStream os, byte[] slurp)
          Uses the buffer slurp to perform a bulk transfer operation from the InputStream, until it is exhausted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUGGESTED_CHUNK_SIZE

public static final int SUGGESTED_CHUNK_SIZE
Suggested size for a buffer in order to perform bulk operations

See Also:
Constant Field Values
Constructor Detail

Transfer

public Transfer()
Method Detail

byteTransfer

public static void byteTransfer(InputStream is,
                                OutputStream os)
                         throws IOException
Transfers data from the InputStream to the OutputStream, one byte at a time. There may be some scenarios where this form of transfer is necessary, but generally the transfer methods will operate much more efficiently. Once the transfer is completed, the input stream will automatically be closed.

Throws:
IOException

transfer

public static void transfer(InputStream is,
                            OutputStream os)
                     throws IOException
Convenience method for a bulk transfer operation. Will create a new buffer based on SUGGESTED_CHUNK_SIZE, and use it transfer data until the input stream is exhausted.

Throws:
IOException
See Also:
transfer(InputStream, OutputStream, byte[])

transfer

public static void transfer(InputStream is,
                            OutputStream os,
                            byte[] slurp)
                     throws IOException
Uses the buffer slurp to perform a bulk transfer operation from the InputStream, until it is exhausted. At that point the stream is automatically closed. While an InputStream is allowed to return from a read without actually loading any data, this method must insist that the stream should block until data is available in order to prevent an infinite loop. An exception will hence be thrown if the InputStream returns from a read with no data loaded. Once the InputStream has been exhausted, it is automatically closed. The procedure used to transfer data is a simple, single threaded, linear transfer.

Throws:
IOException

loadFileBytes

public static byte[] loadFileBytes(File src)
                            throws IOException
Convenience method to load an entire file into a single byte[] buffer. Since files can grow quite large, a failure to allocate a sufficient buffer is thrown as a checked IOException. Otherwise, the returned buffer contains full the contents of the file as they were read.

Throws:
IOException

loadTextFile

public static String loadTextFile(File src)
                           throws IOException
Convenience method to load an entire text file into memory, and return the complete contents as a single String (using the platforms default encoding).

Throws:
IOException
See Also:
loadFileBytes(File)

shutDown

public static void shutDown(InputStream is,
                            IOExceptionHandler handler)
Convenience method to attempt to close an InputStream. This method may be cleaner to call than is.close(), since this method delegates any potential IOException to the provided handler, and does not rethrow it.


shutDown

public static void shutDown(OutputStream os,
                            IOExceptionHandler handler)
Convenience method to attempt to close an OutputStream. This method may be cleaner to call than os.close(), since this method delegates any potential IOException to the provided handler, and does not rethrow it.


skip

public static void skip(InputStream is,
                        long n)
                 throws IOException
This version of skip always skips n bytes, or throws an IOException if the skip can not be fully completed. In which case, the total number of bytes which the InputStream was able to successfully skip can not be guaranteed.

Throws:
IOException

skip

public static void skip(Reader r,
                        long n)
                 throws IOException
This version of skip always skips n bytes, or throws an IOException if the skip can not be fully completed. In which case, the total number of bytes which the Reader was able to successfully skip can not be guaranteed.

Throws:
IOException