Multivalent API

phelps.io
Class InputStreams

java.lang.Object
  extended by phelps.io.InputStreams

public class InputStreams
extends java.lang.Object

Utilities for InputStreams.

Version:
$Revision: 1.5 $ $Date: 2005/01/15 13:07:42 $

Field Summary
static java.io.InputStream DEVNULL
          InputStream that always reports end of file (-1) on read.
static java.io.InputStream DEVRANDOM
          InputStream that returns a random number (0..255) on read.
static java.io.InputStream DEVZERO
          InputStream that always returns 0 on read.
 
Method Summary
static long copy(java.io.InputStream is, java.io.OutputStream out)
          Convenience method for copy(in, out, false).
static long copy(java.io.InputStream is, java.io.OutputStream out, boolean fclose)
           
static long copy(java.io.InputStream is, java.io.OutputStream out, boolean fclose, int length)
          Copy contents of is to out.
static void copy(java.io.InputStream is, com.pt.io.RandomAccess ra)
          Copies rest of is to ra, which should be writable.
static long crc32(java.io.InputStream is)
          Returns CRC32 checksum of is.
static void readFully(java.io.InputStream is, byte[] b)
           
static void readFully(java.io.InputStream is, byte[] b, int off, int len)
          Reads exactly len bytes from this file into the byte array.
static void skipFully(java.io.InputStream is, long length)
          Skips length bytes, unless reach end of stream.
static byte[] toByteArray(java.io.InputStream is)
          Reads the rest of is and returns contents.
static byte[] toByteArray(java.io.InputStream is, long estlength)
          Reads the rest of is and returns contents.
static java.io.InputStream uncompress(java.io.InputStream is, java.lang.String type)
          Wraps is with another stream that uncompresses it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEVNULL

public static final java.io.InputStream DEVNULL
InputStream that always reports end of file (-1) on read.


DEVZERO

public static final java.io.InputStream DEVZERO
InputStream that always returns 0 on read.


DEVRANDOM

public static final java.io.InputStream DEVRANDOM
InputStream that returns a random number (0..255) on read.

Method Detail

crc32

public static long crc32(java.io.InputStream is)
                  throws java.io.IOException
Returns CRC32 checksum of is.

Throws:
java.io.IOException

readFully

public static void readFully(java.io.InputStream is,
                             byte[] b,
                             int off,
                             int len)
                      throws java.io.IOException
Reads exactly len bytes from this file into the byte array.

Throws:
java.io.EOFException - if this file reaches the end before reading all the bytes.
java.io.IOException

readFully

public static void readFully(java.io.InputStream is,
                             byte[] b)
                      throws java.io.IOException
Throws:
java.io.IOException

skipFully

public static void skipFully(java.io.InputStream is,
                             long length)
                      throws java.io.IOException
Skips length bytes, unless reach end of stream.

Throws:
java.io.IOException

uncompress

public static java.io.InputStream uncompress(java.io.InputStream is,
                                             java.lang.String type)
                                      throws java.io.IOException
Wraps is with another stream that uncompresses it. Supports suffixes Z, gz, bz2/bzip2, and all HTTP/1.1 Content-Encodings (gzip, compress, deflate, identity).

Parameters:
type - filename with compression suffix, or compression type (LZW, gzip, deflate, bzip2).
Throws:
java.io.IOException
See Also:
Files.getEncoding(String)

copy

public static long copy(java.io.InputStream is,
                        java.io.OutputStream out)
                 throws java.io.IOException
Convenience method for copy(in, out, false).

Throws:
java.io.IOException

copy

public static long copy(java.io.InputStream is,
                        java.io.OutputStream out,
                        boolean fclose)
                 throws java.io.IOException
Throws:
java.io.IOException

copy

public static long copy(java.io.InputStream is,
                        java.io.OutputStream out,
                        boolean fclose,
                        int length)
                 throws java.io.IOException
Copy contents of is to out. If fclose is true then close both streams, so a stream-to-stream copy is as simple as copy(new InputStream(), new OutputStream(), true). Neither stream needs to be buffered as block reads and writes are used (which is all that buffered streams do).

Returns:
number of bytes copied
Throws:
java.io.IOException

copy

public static void copy(java.io.InputStream is,
                        com.pt.io.RandomAccess ra)
                 throws java.io.IOException
Copies rest of is to ra, which should be writable.

Throws:
java.io.IOException

toByteArray

public static byte[] toByteArray(java.io.InputStream is)
                          throws java.io.IOException
Reads the rest of is and returns contents. Closes is.

Throws:
java.io.IOException

toByteArray

public static byte[] toByteArray(java.io.InputStream is,
                                 long estlength)
                          throws java.io.IOException
Reads the rest of is and returns contents. Closes is.

Throws:
java.io.IOException

Multivalent API