com.partnersoft.io
Class IOLib

java.lang.Object
  extended by com.partnersoft.io.IOLib

public class IOLib
extends java.lang.Object

General-purpose I/O routines.

Author:
Paul Reavis Copyright 2003 Partner Software, Inc.

Field Summary
static int BUFFER_SIZE
           
 
Constructor Summary
IOLib()
           
 
Method Summary
static long checksum(byte[] victim)
          Generates a checksum for the given byte array.
static long dataCopy(java.io.DataInput source, java.io.DataOutput sink, int howMany)
          Binary copies up to the given number of bytes from a DataInput object to an DataOutput object.
static long dataToStream(java.io.DataInput source, java.io.OutputStream sink, int howMany)
           
static long dataToStream(java.io.DataInput source, java.io.OutputStream sink, int howMany, java.security.MessageDigest digest)
          Binary copies up to the given number of bytes from a DataInput object to an output stream.
static byte[] readBytesFromStream(java.io.InputStream innie)
          Reads the entirety of the given input stream in as a byte array and returns the result.
static java.lang.String readTextFromReader(java.io.Reader reader)
          Reads the entirety of the given reader in as a String and returns the result.
static java.lang.String readTextFromStream(java.io.InputStream innie)
          Reads the entirety of the given input stream in as a String and returns the result.
static long streamCopy(java.io.InputStream source, java.io.OutputStream sink)
          Binary copies bytes from an input stream to an output stream.
static long streamCopy(java.io.InputStream source, java.io.OutputStream sink, ActivityProgress progress, int progressLevel)
           
static long streamCopy(java.io.InputStream source, java.io.OutputStream sink, int howMany)
          Binary copies up to the given number of bytes from an input stream to an output stream.
static long streamCopy(java.io.InputStream source, java.io.OutputStream sink, int howMany, java.security.MessageDigest digest)
          Binary copies up to the given number of bytes from an input stream to an output stream.
static long streamCopyWithChecksum(java.io.InputStream source, java.io.OutputStream sink, int howMany)
          Binary copies up to the given number of bytes from an input stream to an output stream.
static long textCopy(java.io.Reader source, java.io.Writer sink)
          Copies text from a read to a writer.
static long textCopy(java.io.Reader source, java.io.Writer sink, ActivityProgress progress, int progressLevel)
           
static long textCopy(java.io.Reader source, java.io.Writer sink, int howMany)
          Binary copies up to the given number of bytes from an input stream to an output stream.
static void writeBytesToStream(byte[] bytes, java.io.OutputStream outie)
          Writes the given bytes to the given OutputStream.
static void writeTextToStream(java.lang.String text, java.io.OutputStream outie)
          Writes the given String to the given OutputStream.
static void writeTextToWriter(java.lang.String text, java.io.Writer writer)
          Writes the given String to the given Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

IOLib

public IOLib()
Method Detail

readTextFromStream

public static java.lang.String readTextFromStream(java.io.InputStream innie)
                                           throws java.io.IOException
Reads the entirety of the given input stream in as a String and returns the result.

Throws:
java.io.IOException

readTextFromReader

public static java.lang.String readTextFromReader(java.io.Reader reader)
                                           throws java.io.IOException
Reads the entirety of the given reader in as a String and returns the result.

Throws:
java.io.IOException

writeTextToStream

public static void writeTextToStream(java.lang.String text,
                                     java.io.OutputStream outie)
                              throws java.io.IOException
Writes the given String to the given OutputStream.

Throws:
java.io.IOException

writeTextToWriter

public static void writeTextToWriter(java.lang.String text,
                                     java.io.Writer writer)
                              throws java.io.IOException
Writes the given String to the given Writer. This is included for symmetry, but you can just use writer.write(text).

Throws:
java.io.IOException

readBytesFromStream

public static byte[] readBytesFromStream(java.io.InputStream innie)
                                  throws java.io.IOException
Reads the entirety of the given input stream in as a byte array and returns the result.

Throws:
java.io.IOException

writeBytesToStream

public static void writeBytesToStream(byte[] bytes,
                                      java.io.OutputStream outie)
                               throws java.io.IOException
Writes the given bytes to the given OutputStream.

Throws:
java.io.IOException

streamCopy

public static long streamCopy(java.io.InputStream source,
                              java.io.OutputStream sink)
                       throws java.io.IOException
