net.ontopia.utils
Class StreamUtils

java.lang.Object
  extended by net.ontopia.utils.StreamUtils

public class StreamUtils
extends Object

INTERNAL: Utilities for working with streams and readers.

Since:
1.3.3

Constructor Summary
StreamUtils()
           
 
Method Summary
static boolean compare(InputStream r1, InputStream r2)
          INTERNAL: Compares the contents of the two InputStreams for equality.
static boolean compare(Reader r1, Reader r2)
          INTERNAL: Compares the contents of the two Readers for equality.
static boolean compareAndClose(InputStream r1, InputStream r2)
          INTERNAL: Compares the contents of the two InputStream for equality and closes them afterwards.
static InputStream getInputStream(File basedir, String name)
          INTERNAL: Returns an input stream for the given url.
static InputStream getInputStream(String name)
          INTERNAL: Same as getInputStream(null, name);
static URL getResource(String name)
          INTERNAL: Returns an input stream for the given url.
static byte[] read(InputStream in)
          INTERNAL: Returns the entire contents of a stream as a byte array.
static byte[] read(InputStream in, int length)
          INTERNAL: Returns the first given number of bytes of a stream into a byte array.
static String read(Reader in)
          INTERNAL: Returns the entire contents of a stream (well, Reader) as a string.
static String readString(Reader r, long length)
           
static void transfer(InputStream in, OutputStream out)
          INTERNAL: Transfers the entire contents of the InputStream to the OutputStream without modifying them in any way.
static void transfer(Reader in, Writer out)
          INTERNAL: Transfers the entire contents of the Reader to the Writer without modifying them in any way.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtils

public StreamUtils()
Method Detail

transfer

public static void transfer(InputStream in,
                            OutputStream out)
                     throws IOException
INTERNAL: Transfers the entire contents of the InputStream to the OutputStream without modifying them in any way.

Throws:
IOException

transfer

public static void transfer(Reader in,
                            Writer out)
                     throws IOException
INTERNAL: Transfers the entire contents of the Reader to the Writer without modifying them in any way.

Throws:
IOException
Since:
2.0.4

read

public static String read(Reader in)
                   throws IOException
INTERNAL: Returns the entire contents of a stream (well, Reader) as a string.

Throws:
IOException
Since:
1.4

read

public static byte[] read(InputStream in,
                          int length)
                   throws IOException
INTERNAL: Returns the first given number of bytes of a stream into a byte array.

Throws:
IOException
Since:
2.0

read

public static byte[] read(InputStream in)
                   throws IOException
INTERNAL: Returns the entire contents of a stream as a byte array.

Throws:
IOException
Since:
3.3.0

compare

public static boolean compare(InputStream r1,
                              InputStream r2)
                       throws IOException
INTERNAL: Compares the contents of the two InputStreams for equality.

Throws:
IOException
Since:
4.0

compareAndClose

public static boolean compareAndClose(InputStream r1,
                                      InputStream r2)
                               throws IOException
INTERNAL: Compares the contents of the two InputStream for equality and closes them afterwards.

Throws:
IOException

compare

public static boolean compare(Reader r1,
                              Reader r2)
                       throws IOException
INTERNAL: Compares the contents of the two Readers for equality.

Throws:
IOException
Since:
4.0

getInputStream

public static InputStream getInputStream(String name)
                                  throws IOException
INTERNAL: Same as getInputStream(null, name);

Throws:
IOException
Since:
3.4.3

getInputStream

public static InputStream getInputStream(File basedir,
                                         String name)
                                  throws IOException
INTERNAL: Returns an input stream for the given url. Supports file: and classpath:. If no scheme given then file system will be checked before classpath. Exception will be thrown if resource is not found when scheme is given. If no scheme was given null is returned. File references will be interpreted relative to basedir. If basedir is null, it will be ignored.

Throws:
IOException
Since:
5.1.1

getResource

public static URL getResource(String name)
                       throws IOException
INTERNAL: Returns an input stream for the given url. Supports file: and classpath:. If no schema given then file system will be checked before classpath. Exception will be thrown if resource is not found when schema is given. If no schema was given null is returned.

Throws:
IOException
Since:
3.4.3

readString

public static String readString(Reader r,
                                long length)
                         throws IOException
Throws:
IOException


Copyright © 2000-2012 Ontopia.