SunSPOT API V3.0


com.sun.spot.flashmanagement
Class FlashFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.sun.spot.flashmanagement.FlashFileOutputStream

public class FlashFileOutputStream
extends OutputStream

FlashFileOutputStream represents an output stream over some flash memory. There are two uses for this.

The first is to stream over the flash memory allocated to an instance of a FlashFile. In this case, you should construct the output stream accordingly, for example:

 FlashFile myFile = new FlashFile("my file");
 myFile.createNewFile(requiredSize);
 FlashFileOutputStream ffos = new FlashFileOutputStream(myFile);
 

In this case, the output stream will throw an IOException if you attempt to write beyond the end of the last sector allocated to the FlashFile. Note that this will allow more than requiredSize bytes to be written to the file when requiredSize is not equal to a whole number of flash memory sectors.

The second use of FlashFileOutputStream is to stream over the flash memory in an arbitrary sector of the flash memory. In this case, construct the output stream like this:

 FlashFileOutputStream ffos = new FlashFileOutputStream(new NorFlashSector(mySectorNumber));

In this case, the output stream will throw an IOException if you attempt to write beyond the end of the sector.


Field Summary
static int DEFAULT_BUFFER_SIZE
          The default size of the output buffer.
 
Constructor Summary
FlashFileOutputStream(FlashFile file)
          Construct an output stream over the space allocated to a previously created FlashFile
FlashFileOutputStream(FlashFile file, int bufferSize)
          Construct an output stream over the space allocated to a previously created FlashFile, specifying a non-standard buffer size.
FlashFileOutputStream(IAddressableNorFlashSector sector)
          Construct an output stream over a sector of the flash memory.
 
Method Summary
 void close()
          Closes this output stream and releases any system resources associated with this stream.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default size of the output buffer. This can be overridden when opening a stream.

See Also:
Constant Field Values
Constructor Detail

FlashFileOutputStream

public FlashFileOutputStream(FlashFile file)
                      throws FlashFileNotFoundException
Construct an output stream over the space allocated to a previously created FlashFile

Parameters:
file - The FlashFile to write data to
Throws:
FlashFileNotFoundException

FlashFileOutputStream

public FlashFileOutputStream(FlashFile file,
                             int bufferSize)
                      throws FlashFileNotFoundException
Construct an output stream over the space allocated to a previously created FlashFile, specifying a non-standard buffer size. The output stream will flush its contents to flash memory when either this buffer is full, or when flush() or close() are called. Thus varying the buffer size affects the performance characteristics of the output stream. The default value is 512;

Parameters:
file - The FlashFile to write data to
bufferSize - The size - in bytes - for the FlashFile's output buffer.
Throws:
FlashFileNotFoundException

FlashFileOutputStream

public FlashFileOutputStream(IAddressableNorFlashSector sector)
                      throws FlashFileNotFoundException
Construct an output stream over a sector of the flash memory.

Parameters:
sector - the sector to write data to.
Throws:
FlashFileNotFoundException
Method Detail

write

public void write(int b)
           throws IOException
Description copied from class: OutputStream
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Subclasses of OutputStream must provide an implementation for this method.

Specified by:
write in class OutputStream
Parameters:
b - the byte.
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
See Also:
OutputStream.write(int)

flush

public void flush()
           throws IOException
Description copied from class: OutputStream
Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

The flush method of OutputStream does nothing.

Overrides:
flush in class OutputStream
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.flush()

close

public void close()
           throws IOException
Description copied from class: OutputStream
Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

The close method of OutputStream does nothing.

Overrides:
close in class OutputStream
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.close()

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.