com.quadrique.jbuildingblocks.core.io.stream
Class JbbStream

java.lang.Object
  extended by com.quadrique.jbuildingblocks.core.io.stream.JbbStream

public class JbbStream
extends Object

This class provides goodies to manipulate streams (files, String, byte arrays...)

Author:
Hervé Rivere

Method Summary
 long copyByteArrayToFile(byte[] bytes, String fileName)
          Copy the given byte array to a file
 long copyByteArrayToOutputStream(byte[] bytes, OutputStream outputStream, boolean useBufferedOutputStream, boolean closeOutputStream)
          Copy the given byte array to the given output stream
 byte[] copyFileToByteArray(File file)
          Copy the given file in a byte array
 byte[] copyFileToByteArray(String fileName)
          Copy the given file in a byte array
 long copyFileToFile(File sourceFile, File destFile)
          Copy the given input file to the given output file
 long copyFileToOutputStream(String fileName, OutputStream outputStream, boolean useBufferedOutputStream, boolean closeOutputStream)
          Copy the content of the given file in the given output stream Both input and output streams are synchronized for concurrent access
 String copyFileToString(String fileName)
          Copy the content of the given file in a string, translating bytes into characters according to the platform's default character encoding.
 String copyFileToString(String fileName, String characterEncoding)
          Copy the content of the given file in a string, translating bytes into characters according to the given character encoding (e.g.
 byte[] copyInputStreamToByteArray(InputStream inputStream, boolean closeInputStream)
           
 long copyInputStreamToFile(InputStream inputStream, File file, boolean closeInputStream)
           
 long copyStreamToStream(InputStream inputStream, OutputStream outputStream, boolean useBufferedOutputStream, boolean closeInputStream, boolean closeOutputStream)
          Both input and output streams are synchronized for concurrent access
 byte[] copyStringToByteArray(String string)
          Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
 byte[] copyStringToByteArray(String string, String charsetName)
          Encodes this String into a sequence of bytes using the named charset ((e.g.
 long copyStringToFile(String string, String destinationFileName)
          Encodes this String into a sequence of bytes using the platform's default character set, storing the result into the given file name Both input and output streams are synchronized for concurrent access
 long copyStringToFile(String string, String charsetName, String destinationFileName)
          Encodes this String into a sequence of bytes using the named charset ((e.g.
 long copyStringToOutputStream(String string, OutputStream outputStream, boolean useBufferedOutputStream, boolean closeOutputStream)
          Encodes this String into a sequence of bytes using the platform's default character set, storing the result into the given output stream Both input and output streams are synchronized for concurrent access
 long copyStringToOutputStream(String string, String charsetName, OutputStream outputStream, boolean useBufferedOutputStream, boolean closeOutputStream)
          Encodes this String into a sequence of bytes using the named charset ((e.g.
static JbbStream newInstance()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static JbbStream newInstance()

copyStreamToStream

public long copyStreamToStream(InputStream inputStream,
                               OutputStream outputStream,
                               boolean useBufferedOutputStream,
                               boolean closeInputStream,
                               boolean closeOutputStream)
                        throws Exception
Both input and output streams are synchronized for concurrent access

Parameters:
inputStream -
outputStream -
useBufferedOutputStream - true to use a BufferedOutputStream for the actual copy, false otherwise
closeInputStream - true to close the input stream once the copy has been performed
closeOutputStream - true to close the output stream once the copy has been performed
Returns:
the total number of bytes transferred from the input stream to the output stream
Throws:
Exception

copyByteArrayToOutputStream

public long copyByteArrayToOutputStream(byte[] bytes,
                                        OutputStream outputStream,
                                        boolean useBufferedOutputStream,
                                        boolean closeOutputStream)
                                 throws Exception
Copy the given byte array to the given output stream

Parameters:
bytes -
outputStream -
useBufferedOutputStream - true to use a BufferedOutputStream for the actual copy, false otherwise
closeOutputStream - true to close the output stream once the copy has been performed
Returns:
the total number of bytes transferred from the input stream to the output stream
Throws:
Exception

copyByteArrayToFile

public long copyByteArrayToFile(byte[] bytes,
                                String fileName)
                         throws Exception
Copy the given byte array to a file

Parameters:
bytes -
fileName -
Returns:
the total number of bytes that were copied
Throws:
Exception

copyFileToOutputStream

public long copyFileToOutputStream(String fileName,
                                   OutputStream outputStream,
                                   boolean useBufferedOutputStream,
                                   boolean closeOutputStream)
                            throws Exception
Copy the content of the given file in the given output stream Both input and output streams are synchronized for concurrent access

Parameters:
fileName -
outputStream -
useBufferedOutputStream - true to use a BufferedOutputStream for the actual copy, false otherwise
closeOutputStream - true to close the output stream once the copy has been performed
Returns:
the total number of bytes that were copied
Throws:
Exception

copyFileToFile

public long copyFileToFile(File sourceFile,
                           File destFile)
                    throws Exception
Copy the given input file to the given output file

Parameters:
sourceFile -
destFile -
Returns:
the total number of bytes that were copied
Throws:
Exception

copyFileToString

public String copyFileToString(String fileName)
                        throws Exception
Copy the content of the given file in a string, translating bytes into characters according to the platform's default character encoding.

Parameters:
fileName -
Returns:
the String
Throws:
Exception

copyFileToString

public String copyFileToString(String fileName,
                               String characterEncoding)
                        throws Exception
Copy the content of the given file in a string, translating bytes into characters according to the given character encoding (e.g. "8859_1" for ISO latin 1, "Unicode" for unicode eith a byte order mark, "UnicodeBig" for Unicode with big-endian byte order, "Cp297" forn EBCDI for French...).

Parameters:
fileName -
characterEncoding -
Returns:
the String
Throws:
Exception

copyFileToByteArray

public byte[] copyFileToByteArray(File file)
                           throws Exception
Copy the given file in a byte array

Parameters:
file -
Returns:
the bytes of the file
Throws:
Exception

copyFileToByteArray

public byte[] copyFileToByteArray(String fileName)
                           throws Exception
Copy the given file in a byte array

Parameters:
fileName -
Returns:
the bytes of the file
Throws:
Exception

copyStringToByteArray

public byte[] copyStringToByteArray(String string)
                             throws Exception
Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

Parameters:
string -
Returns:
the bytes of the String
Throws:
Exception

copyStringToByteArray

public byte[] copyStringToByteArray(String string,
                                    String charsetName)
                             throws Exception
Encodes this String into a sequence of bytes using the named charset ((e.g. "8859_1" for ISO latin 1, "Unicode" for unicode eith a byte order mark, "UnicodeBig" for Unicode with big-endian byte order, "Cp297" forn EBCDI for French...), storing the result into a new byte array.

Parameters:
string -
charsetName -
Returns:
the bytes of the String
Throws:
Exception

copyStringToOutputStream

public long copyStringToOutputStream(String string,
                                     OutputStream outputStream,
                                     boolean useBufferedOutputStream,
                                     boolean closeOutputStream)
                              throws Exception
Encodes this String into a sequence of bytes using the platform's default character set, storing the result into the given output stream Both input and output streams are synchronized for concurrent access

Parameters:
string -
outputStream -
useBufferedOutputStream - true to use a BufferedOutputStream for the actual copy, false otherwise
closeOutputStream - true to close the output stream once the copy has been performed
Returns:
the number of bytes transferred from the String to the output stream
Throws:
Exception

copyStringToOutputStream

public long copyStringToOutputStream(String string,
                                     String charsetName,
                                     OutputStream outputStream,
                                     boolean useBufferedOutputStream,
                                     boolean closeOutputStream)
                              throws Exception
Encodes this String into a sequence of bytes using the named charset ((e.g. "8859_1" for ISO latin 1, "Unicode" for unicode eith a byte order mark, "UnicodeBig" for Unicode with big-endian byte order, "Cp297" forn EBCDI for French...), storing the result into the given output stream Both input and output streams are synchronized for concurrent access

Parameters:
string -
charsetName - the name of the charset
outputStream -
useBufferedOutputStream - true to use a BufferedOutputStream for the actual copy, false otherwise
closeOutputStream - true to close the output stream once the copy has been performed
Returns:
the number of bytes transferred from the String to the output stream
Throws:
Exception

copyStringToFile

public long copyStringToFile(String string,
                             String destinationFileName)
                      throws Exception
Encodes this String into a sequence of bytes using the platform's default character set, storing the result into the given file name Both input and output streams are synchronized for concurrent access

Parameters:
string - the string to save in the destination file
destinationFileName - the destination file name
Returns:
the number of bytes transferred
Throws:
Exception

copyStringToFile

public long copyStringToFile(String string,
                             String charsetName,
                             String destinationFileName)
                      throws Exception
Encodes this String into a sequence of bytes using the named charset ((e.g. "8859_1" for ISO latin 1, "Unicode" for unicode eith a byte order mark, "UnicodeBig" for Unicode with big-endian byte order, "Cp297" forn EBCDI for French...), storing the result into the given file name Both input and output streams are synchronized for concurrent access

Parameters:
string - the string to save in the destination file
charsetName - the name of the charset
destinationFileName - the destination file name
Returns:
the number of bytes transferred
Throws:
Exception

copyInputStreamToFile

public long copyInputStreamToFile(InputStream inputStream,
                                  File file,
                                  boolean closeInputStream)
                           throws Exception
Parameters:
inputStream -
file -
closeInputStream -
Returns:
the number of bytes transferred
Throws:
Exception

copyInputStreamToByteArray

public byte[] copyInputStreamToByteArray(InputStream inputStream,
                                         boolean closeInputStream)
                                  throws Exception
Parameters:
inputStream -
closeInputStream -
Returns:
the number of bytes transferred
Throws:
Exception


Copyright © 2001-2008 Quadrique Corporation. All Rights Reserved.