ProgramixGenericLib v5.0.1

com.programix.io
Class IOTools

java.lang.Object
  extended by com.programix.io.IOTools

public class IOTools
extends Object

Handy tools for working with I/O.

Author:
Paul Hyde

Nested Class Summary
static class IOTools.BaseDirectoryResourceLocator
          An implementation of IOTools.ResourceLocator that uses the specified base directory to try to locate resources.
static class IOTools.ClassLoaderResourceLocator
          An implementation of IOTools.ResourceLocator that uses the specified Class to try to locate resources.
static class IOTools.ObjectStreamPair
          An immutable holder of an ObjectInputStream and ObjectOutputStream pair.
static interface IOTools.ResourceLocator
          A ResourceLocator is used to assist in finding and opening InputStream's and URL's for an application based on the resources name.
static class IOTools.ServletResourceLocator
          An implementation of IOTools.ResourceLocator that uses the specified HttpServlet to try to locate resources.
 
Field Summary
static int DEFAULT_BUFFER_SIZE
          The default buffer size that is used with streams in the tools class.
static int EOS
          Constant for "end of stream" or more loosely "end of file".
 
Method Summary
static void closeQuietly(InputStream in)
          Closes the specified stream and suppresses any IOException's that may be thrown.
static void closeQuietly(InputStream in, OutputStream out)
          Closes the OutputStream and the InputStream [in that order].
static void closeQuietly(OutputStream out)
          Closes the specified stream and suppresses any IOException's that may be thrown.
static void closeQuietly(Reader in)
          Closes the specified stream and suppresses any IOException's that may be thrown.
static void closeQuietly(ServerSocket ss)
          Closes the specified ServerSocket and suppresses any IOException's that may be thrown.
static void closeQuietly(Socket socket)
          Closes the specified Socket and suppresses any IOException's that may be thrown.
static void closeQuietly(Socket socket, InputStream in, OutputStream out)
          Closes the OutputStream, InputStream, and Socket [in that order].
static void closeQuietly(Socket socket, Reader in, Writer out)
          Closes the Writer, Reader, and Socket [in that order].
static void closeQuietly(Writer out)
          Closes the specified stream and suppresses any IOException's that may be thrown.
static int copy(File source, File destination)
          Copies bytes between the files with the DEFAULT_BUFFER_SIZE and closes both streams after the copy is complete.
static int copy(InputStream in, boolean closeInputStream, OutputStream out, boolean closeOutputStream)
          Copies bytes between the streams with the DEFAULT_BUFFER_SIZE.
static int copy(InputStream in, boolean closeInputStream, OutputStream out, boolean closeOutputStream, int transferBufferSize)
          Copies all the bytes from the InputStream to the OutputStream.
static int copy(InputStream in, OutputStream out)
          Copies bytes between the streams with the DEFAULT_BUFFER_SIZE and closes both streams after the copy is complete.
static BufferedReader createBufferedReader(File source)
          Creates a BufferedReader using the default InputStreamReader.
static BufferedReader createBufferedReader(InputStream rawIn)
          Creates a BufferedReader using the default InputStreamReader constructor.
static BufferedReader createBufferedReader(Socket socket)
          Creates a BufferedReader using the default InputStreamReader.
static BufferedReader createBufferedReader(URL source)
          Creates a BufferedReader using the default InputStreamReader.
static BufferedReader createBufferedReaderFromFile(String filename)
          Creates a BufferedReader using the default InputStreamReader.
static BufferedReader createBufferedReaderFromResource(String resourceLocation)
          Creates a BufferedReader using the default InputStreamReader.
static BufferedReader createBufferedReaderFromResource(String resourceLocation, Class<?> searchStartPoint)
          Creates a BufferedReader using the default InputStreamReader.
static BufferedWriter createBufferedWriter(File destination)
          Creates a BufferedWriter using the default OutputStreamWriter.
static BufferedWriter createBufferedWriter(OutputStream rawOut)
          Creates a BufferedWriter using the default OutputStreamWriter constructor.
static BufferedWriter createBufferedWriter(Socket socket)
          Creates a BufferedWriter using the default OutputStreamWriter.
static BufferedWriter createBufferedWriterToFile(String filename)
          Creates a BufferedWriter using the default OutputStreamWriter.
static DataInputStream createDataInputStream(File source)
          Creates a DataInputStream with buffering.
static DataInputStream createDataInputStream(InputStream rawIn)
          Creates a DataInputStream and adds buffering by wrapping a BufferedInputStream around the supplied InputStream, rawIn.
static DataInputStream createDataInputStream(Socket socket)
          Creates a DataInputStream with buffering.
static DataInputStream createDataInputStream(URL source)
          Creates a DataInputStream with buffering.
static DataInputStream createDataInputStreamFromFile(String filename)
          Creates a DataInputStream with buffering.
