com.foxsmart.ic.io
Class StreamWriter

java.lang.Object
  extended by com.foxsmart.ic.io.StreamWriter

public class StreamWriter
extends java.lang.Object

This class provides the ability to write a stream of bytes to a specified destination (e.g. a file on a hard disk). The stream can be written in increments in case the stream is being written over a long period of time and the caller wishes to provide some type of user feedback during the writing process.


Constructor Summary
StreamWriter(java.io.File file)
          Constructs a stream writer to a file.
 
Method Summary
 void close()
          Closes the output stream.
static void main(java.lang.String[] args)
          Test Driver.
 int write(byte[] byteArray)
          Write all bytes in a byte array to the output stream.
 int write(byte[] byteArray, int offset, int length)
          Write a specified number of bytes in a byte array to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamWriter

public StreamWriter(java.io.File file)
             throws java.io.IOException
Constructs a stream writer to a file.

Parameters:
file - The file to create the stream to
Throws:
java.io.IOException - if the URL stream could not be opened to the URL
Method Detail

write

public int write(byte[] byteArray)
          throws java.io.IOException
Write all bytes in a byte array to the output stream.

Parameters:
byteArray - The byte array to write.
Returns:
The number of bytes written.
Throws:
java.io.IOException - if the stream could not be written or an error occurred while writing to the stream.

write

public int write(byte[] byteArray,
                 int offset,
                 int length)
          throws java.io.IOException
Write a specified number of bytes in a byte array to the output stream.

Parameters:
byteArray - The byte array to write.
offset - The offset in the array to start writing.
length - The number of bytes to write.
Returns:
The number of bytes written.
Throws:
java.io.IOException - if the stream could not be written or an error occurred while writing to the stream.

close

public void close()
           throws java.io.IOException
Closes the output stream. This method should be called when the entire stream has been written to so resources can be freed up.

Throws:
java.io.IOException - if the stream could not be closed.

main

public static void main(java.lang.String[] args)
Test Driver.

Parameters:
args - the arguments


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.