org.openrdf.util.io
Class IOUtil

java.lang.Object
  extended byorg.openrdf.util.io.IOUtil

public final class IOUtil
extends Object


Constructor Summary
IOUtil()
           
 
Method Summary
static byte[] readBytes(InputStream in, int maxBytes)
          Reads at most maxBytes bytes from the supplied input stream and returns them as a byte array.
static byte[] readFully(InputStream in)
          Fully reads the bytes available from the supplied InputStream and returns these bytes in a byte array.
static String readFully(Reader reader)
          Fully reads the characters available from the supplied Reader and returns these characters as a String object.
static long transfer(InputStream in, OutputStream out)
          Transfers all bytes that can be read from in to out.
static long transfer(Reader in, Writer out)
          Transfers all characters that can be read from in to out.
static long writeToFile(InputStream in, File file)
          Writes all bytes from an InputStream to a file.
static long writeToFile(Reader reader, File file)
          Writes all characters from a Reader to a file using the default character encoding.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtil

public IOUtil()
Method Detail

transfer

public static final long transfer(InputStream in,
                                  OutputStream out)
                           throws IOException
Transfers all bytes that can be read from in to out.

Parameters:
in - The InputStream to read data from.
out - The OutputStream to write data to.
Returns:
The total number of bytes transfered.
Throws:
IOException

readFully

public static final byte[] readFully(InputStream in)
                              throws IOException
Fully reads the bytes available from the supplied InputStream and returns these bytes in a byte array.

Parameters:
in - The InputStream to read the bytes from.
Returns:
A byte array containing the bytes that were read.
Throws:
IOException - If I/O error occurred.

readBytes

public static final byte[] readBytes(InputStream in,
                                     int maxBytes)
                              throws IOException
Reads at most maxBytes bytes from the supplied input stream and returns them as a byte array.

Parameters:
in - The InputStream supplying the bytes.
maxBytes - The maximum number of bytes to read from the input stream.
Returns:
A byte array of size maxBytes if the input stream can produce that amount of bytes, or a smaller byte containing all available bytes from the stream otherwise.
Throws:
IOException

writeToFile

public static final long writeToFile(InputStream in,
                                     File file)
                              throws IOException
Writes all bytes from an InputStream to a file.

Parameters:
in - The InputStream containing the data to write to the file.
file - The file to write the data to.
Returns:
The total number of bytes written.
Throws:
IOException - If an I/O error occured while trying to write the data to the file.

transfer

public static final long transfer(Reader in,
                                  Writer out)
                           throws IOException
Transfers all characters that can be read from in to out.

Parameters:
in - The Reader to read characters from.
out - The Writer to write characters to.
Returns:
The total number of characters transfered.
Throws:
IOException

readFully

public static final String readFully(Reader reader)
                              throws IOException
Fully reads the characters available from the supplied Reader and returns these characters as a String object.

Parameters:
reader - The Reader to read the characters from.
Returns:
A String existing of the characters that were read.
Throws:
IOException - If I/O error occurred.

writeToFile

public static final long writeToFile(Reader reader,
                                     File file)
                              throws IOException
Writes all characters from a Reader to a file using the default character encoding.

Parameters:
reader - The Reader containing the data to write to the file.
file - The file to write the data to.
Returns:
The total number of characters written.
Throws:
IOException - If an I/O error occured while trying to write the data to the file.
See Also:
FileWriter


Copyright © 2002-2006 Aduna BV, GNU LGPL License applies.