static DataInputStream createDataInputStreamFromResource(String resourceLocation)
          Creates a buffered DataInputStream.
static DataInputStream createDataInputStreamFromResource(String resourceLocation, Class<?> searchStartPoint)
          Creates a buffered DataInputStream.
static DataOutputStream createDataOutputStream(File destination)
          Creates a DataOutputStream with buffering.
static DataOutputStream createDataOutputStream(OutputStream rawOut)
          Creates a DataOutputStream and adds buffering by wrapping a BufferedOutputStream around the supplied OutputStream, rawOut.
static DataOutputStream createDataOutputStream(Socket socket)
          Creates a DataOutputStream with buffering.
static DataOutputStream createDataOutputStreamToFile(String filename)
          Creates a DataOutputStream with buffering.
static ObjectInputStream createObjectInputStream(File source)
          Creates an ObjectInputStream with buffering.
static ObjectInputStream createObjectInputStream(InputStream rawIn)
          Creates an ObjectInputStream and adds buffering by wrapping a BufferedInputStream around the supplied InputStream, rawIn.
static ObjectInputStream createObjectInputStream(Socket socket)
          Creates an ObjectInputStream with buffering.
static ObjectInputStream createObjectInputStream(URL source)
          Creates an ObjectInputStream with buffering.
static ObjectInputStream createObjectInputStreamFromFile(String filename)
          Creates an ObjectInputStream with buffering.
static ObjectInputStream createObjectInputStreamFromResource(String resourceLocation)
          Creates a buffered ObjectInputStream.
static ObjectInputStream createObjectInputStreamFromResource(String resourceLocation, Class<?> searchStartPoint)
          Creates a buffered ObjectInputStream.
static ObjectOutputStream createObjectOutputStream(File destination)
          Creates an ObjectOutputStream with buffering.
static ObjectOutputStream createObjectOutputStream(OutputStream rawOut)
          Creates an ObjectOutputStream and adds buffering by wrapping a BufferedOutputStream around the supplied OutputStream, rawOut.
static ObjectOutputStream createObjectOutputStream(Socket socket)
          Creates an ObjectOutputStream with buffering.
static ObjectOutputStream createObjectOutputStreamToFile(String filename)
          Creates an ObjectOutputStream with buffering.
static IOTools.ObjectStreamPair createObjectStreamsAsync(InputStream rawIn, OutputStream rawOut)
          Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream.
static IOTools.ObjectStreamPair createObjectStreamsAsync(Socket socket)
          Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream.
static IOTools.ObjectStreamPair createObjectStreamsForClient(InputStream rawIn, OutputStream rawOut)
          Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream.
static IOTools.ObjectStreamPair createObjectStreamsForClient(Socket socket)
          Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream.
static IOTools.ObjectStreamPair createObjectStreamsForServer(InputStream rawIn, OutputStream rawOut)
          Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream.
static IOTools.ObjectStreamPair createObjectStreamsForServer(Socket socket)
          Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified Socket's streams.
static InputStream getInputStreamForResource(String resourceLocation)
          Returns an InputStream to read data from the specified resourceLocation.
static InputStream getInputStreamForResource(String resourceLocation, Class<?> searchStartPoint)
          Returns an InputStream to read data from the specified resourceLocation.
static URL getUrlForResource(String resourceLocation)
          Returns a URL to access the specified resourceLocation using IOTools.class as a starting point.
static URL getUrlForResource(String resourceLocation, Class<?> searchStartPoint)
          Returns a URL to access the specified resourceLocation.
static void prependResourceLocator(IOTools.ResourceLocator locator)
          Adds the specified locator to the beginning of the list of IOTools.ResourceLocator's to use when searching for resources.
static byte[] readAll(File source)
          Reads the entire file and returns all the data read in a byte[].
static byte[] readAll(InputStream rawIn)
          Reads the entire stream and returns all the data read in a byte[].
static byte[] readAll(Socket socket)
          Reads the entire stream of data from the Socket and returns all the data read in a byte[].
static byte[] readAll(URL source)
          Reads the entire stream of data from the URL and returns all the data read in a byte[].
static byte[] readAllFromFile(String filename)
          Reads the entire file and returns all the data read in a byte[].
static byte[] readAllFromResource(String resourceLocation)
          Reads the entire stream from the specified resourceLocation and returns all the data read in a byte[].
static byte[] readAllFromResource(String resourceLocation, Class<?> searchStartPoint)
          Reads the entire stream from the specified resourceLocation and returns all the data read in a byte[].
static String[] readAllLines(BufferedReader in)
          Reads the entire stream of characters and returns all the lines read in a String[].
static String[] readAllLines(File source)
          Reads the entire file converting bytes to characters using the default InputStreamReader and returns all the lines read in a String[].
