Overview | Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jcontrol.storage
Class FlashStream

    java.lang.Object
      jcontrol.storage.FlashStream

All Implemented Interfaces:
  BasicInputStream, BasicOutputStream

    public class FlashStream

extends Object
implements BasicInputStream, BasicOutputStream

This class `FlashStream` represents a memory cached data stream for reading and writing continuous data to the flash memory.

If the flash memory is full or some other error occurs, an `IOException` is thrown.

Author:
  Wolfgang Klingauf
See Also:
  `Flash`, `FlashTlv`
Available on JControl Devices:

  lib

Field Summary
`protected byte[]` | `cache` sector cache for faster reads
`protected byte` | `m_bank` currently used flash bank (always starts at bank 0)
`protected int` | `m_pos` position in current sector (for the stream)
`protected int` | `m_sector` current sector
`protected int` | `sectorcount` flash sectorsize and -count
`protected int` | `sectorsize` flash sectorsize and -count

Constructor Summary
`FlashStream()` Create a new flash stream.

Method Summary
`void` | `clearCache()` Frees the flash memory.
`void` | `close()` Closes the stream, further reads are not possible, attached hardware will be turned off.
`int` | `getSectorsize()` Returns the sectorsize.
`char` | `read()` Read a single character from the flash stream.
`int` | `read(byte[] buffer, int startindex, int length)` Read data from the flash stream.
`int` | `write(byte[] buffer, int startindex, int length)` Write data to the flash stream.
`void` | `write(char data)` Write a single character to the flash stream.

Methods inherited from class java.lang.Object
`clone, equals, notifyAll, wait`

Field Detail

### cache

    protected byte[] cache

  sector cache for faster reads

### m_bank

    protected byte m_bank

  currently used flash bank (always starts at bank 0)

### m_pos

    protected int m_pos

  position in current sector (for the stream)

### m_sector

    protected int m_sector

  current sector

### sectorcount

    protected int sectorcount

  flash sectorsize and -count

### sectorsize

    protected int sectorsize

  flash sectorsize and -count

Constructor Detail

### FlashStream

    public FlashStream()
                throws IOException

  Create a new flash stream.

  Throws:
    `IOException`

Method Detail

### clearCache

    public void clearCache()

  Frees the flash memory.

### close

    public void close()

  Description copied from interface: `BasicInputStream`
  Closes the stream, further reads are not possible, attached hardware will be turned off. Its save to call this method multiple times. Should be called by `finalize` of implementing classes.

  Specified by:
    `close` in interface `BasicInputStream`
  Specified by:
    `close` in interface `BasicOutputStream`
  See Also:
    `BasicOutputStream.close()`

### getSectorsize

    public int getSectorsize()

  Returns the sectorsize.

  Returns:
    int

### read

    public char read()
              throws IOException

  Read a single character from the flash stream.

  Specified by:
    `read` in interface `BasicInputStream`
  Returns:
    the byte read, converted to a char (range 0 .. 255)
  Throws:
    `IOException` - if an error occurs
  See Also:
    `BasicInputStream.read()`

### read

    public int read(byte[] buffer,
                    int startindex,
                    int length)
             throws IOException

  Read data from the flash stream.

  Specified by:
    `read` in interface `BasicInputStream`
  Parameters:
    `buffer` - the buffer to fill
    `startindex` - the index to start filling the array
    `length` - number of byte to read; the array is filled from `startindex` to `startindex`+`length`-1
  Returns:
    the number of received bytes
  Throws:
    `IOException` - if an error occurs
  See Also:
    `BasicInputStream.read(byte[], int, int)`

### write

    public int write(byte[] buffer,
                     int startindex,
                     int length)
              throws IOException

  Write data to the flash stream.

  Specified by:
    `write` in interface `BasicOutputStream`
  Parameters:
    `buffer` - the buffer that holds the data to write
    `startindex` - the index to start reading the array
    `length` - number of bytes to write; the array is read from `startindex` to `startindex`+`length`-1
  Returns:
    the number of sent bytes
  Throws:
    `IOException` - if an error occurs
  See Also:
    `BasicOutputStream.write(byte[], int, int)`

### write

    public void write(char data)
               throws IOException

  Write a single character to the flash stream.

  Specified by:
    `write` in interface `BasicOutputStream`
  Parameters:
    `data` - the byte to write (range of the char 0 .. 255, the highbyte is ignored)
  Throws:
    `IOException` - if an error occurs
  See Also:
    `BasicOutputStream.write(char)`

Overview | Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD