org.littleshoot.util
Class IoUtils

java.lang.Object
  extended by org.littleshoot.util.IoUtils

public final class IoUtils
extends Object

Utility functions for IO.


Constructor Summary
IoUtils()
           
 
Method Summary
static long copy(InputStream in, OutputStream out, long originalByteCount)
          Copies the InputStream to the specified OutputStream for the specified number of bytes or until EOF or exception.
static int copy(InputStream is, OutputStream os, WriteListener listener)
          Copy bytes from an InputStream to an OutputStream.
static long copy(InputStream is, RandomAccessFile raf, long offset, long length)
          Copy method for copying data from an InputStream to a RandomAccessFile.
static long copy(InputStream is, RandomAccessFile raf, long offset, long length, LongRangeListener lrl, WriteListener wl)
          Copy method for copying data from an InputStream to a RandomAccessFile.
static byte[] deflate(String str)
           
static byte[] inflate(byte[] bytes)
           
static String inflateString(byte[] bytes)
           
static byte[] toByteArray(InputStream is, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IoUtils

public IoUtils()
Method Detail

toByteArray

public static byte[] toByteArray(InputStream is,
                                 int length)
                          throws IOException
Throws:
IOException

copy

public static int copy(InputStream is,
                       OutputStream os,
                       WriteListener listener)
                throws IOException
Copy bytes from an InputStream to an OutputStream.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

Parameters:
is - The InputStream to read from
os - The OutputStream to write to
listener - The listener for write events.
Returns:
the number of bytes copied
Throws:
NullPointerException - if the input or output is null
IOException - if an I/O error occurs

copy

public static long copy(InputStream in,
                        OutputStream out,
                        long originalByteCount)
                 throws IOException
Copies the InputStream to the specified OutputStream for the specified number of bytes or until EOF or exception.

Parameters:
in - The InputStream to copy from.
out - The OutputStream to copy to.
originalByteCount - The number of bytes to copy.
Returns:
The number of bytes written.
Throws:
IOException - If there's an IO error copying the bytes.

copy

public static long copy(InputStream is,
                        RandomAccessFile raf,
                        long offset,
                        long length)
                 throws IOException
Copy method for copying data from an InputStream to a RandomAccessFile.

Parameters:
is - The input data.
raf - The file to write to.
offset - The offset within the file to start writing at.
length - The number of bytes to copy.
Returns:
The number of bytes copied.
Throws:
IOException - If any IO error occurs.

copy

public static long copy(InputStream is,
                        RandomAccessFile raf,
                        long offset,
                        long length,
                        LongRangeListener lrl,
                        WriteListener wl)
                 throws IOException
Copy method for copying data from an InputStream to a RandomAccessFile.

Parameters:
is - The input data.
raf - The file to write to.
offset - The offset within the file to start writing at.
length - The number of bytes to copy.
Returns:
The number of bytes copied.
Throws:
IOException - If any IO error occurs.

deflate

public static byte[] deflate(String str)

inflateString

public static String inflateString(byte[] bytes)

inflate

public static byte[] inflate(byte[] bytes)


Copyright © 2011-2013 LittleShoot. All Rights Reserved.