static String[] readAllLines(InputStream rawIn)
          Reads the entire stream of bytes converting them to characters using the default InputStreamReader and returns all the lines read in a String[].
static String[] readAllLines(Reader in)
          Reads the entire stream of characters and returns all the lines read in a String[].
static String[] readAllLines(URL source)
          Reads the entire stream of data from the URL converting bytes to characters using the default InputStreamReader and returns all the lines read in a String[].
static String[] readAllLinesFromFile(String filename)
          Reads the entire file converting bytes to characters using the default InputStreamReader and returns all the lines read in a String[].
static String[] readAllLinesFromResource(String resourceLocation)
          Reads the entire stream from the specified resourceLocation and returns all the data read in a String[].
static String[] readAllLinesFromResource(String resourceLocation, Class<?> searchStartPoint)
          Reads the entire stream from the specified resourceLocation and returns all the data read in a String[].
static boolean removeResourceLocator(IOTools.ResourceLocator rl)
          Removes the specified ResourceLocator from the list if it exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOS

public static final int EOS
Constant for "end of stream" or more loosely "end of file". The value of this constant is -1 (the value that is so commonly used throughout Java I/O to indicate end of stream/file).

See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default buffer size that is used with streams in the tools class. This value is always 2048.

See Also:
Constant Field Values
Method Detail

copy

public static int copy(InputStream in,
                       boolean closeInputStream,
                       OutputStream out,
                       boolean closeOutputStream,
                       int transferBufferSize)
                throws IOException
Copies all the bytes from the InputStream to the OutputStream. The InputStream is read until the end of stream is detected. The OutputStream is flushed after the final transfer.

Parameters:
in - the stream to read bytes from
closeInputStream - if true, close the InputStream after reaching the end-of-stream.
out - the stream to write bytes out to
closeOutputStream - if true, close the OutputStream after writing and flushing the final bytes that were read from the InputStream.
transferBufferSize - the byte-size of the internally allocated buffer.
Returns:
the number of bytes copied.
Throws:
IOException - if there is a transfer problem

copy

public static int copy(InputStream in,
                       boolean closeInputStream,
                       OutputStream out,
                       boolean closeOutputStream)
                throws IOException
Copies bytes between the streams with the DEFAULT_BUFFER_SIZE. Equivalent to:
 return copy(in, closeInputStream,
             out, closeOutputStream, DEFAULT_BUFFER_SIZE);
 

Throws:
IOException
See Also:
copy(InputStream, boolean, OutputStream, boolean, int)

copy

public static int copy(InputStream in,
                       OutputStream out)
                throws IOException
Copies bytes between the streams with the DEFAULT_BUFFER_SIZE and closes both streams after the copy is complete. Equivalent to:
 return copy(in, true, out, true, DEFAULT_BUFFER_SIZE);
 

Throws:
IOException
See Also:
copy(InputStream, boolean, OutputStream, boolean, int)

copy

public static int copy(File source,
                       File destination)
                throws FileNotFoundException,
                       IOException
Copies bytes between the files with the DEFAULT_BUFFER_SIZE and closes both streams after the copy is complete. If an exception is thrown, any streams that were successfully opened are automatically closed. Equivalent to:
 return copy(new FileInputStream(source), true,
             new FileOutputStream(destination), true,
             DEFAULT_BUFFER_SIZE);
 

Throws:
FileNotFoundException
IOException
See Also:
copy(InputStream, boolean, OutputStream, boolean, int)

prependResourceLocator

public static void prependResourceLocator(IOTools.ResourceLocator locator)
                                   throws IllegalArgumentException
Adds the specified locator to the beginning of the list of IOTools.ResourceLocator's to use when searching for resources. This is a VM-wide setting. The last locator prepended will be the first one to be used when looking for resources.

Parameters:
locator - the resource locator to place at the front of the search locations.
Throws:
IllegalArgumentException - if null is passed in
See Also:
IOTools.ClassLoaderResourceLocator, IOTools.ServletResourceLocator, IOTools.BaseDirectoryResourceLocator

removeResourceLocator

public static boolean removeResourceLocator(IOTools.ResourceLocator rl)
Removes the specified ResourceLocator from the list if it exists. See prependResourceLocator for more information.

Parameters:
rl - locator to remove
Returns:
true if the locator was found and removed, false if the specified locator was not found (or if null is passed in).

getUrlForResource

public static URL getUrlForResource(String resourceLocation,
                                    Class<?> searchStartPoint)
                             throws FileNotFoundException,
                                    IOException
Returns a URL to access the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. The getResource(String path) method on the Class object passed in is used as a starting point to locate the requested resource. After that, IOTools.class is used, and if that still doesn't work, then String.class is used. If they all fail to be able to locate the resource, then a FileNotFoundException is thrown.

Parameters:
resourceLocation - the path to the resource, with or without a leading /. If the resource is not found using name passed in, then a / is prefixed and the search is re-attempted.
searchStartPoint - the Class to invoke getResource on first. If null, then this IOTools class will be used first.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are any other problems

getUrlForResource

public static URL getUrlForResource(String resourceLocation)
                             throws FileNotFoundException,
                                    IOException
Returns a URL to access the specified resourceLocation using IOTools.class as a starting point. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation.

Equivalent to:

 return getUrlForResource(resourceLocation, null);
 

Parameters:
resourceLocation - the path to the resource, with or without a leading /. If the resource is not found using name passed in, then a / is prefixed and the search is re-attempted.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are any other problems

getInputStreamForResource

public static InputStream getInputStreamForResource(String resourceLocation,
                                                    Class<?> searchStartPoint)
                                             throws FileNotFoundException,
                                                    IOException
Returns an InputStream to read data from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation.

Equivalent to:

 return getUrlForResource(
         resourceLocation, searchStartPoint).openStream();
 

Throws:
FileNotFoundException
IOException

getInputStreamForResource

public static InputStream getInputStreamForResource(String resourceLocation)
                                             throws FileNotFoundException,
                                                    IOException
Returns an InputStream to read data from the specified resourceLocation. Uses IOTools.class as a starting point for the search. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation.

Equivalent to:

 return getInputStreamForResource(resourceLocation, null);
 

Throws:
FileNotFoundException
IOException

readAll

public static byte[] readAll(InputStream rawIn)
                      throws IOException
Reads the entire stream and returns all the data read in a byte[]. The stream supplied does not need to be buffered. The stream supplied is closed by this method (even if an IOException is thrown).

Parameters:
rawIn - source of bytes
Returns:
all of the data read
Throws:
IOException - if anything goes wrong

readAll

public static byte[] readAll(File source)
                      throws FileNotFoundException,
                             IOException
Reads the entire file and returns all the data read in a byte[]. Equivalent to:
 return readAll(new FileInputStream(source));
 

Throws:
FileNotFoundException
IOException

readAllFromFile

public static byte[] readAllFromFile(String filename)
                              throws FileNotFoundException,
                                     IOException
Reads the entire file and returns all the data read in a byte[]. Equivalent to:
 return readAll(new FileInputStream(source));
 

Throws:
FileNotFoundException
IOException

readAll

public static byte[] readAll(URL source)
                      throws IOException
Reads the entire stream of data from the URL and returns all the data read in a byte[]. Equivalent to:
 return readAll(source.openStream());
 

Throws:
IOException

readAllFromResource

public static byte[] readAllFromResource(String resourceLocation,
                                         Class<?> searchStartPoint)
                                  throws FileNotFoundException,
                                         IOException
Reads the entire stream from the specified resourceLocation and returns all the data read in a byte[]. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. The getResource(String path) method on the Class object passed in is used to locate the requested resource. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return readAll(
     getInputStreamForResource(resourceLocation, searchStartPoint));
 

Parameters:
resourceLocation - the path to the resource
searchStartPoint - the Class to invoke getResource. If null, IOTools.class is used.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

readAllFromResource

public static byte[] readAllFromResource(String resourceLocation)
                                  throws FileNotFoundException,
                                         IOException
Reads the entire stream from the specified resourceLocation and returns all the data read in a byte[]. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return readAll(getInputStreamForResource(resourceLocation));
 

Parameters:
resourceLocation - the path to the resource
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

readAll

public static byte[] readAll(Socket socket)
                      throws IOException
Reads the entire stream of data from the Socket and returns all the data read in a byte[]. After reading, the InputStream for the Socket is closed, but the Socket itself remains open. Equivalent to:
 return readAll(socket.getInputStream());
 

Throws:
IOException

readAllLines

public static String[] readAllLines(BufferedReader in)
                             throws IOException
Reads the entire stream of characters and returns all the lines read in a String[]. The BufferedReader supplied is closed by this method (even if an IOException is thrown).

Parameters:
in - source of characters
Returns:
all of the lines read
Throws:
IOException - if anything goes wrong

readAllLines

public static String[] readAllLines(Reader in)
                             throws IOException
Reads the entire stream of characters and returns all the lines read in a String[]. The Reader supplied is closed by this method (even if an IOException is thrown).

Parameters:
in - source of characters
Returns:
all of the lines read
Throws:
IOException - if anything goes wrong

readAllLines

public static String[] readAllLines(InputStream rawIn)
                             throws IOException
Reads the entire stream of bytes converting them to characters using the default InputStreamReader and returns all the lines read in a String[]. The stream supplied does not need to be buffered. The stream supplied is closed by this method (even if an IOException is thrown).

Parameters:
rawIn - source of bytes
Returns:
all of the lines read
Throws:
IOException - if anything goes wrong

readAllLines

public static String[] readAllLines(File source)
                             throws FileNotFoundException,
                                    IOException
Reads the entire file converting bytes to characters using the default InputStreamReader and returns all the lines read in a String[].

Parameters:
source - file to read from
Returns:
all of the lines read
Throws:
IOException - if anything goes wrong
FileNotFoundException

readAllLinesFromFile

public static String[] readAllLinesFromFile(String filename)
                                     throws FileNotFoundException,
                                            IOException
Reads the entire file converting bytes to characters using the default InputStreamReader and returns all the lines read in a String[].

Parameters:
filename - file to read from
Returns:
all of the lines read
Throws:
IOException - if anything goes wrong
FileNotFoundException

readAllLines

public static String[] readAllLines(URL source)
                             throws IOException
Reads the entire stream of data from the URL converting bytes to characters using the default InputStreamReader and returns all the lines read in a String[].

Parameters:
source - url to read from
Returns:
all of the lines read
Throws:
IOException - if anything goes wrong

readAllLinesFromResource

public static String[] readAllLinesFromResource(String resourceLocation,
                                                Class<?> searchStartPoint)
                                         throws FileNotFoundException,
                                                IOException
Reads the entire stream from the specified resourceLocation and returns all the data read in a String[]. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. The getResource(String path) method on the Class object passed in is used to locate the requested resource. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return readAllLines(
     getInputStreamForResource(resourceLocation, searchStartPoint));
 

Parameters:
resourceLocation - the path to the resource
searchStartPoint - the Class to invoke getResource. If null, IOTools.class is used.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

readAllLinesFromResource

public static String[] readAllLinesFromResource(String resourceLocation)
                                         throws FileNotFoundException,
                                                IOException
Reads the entire stream from the specified resourceLocation and returns all the data read in a String[]. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return readAllLines(getInputStreamForResource(resourceLocation));
 

Parameters:
resourceLocation - the path to the resource
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createBufferedWriter

public static BufferedWriter createBufferedWriter(OutputStream rawOut)
Creates a BufferedWriter using the default OutputStreamWriter constructor. Also adds a BufferedOutputStream to the supplied OutputStream, rawOut.

Parameters:
rawOut - unbuffered destination for the bytes

createBufferedWriter

public static BufferedWriter createBufferedWriter(File destination)
                                           throws FileNotFoundException,
                                                  IOException
Creates a BufferedWriter using the default OutputStreamWriter. Equivalent to:
 return createBufferedWriter(new FileOutputStream(destination));
 

Throws:
FileNotFoundException
IOException

createBufferedWriterToFile

public static BufferedWriter createBufferedWriterToFile(String filename)
                                                 throws FileNotFoundException,
                                                        IOException
Creates a BufferedWriter using the default OutputStreamWriter. Equivalent to:
 return createBufferedWriter(new FileOutputStream(filename));
 

Throws:
FileNotFoundException
IOException

createBufferedWriter

public static BufferedWriter createBufferedWriter(Socket socket)
                                           throws IOException
Creates a BufferedWriter using the default OutputStreamWriter. Equivalent to:
 return createBufferedWriter(socket.getOutputStream());
 

Throws:
IOException

createBufferedReader

public static BufferedReader createBufferedReader(InputStream rawIn)
Creates a BufferedReader using the default InputStreamReader constructor. If the passed InputStream is not a BufferedInputStream, then it is automatically wrapped with a BufferedInputStream to promote I/O efficiency. Therefore, there is no need to pass in a BufferedInputStream into this method, but there is also no need to avoid passing in a BufferedInputStream.

Parameters:
rawIn - source of the bytes

createBufferedReader

public static BufferedReader createBufferedReader(File source)
                                           throws FileNotFoundException,
                                                  IOException
Creates a BufferedReader using the default InputStreamReader. Equivalent to:
 return createBufferedReader(new FileInputStream(source));
 

Throws:
FileNotFoundException
IOException

createBufferedReaderFromFile

public static BufferedReader createBufferedReaderFromFile(String filename)
                                                   throws FileNotFoundException,
                                                          IOException
Creates a BufferedReader using the default InputStreamReader. Equivalent to:
 return createBufferedReader(new FileInputStream(filename));
 

Throws:
FileNotFoundException
IOException

createBufferedReader

public static BufferedReader createBufferedReader(URL source)
                                           throws IOException
Creates a BufferedReader using the default InputStreamReader. Equivalent to:
 return createBufferedReader(source.openStream());
 

Throws:
IOException

createBufferedReaderFromResource

public static BufferedReader createBufferedReaderFromResource(String resourceLocation,
                                                              Class<?> searchStartPoint)
                                                       throws FileNotFoundException,
                                                              IOException
Creates a BufferedReader using the default InputStreamReader. The underlying InputStream comes from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. The getResource(String path) method on the Class object passed in is used to locate the requested resource. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return createBufferedReader(
     getInputStreamForResource(resourceLocation, searchStartPoint));
 

Parameters:
resourceLocation - the path to the resource
searchStartPoint - the Class to invoke getResource. If null, IOTools.class is used.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createBufferedReaderFromResource

public static BufferedReader createBufferedReaderFromResource(String resourceLocation)
                                                       throws FileNotFoundException,
                                                              IOException
Creates a BufferedReader using the default InputStreamReader. The underlying InputStream comes from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return createBufferedReader(
     getInputStreamForResource(resourceLocation));
 

Parameters:
resourceLocation - the path to the resource
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createBufferedReader

public static BufferedReader createBufferedReader(Socket socket)
                                           throws IOException
Creates a BufferedReader using the default InputStreamReader. Equivalent to:
 return createBufferedReader(socket.getInputStream());
 

Throws:
IOException

createDataOutputStream

public static DataOutputStream createDataOutputStream(OutputStream rawOut)
Creates a DataOutputStream and adds buffering by wrapping a BufferedOutputStream around the supplied OutputStream, rawOut.

Parameters:
rawOut - unbuffered destination for the bytes

createDataOutputStream

public static DataOutputStream createDataOutputStream(File destination)
                                               throws FileNotFoundException,
                                                      IOException
Creates a DataOutputStream with buffering. Equivalent to:
 return createDataOutputStream(new FileOutputStream(destination));
 

Throws:
FileNotFoundException
IOException

createDataOutputStreamToFile

public static DataOutputStream createDataOutputStreamToFile(String filename)
                                                     throws FileNotFoundException,
                                                            IOException
Creates a DataOutputStream with buffering. Equivalent to:
 return createDataOutputStream(new FileOutputStream(filename));
 

Throws:
FileNotFoundException
IOException

createDataOutputStream

public static DataOutputStream createDataOutputStream(Socket socket)
                                               throws IOException
Creates a DataOutputStream with buffering. Equivalent to:
 return createDataOutputStream(socket.getOutputStream());
 

Throws:
IOException

createDataInputStream

public static DataInputStream createDataInputStream(InputStream rawIn)
Creates a DataInputStream and adds buffering by wrapping a BufferedInputStream around the supplied InputStream, rawIn.

Parameters:
rawIn - unbuffered source of the bytes

createDataInputStream

public static DataInputStream createDataInputStream(File source)
                                             throws FileNotFoundException,
                                                    IOException
Creates a DataInputStream with buffering. Equivalent to:
 return createDataInputStream(new FileInputStream(source));
 

Throws:
FileNotFoundException
IOException

createDataInputStreamFromFile

public static DataInputStream createDataInputStreamFromFile(String filename)
                                                     throws FileNotFoundException,
                                                            IOException
Creates a DataInputStream with buffering. Equivalent to:
 return createDataInputStream(new FileInputStream(filename));
 

Throws:
FileNotFoundException
IOException

createDataInputStream

public static DataInputStream createDataInputStream(URL source)
                                             throws IOException
Creates a DataInputStream with buffering. Equivalent to:
 return createDataInputStream(source.openStream());
 

Throws:
IOException

createDataInputStreamFromResource

public static DataInputStream createDataInputStreamFromResource(String resourceLocation,
                                                                Class<?> searchStartPoint)
                                                         throws FileNotFoundException,
                                                                IOException
Creates a buffered DataInputStream. The underlying InputStream comes from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. The getResource(String path) method on the Class object passed in is used to locate the requested resource. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return createDataInputStream(
     getInputStreamForResource(resourceLocation, searchStartPoint));
 

Parameters:
resourceLocation - the path to the resource
searchStartPoint - the Class to invoke getResource. If null, IOTools.class is used.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createDataInputStreamFromResource

public static DataInputStream createDataInputStreamFromResource(String resourceLocation)
                                                         throws FileNotFoundException,
                                                                IOException
Creates a buffered DataInputStream. The underlying InputStream comes from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return createDataInputStream(
     getInputStreamForResource(resourceLocation));
 

Parameters:
resourceLocation - the path to the resource
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createDataInputStream

public static DataInputStream createDataInputStream(Socket socket)
                                             throws IOException
Creates a DataInputStream with buffering. Equivalent to:
 return createDataInputStream(socket.getInputStream());
 

Throws:
IOException

createObjectOutputStream

public static ObjectOutputStream createObjectOutputStream(OutputStream rawOut)
                                                   throws IOException
