SunSPOT host API V3.0


com.sun.spot.flashmanagement
Class FlashFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.sun.spot.flashmanagement.FlashFileOutputStream
All Implemented Interfaces:
Closeable, Flushable

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()
           
 void flush()
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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
Specified by:
write in class OutputStream
Throws:
IOException
See Also:
OutputStream.write(int)

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException
See Also:
OutputStream.flush()

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException
See Also:
OutputStream.close()

SunSPOT host API V3.0


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