org.archive.wayback.util
Class ByteOp

java.lang.Object
  extended by org.archive.wayback.util.ByteOp

public class ByteOp
extends Object

Byte oriented static methods. Likely a lot of overlap with apache- commons stuff - eventually should be reconciled.

Author:
brad

Field Summary
static int BUFFER_SIZE
          Default buffer size for IO ops
 
Constructor Summary
ByteOp()
           
 
Method Summary
static boolean cmp(byte[] a, byte[] b)
          Compare two byte arrays
static byte[] copy(byte[] src, int offset, int length)
          Create a new byte array with contents initialized to values from the argument byte array.
static void copyStream(InputStream is, OutputStream os)
          Write all bytes from is to os.
static void copyStream(InputStream is, OutputStream os, int size)
          Write all bytes from is to os.
static void discardStream(InputStream is)
          throw away all bytes from stream argument
static void discardStream(InputStream is, int size)
          throw away all bytes from stream argument
static long discardStreamCount(InputStream is)
          throw away all bytes from stream argument, and count how many bytes were discarded before reaching the end of the stream.
static long discardStreamCount(InputStream is, int size)
          throw away all bytes from stream argument, and count how many bytes were discarded before reaching the end of the stream.
 
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
Default buffer size for IO ops

See Also:
Constant Field Values
Constructor Detail

ByteOp

public ByteOp()
Method Detail

copy

public static byte[] copy(byte[] src,
                          int offset,
                          int length)
Create a new byte array with contents initialized to values from the argument byte array.

Parameters:
src - source byte array of initial values
offset - start offset to copy bytes
length - number of bytes to copy
Returns:
a new byte array of size length, containing values from src starting from offset in the src array.

cmp

public static boolean cmp(byte[] a,
                          byte[] b)
Compare two byte arrays

Parameters:
a - byte array to compare
b - byte array to compare
Returns:
true if a and b have same length, and all the same values, false otherwise

discardStream

public static void discardStream(InputStream is)
                          throws IOException
throw away all bytes from stream argument

Parameters:
is - InputStream to read and discard
Throws:
IOException - when is throws one

discardStream

public static void discardStream(InputStream is,
                                 int size)
                          throws IOException
throw away all bytes from stream argument

Parameters:
is - InputStream to read and discard
size - number of bytes to read at once from the stream
Throws:
IOException - when is throws one

discardStreamCount

public static long discardStreamCount(InputStream is)
                               throws IOException
throw away all bytes from stream argument, and count how many bytes were discarded before reaching the end of the stream.

Parameters:
is - InputStream to read and discard
Returns:
the number of bytes discarded
Throws:
IOException - when is throws one

discardStreamCount

public static long discardStreamCount(InputStream is,
                                      int size)
                               throws IOException
throw away all bytes from stream argument, and count how many bytes were discarded before reaching the end of the stream.

Parameters:
is - InputStream to read and discard
size - number of bytes to read at once from the stream
Returns:
the number of bytes discarded
Throws:
IOException - when is throws one

copyStream

public static void copyStream(InputStream is,
                              OutputStream os)
                       throws IOException
Write all bytes from is to os. Does not close either stream.

Parameters:
is - to copy bytes from
os - to copy bytes to
Throws:
IOException - for usual reasons

copyStream

public static void copyStream(InputStream is,
                              OutputStream os,
                              int size)
                       throws IOException
Write all bytes from is to os. Does not close either stream.

Parameters:
is - to copy bytes from
os - to copy bytes to
size - number of bytes to buffer between read and write operations
Throws:
IOException - for usual reasons


Copyright © 2005-2011 Internet Archive. All Rights Reserved.