Creates an ObjectOutputStream and adds buffering by wrapping a BufferedOutputStream around the supplied OutputStream, rawOut. Just after construction and before being returned from this method, the new ObjectOutputStream instance is flushed. The flushing ensures that the "object stream header" is pushed out right away in case an associated ObjectInputStream is waiting in its constructor.

Parameters:
rawOut - unbuffered destination for the bytes
Throws:
IOException

createObjectOutputStream

public static ObjectOutputStream createObjectOutputStream(File destination)
                                                   throws FileNotFoundException,
                                                          IOException
Creates an ObjectOutputStream with buffering. Equivalent to:
 return createObjectOutputStream(new FileOutputStream(destination));
 

Throws:
FileNotFoundException
IOException

createObjectOutputStreamToFile

public static ObjectOutputStream createObjectOutputStreamToFile(String filename)
                                                         throws FileNotFoundException,
                                                                IOException
Creates an ObjectOutputStream with buffering. Equivalent to:
 return createObjectOutputStream(new FileOutputStream(filename));
 

Throws:
FileNotFoundException
IOException

createObjectOutputStream

public static ObjectOutputStream createObjectOutputStream(Socket socket)
                                                   throws IOException
Creates an ObjectOutputStream with buffering. Equivalent to:
 return createObjectOutputStream(socket.getOutputStream());
 

Throws:
IOException

createObjectInputStream

public static ObjectInputStream createObjectInputStream(InputStream rawIn)
                                                 throws IOException
Creates an ObjectInputStream and adds buffering by wrapping a BufferedInputStream around the supplied InputStream, rawIn. The standard ObjectInputStream constructor always blocks until the "object stream header" is read from the underlying byte source; as a result, this method must also block until that header is read.

Parameters:
rawIn - unbuffered source of the bytes
Throws:
IOException

createObjectInputStream

public static ObjectInputStream createObjectInputStream(File source)
                                                 throws FileNotFoundException,
                                                        IOException
Creates an ObjectInputStream with buffering. Equivalent to:
 return createObjectInputStream(new FileInputStream(source));
 

Throws:
FileNotFoundException
IOException

createObjectInputStreamFromFile

public static ObjectInputStream createObjectInputStreamFromFile(String filename)
                                                         throws FileNotFoundException,
                                                                IOException
Creates an ObjectInputStream with buffering. Equivalent to:
 return createObjectInputStream(new FileInputStream(filename));
 

Throws:
FileNotFoundException
IOException

createObjectInputStream

public static ObjectInputStream createObjectInputStream(URL source)
                                                 throws IOException
Creates an ObjectInputStream with buffering. Equivalent to:
 return createObjectInputStream(source.openStream());
 

Throws:
IOException

createObjectInputStreamFromResource

public static ObjectInputStream createObjectInputStreamFromResource(String resourceLocation,
                                                                    Class<?> searchStartPoint)
                                                             throws FileNotFoundException,
                                                                    IOException
Creates a buffered ObjectInputStream. The underlying InputStream comes from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. The getResource(String path) method on the Class object passed in is used to locate the requested resource. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return createObjectInputStream(
     getInputStreamForResource(resourceLocation, searchStartPoint));
 

Parameters:
resourceLocation - the path to the resource
searchStartPoint - the Class to invoke getResource. If null, IOTools.class is used.
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createObjectInputStreamFromResource

public static ObjectInputStream createObjectInputStreamFromResource(String resourceLocation)
                                                             throws FileNotFoundException,
                                                                    IOException
Creates a buffered ObjectInputStream. The underlying InputStream comes from the specified resourceLocation. This method is suitable for retrieving resources from JAR files, WAR files, and CLASSPATH's. See getUrlForResource(String, Class) for the full explanation of how the search for the URL is performed.

Equivalent to:

 return createObjectInputStream(
     getInputStreamForResource(resourceLocation));
 

Parameters:
resourceLocation - the path to the resource
Throws:
FileNotFoundException - if the specified resource can not be found by the class loader.
IOException - if there are problems reading the data

createObjectInputStream

public static ObjectInputStream createObjectInputStream(Socket socket)
                                                 throws IOException
Creates an ObjectInputStream with buffering. Equivalent to:
 return createObjectInputStream(socket.getInputStream());
 

Throws:
IOException

createObjectStreamsForServer

public static IOTools.ObjectStreamPair createObjectStreamsForServer(InputStream rawIn,
                                                                    OutputStream rawOut)
                                                             throws IOException
Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream. The ObjectOutputStream is created (and flushed) first, which is customary for the server-side to do.

Throws:
IOException

createObjectStreamsForClient

public static IOTools.ObjectStreamPair createObjectStreamsForClient(InputStream rawIn,
                                                                    OutputStream rawOut)
                                                             throws IOException
Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream. The ObjectInputStream is created first, which is customary for the client-side to do.

Throws:
IOException

