sk.uniba.euromath.tools.io
Class IOTools

java.lang.Object
  extended by sk.uniba.euromath.tools.io.IOTools

public final class IOTools
extends Object

Contains various utilities for working with streams, readers and writers.

Author:
Martin Vysny

Method Summary
static void copyCharacters(Reader in, Writer out)
          Copies all characters from reader to writer.
static void copyStream(InputStream in, OutputStream out)
          Copies all bytes from input stream to output stream.
static InputStream createEmptyInputStream()
          Produces empty input stream that is always at the end of stream data (it cannot read anything).
static Reader createEmptyReader()
          Produces empty reader that is always at the end of stream data (it cannot read anything).
static OutputStream createNullOutputStream()
          Deprecated. use NullOutputStream.
static Writer createNullWriter()
          Produces writer that throws all written data away (like null device).
static void encodeStream(Reader source, OutputStream out, String encoding)
          Deprecated. use IOUtils.copy(Reader, OutputStream, String).
static InputStream readerToInputStream(Reader reader, String encoding)
          Converts reader to an inputstream.
static String readerToString(Reader in)
          Deprecated. use IOUtils.toString(Reader)
static Reader streamSourceToReader(StreamSource ssource, String encoding)
          Returns reader from given stream source.
static InputStream stringToInputStream(String string, String encoding)
          Deprecated. use IOUtils.toInputStream(String, String).
static IPath urlToPath(URL url)
          Converts URL address to Eclipse IPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyStream

public static void copyStream(InputStream in,
                              OutputStream out)
                       throws IOException
Copies all bytes from input stream to output stream. Input stream is closed after the copy, even when an exception is thrown.

Parameters:
in - the input stream
out - the output stream
Throws:
IOException - if i/o error occurs during reading and/or writing.

copyCharacters

public static void copyCharacters(Reader in,
                                  Writer out)
                           throws IOException
Copies all characters from reader to writer. Reader is closed after the copy, even when an exception is thrown.

Parameters:
in - the input stream
out - the output stream
Throws:
IOException - if i/o error occurs during reading and/or writing.

readerToString

@Deprecated
public static String readerToString(Reader in)
                             throws IOException
Deprecated. use IOUtils.toString(Reader)

Reads all characters from a reader and returns them as a string.

Parameters:
in - input reader
Returns:
string containing all characters read.
Throws:
IOException - if i/o error occurs during reading.

createEmptyInputStream

public static InputStream createEmptyInputStream()
Produces empty input stream that is always at the end of stream data (it cannot read anything).

Returns:
empty input stream.

createEmptyReader

public static Reader createEmptyReader()
Produces empty reader that is always at the end of stream data (it cannot read anything).

Returns:
empty reader.

createNullOutputStream

@Deprecated
public static OutputStream createNullOutputStream()
Deprecated. use NullOutputStream.

Produces output stream that throws all written data away (like null device).

Returns:
null output stream.

createNullWriter

public static Writer createNullWriter()
Produces writer that throws all written data away (like null device).

Returns:
null writer.

streamSourceToReader

public static Reader streamSourceToReader(StreamSource ssource,
                                          String encoding)
                                   throws UnsupportedEncodingException
Returns reader from given stream source.

Parameters:
ssource - the stream source.
encoding - if no reader is given in ssource then create one from input source using this encoding.
Returns:
reader.
Throws:
UnsupportedEncodingException - if encoding is not known.

urlToPath

public static IPath urlToPath(URL url)
Converts URL address to Eclipse IPath. It must point into a local file.

Parameters:
url - url address to convert.
Returns:
IPath instance.
Throws:
IllegalArgumentException - if given URL is not file:/ address.

stringToInputStream

@Deprecated
public static InputStream stringToInputStream(String string,
                                                         String encoding)
                                       throws IOException
Deprecated. use IOUtils.toInputStream(String, String).

Converts string to an inputstream.

Parameters:
string - the source.
encoding - the encoding.
Returns:
inputstream that reads from given string. Do not forget to close this stream, otherwise the encoding thread may never end.
Throws:
IOException

readerToInputStream

public static InputStream readerToInputStream(Reader reader,
                                              String encoding)
                                       throws IOException
Converts reader to an inputstream.

Parameters:
reader - reader to poll
encoding - the encoding.
Returns:
inputstream that reads from given reader. Do not forget to close this stream, otherwise the encoding thread may never end.
Throws:
IOException - if construction of inputstream fails.

encodeStream

@Deprecated
public static void encodeStream(Reader source,
                                           OutputStream out,
                                           String encoding)
                         throws IOException
Deprecated. use IOUtils.copy(Reader, OutputStream, String).

Encodes given input character stream into a stream of bytes. Closes the source on succesfull finish. Replaces all malformed and unmappable characters with '?'.

Parameters:
source - source reader, must not be null.
out - the sink, must not be null.
encoding - encode characters with this encoder, must not be null.
Throws:
IOException - if io error occurs.


Copyright 2003-2003-2006 null. All Rights Reserved.