Binary copies bytes from an input stream to an output stream. The process is buffered, so you shouldn't need BufferedInput/OutputStreams. Flushes when it's finished, but does not close either stream. Returns the number of bytes copied.

Throws:
java.io.IOException

streamCopy

public static long streamCopy(java.io.InputStream source,
                              java.io.OutputStream sink,
                              ActivityProgress progress,
                              int progressLevel)
                       throws java.io.IOException
Throws:
java.io.IOException

streamCopy

public static long streamCopy(java.io.InputStream source,
                              java.io.OutputStream sink,
                              int howMany)
                       throws java.io.IOException
Binary copies up to the given number of bytes from an input stream to an output stream. The process is buffered, so you shouldn't need BufferedInput/OutputStreams. Flushes when it's finished, but does not close either stream. Throws an EOFExeption if there aren't enough bytes available to transfer the requested amount. Returns the total number of bytes copied.

Throws:
java.io.IOException

streamCopy

public static long streamCopy(java.io.InputStream source,
                              java.io.OutputStream sink,
                              int howMany,
                              java.security.MessageDigest digest)
                       throws java.io.IOException
Binary copies up to the given number of bytes from an input stream to an output stream. The process is buffered, so you shouldn't need BufferedInput/OutputStreams. Flushes when it's finished, but does not close either stream. Throws an EOFExeption if there aren't enough bytes available to transfer the requested amount. Returns the total number of bytes copied.

Throws:
java.io.IOException

textCopy

public static long textCopy(java.io.Reader source,
                            java.io.Writer sink)
                     throws java.io.IOException
Copies text from a read to a writer. The process is buffered, so you shouldn't need BufferedReader/BufferedWriter. Flushes when it's finished, but does not close either stream. Returns the number of bytes copied.

Throws:
java.io.IOException

textCopy

public static long textCopy(java.io.Reader source,
                            java.io.Writer sink,
                            ActivityProgress progress,
                            int progressLevel)
                     throws java.io.IOException
Throws:
java.io.IOException

textCopy

public static long textCopy(java.io.Reader source,
                            java.io.Writer sink,
                            int howMany)
                     throws java.io.IOException
Binary copies up to the given number of bytes from an input stream to an output stream. The process is buffered, so you shouldn't need BufferedInput/Writers. Flushes when it's finished, but does not close either stream. Throws an EOFExeption if there aren't enough bytes available to transfer the requested amount. Returns the total number of bytes copied.

Throws:
java.io.IOException

dataToStream

public static long dataToStream(java.io.DataInput source,
                                java.io.OutputStream sink,
                                int howMany)
                         throws java.io.IOException
Throws:
java.io.IOException

dataToStream

public static long dataToStream(java.io.DataInput source,
                                java.io.OutputStream sink,
                                int howMany,
                                java.security.MessageDigest digest)
                         throws java.io.IOException
Binary copies up to the given number of bytes from a DataInput object to an output stream. The process is buffered, so you shouldn't need BufferedInput/OutputStreams. Flushes when it's finished, but does not close either stream. Throws an EOFExeption if there aren't enough bytes available to transfer the requested amount. Returns the total number of bytes copied.

Throws:
java.io.IOException

streamCopyWithChecksum

public static long streamCopyWithChecksum(java.io.InputStream source,
                                          java.io.OutputStream sink,
                                          int howMany)
                                   throws java.io.IOException
Binary copies up to the given number of bytes from an input stream to an output stream. The process is buffered, so you shouldn't need BufferedInput/OutputStreams. Flushes when it's finished, but does not close either stream. Throws an EOFExeption if there aren't enough bytes available to transfer the requested amount. Returns the checksum of the bytes copied.

Throws:
java.io.IOException

dataCopy

public static long dataCopy(java.io.DataInput source,
                            java.io.DataOutput sink,
                            int howMany)
                     throws java.io.IOException
Binary copies up to the given number of bytes from a DataInput object to an DataOutput object. The process is buffered. Since DataOutput doesn't support closing or flushing, it does neither. Returns the total number of bytes copied.

Throws:
java.io.IOException

checksum

public static long checksum(byte[] victim)
                     throws java.io.IOException
Generates a checksum for the given byte array.

Throws:
java.io.IOException