createObjectStreamsAsync

public static IOTools.ObjectStreamPair createObjectStreamsAsync(InputStream rawIn,
                                                                OutputStream rawOut)
                                                         throws IOException
Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream. Two threads are spawned behind the scenes to attempt to create the ObjectInputStream and ObjectOutputStream as the same time. This prevents an inter-VM deadlock that can occur when the stream creation order for the client-side and the server-side are not coordinated. This method is less efficient that using either createObjectStreamsForServer(InputStream, OutputStream) or createObjectStreamsForClient(InputStream, OutputStream), so this method should only be used when it is unknown if the far end will be creating the streams in a cooperative order.

Throws:
IOException

createObjectStreamsForServer

public static IOTools.ObjectStreamPair createObjectStreamsForServer(Socket socket)
                                                             throws IOException
Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified Socket's streams. The ObjectOutputStream is created (and flushed) first, which is customary for the server-side to do. Equivalent to:
 return createObjectStreamsForServer(
     socket.getInputStream(), socket.getOutputStream());
 

Throws:
IOException

createObjectStreamsForClient

public static IOTools.ObjectStreamPair createObjectStreamsForClient(Socket socket)
                                                             throws IOException
Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream. The ObjectInputStream is created first, which is customary for the client-side to do. Equivalent to:
 return createObjectStreamsForClient(
     socket.getInputStream(), socket.getOutputStream());
 

Throws:
IOException

createObjectStreamsAsync

public static IOTools.ObjectStreamPair createObjectStreamsAsync(Socket socket)
                                                         throws IOException
Creates an ObjectInputStream and an ObjectOutputStream with buffering on the specified InputStream and OutputStream. Two threads are spawned behind the scenes to attempt to create the ObjectInputStream and ObjectOutputStream as the same time. This prevents an inter-VM deadlock that can occur when the stream creation order for the client-side and the server-side are not coordinated. This method is less efficient that using either createObjectStreamsForServer(Socket) or createObjectStreamsForClient(Socket), so this method should only be used when it is unknown if the far end will be creating the streams in a cooperative order. Equivalent to:
 return createObjectStreamsAsync(
     socket.getInputStream(), socket.getOutputStream());
 

Throws:
IOException

closeQuietly

public static void closeQuietly(InputStream in)
Closes the specified stream and suppresses any IOException's that may be thrown. There is no need to avoid passing a null reference because if a null reference is passed to this method, the request to close is silently ignored.


closeQuietly

public static void closeQuietly(OutputStream out)
Closes the specified stream and suppresses any IOException's that may be thrown. There is no need to avoid passing a null reference because if a null reference is passed to this method, the request to close is silently ignored.


closeQuietly

public static void closeQuietly(InputStream in,
                                OutputStream out)
Closes the OutputStream and the InputStream [in that order]. Any IOException's that may be thrown are silently suppressed. There is no need to avoid passing null references because if any null reference is passed to this method, the request to close that particular item is silently ignored. Equivalent to:
 closeQuietly(out);
 closeQuietly(in);
 


closeQuietly

public static void closeQuietly(Reader in)
Closes the specified stream and suppresses any IOException's that may be thrown. There is no need to avoid passing a null reference because if a null reference is passed to this method, the request to close is silently ignored.


closeQuietly

public static void closeQuietly(Writer out)
Closes the specified stream and suppresses any IOException's that may be thrown. There is no need to avoid passing a null reference because if a null reference is passed to this method, the request to close is silently ignored.


closeQuietly

public static void closeQuietly(Socket socket)
Closes the specified Socket and suppresses any IOException's that may be thrown. There is no need to avoid passing a null reference because if a null reference is passed to this method, the request to close is silently ignored.


closeQuietly

public static void closeQuietly(Socket socket,
                                InputStream in,
                                OutputStream out)
Closes the OutputStream, InputStream, and Socket [in that order]. Any IOException's that may be thrown are silently suppressed. There is no need to avoid passing null references because if any null reference is passed to this method, the request to close that particular item is silently ignored. Equivalent to:
 closeQuietly(out);
 closeQuietly(in);
 closeQuietly(socket);
 


closeQuietly

public static void closeQuietly(Socket socket,
                                Reader in,
                                Writer out)
Closes the Writer, Reader, and Socket [in that order]. Any IOException's that may be thrown are silently suppressed. There is no need to avoid passing null references because if any null reference is passed to this method, the request to close that particular item is silently ignored. Equivalent to:
 closeQuietly(out);
 closeQuietly(in);
 closeQuietly(socket);
 


closeQuietly

public static void closeQuietly(ServerSocket ss)
Closes the specified ServerSocket and suppresses any IOException's that may be thrown. There is no need to avoid passing a null reference because if a null reference is passed to this method, the request to close is silently ignored.


ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.