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 FlashTlv

    java.lang.Object
      jcontrol.storage.FlashTlv

    public class FlashTlv

extends Object

This class `FlashTlv.class` implements a tag-length-value file system.
Each file(-type) is represented by a tag of 8 bits. Different files of the same type may be stored. Use this for storing many small records in non-volatile flash memory.
Currently under development.

Version:
  1.0
Author:
  Marcus Timmermann
See Also:
  `Flash`
Available on JControl Devices:

  lib

Field Summary
`static int` | `ALL` To specify all available memory with `format(int)`.

Constructor Summary
`FlashTlv(int flashBank)` Creates a new FlashTlv object.

Method Summary
`void` | `cleanup()` This method will delete all obsolete data.
`void` | `close()` Closes the current file for writing and reading.
`void` | `create(byte tag)` Creates a new file object.
`void` | `delete()` Marks the current file as obsolete.
`TlvFile` | `findNext(TlvFile file)` Finds the next file.
`TlvFile` | `findNext(TlvFile file, byte tag)` Finds the next file with the specified tag.
`void` | `format(int size)` Formats the available flash.
`boolean` | `isFormated()` Checks if the the flash is prepared for the FlashTlv.
`boolean` | `open(TlvFile file)` Opens the specified file for reading.
`byte[]` | `read()` Returns the data of the current file.
`boolean` | `write(byte[] newdata)` Writes data to the specified file.

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

Field Detail

### ALL

    public static final int ALL

  To specify all available memory with `format(int)`.

  See Also:
    Constant Field Values

Constructor Detail

### FlashTlv

    public FlashTlv(int flashBank)
             throws IOException

  Creates a new FlashTlv object. If more than one FlashTlv object exists for the same flash bank, all will handle the same data structure, there is no need to create more than one FlashTlv at the same time.

  Parameters:
    `flashBank` - the flash bank to store the FlashTlv data in.
  Throws:
    `IOException` - if the flash couldn't be initialized.

Method Detail

### cleanup

    public void cleanup()
                 throws IOException

  This method will delete all obsolete data.

  Throws:
    `jcontrol.io.BadFormatException` - if the flash was not formatted correctly.
    `IOException` - if the flash couldn't be initialized.

### close

    public void close()
               throws IOException

  Closes the current file for writing and reading. It is not necessary to call this method before a new file is opened or created.

  Throws:
    `IOException` - if the flash couldn't be initialized.

### create

    public void create(byte tag)
                throws IOException

  Creates a new file object.

  Parameters:
    `tag` - The tag of the new file.
  Throws:
    `IOException` - if the flash couldn't be initialized or if the new file position is beyond the FlashTlv end-tag.

### delete

    public void delete()
                throws IOException

  Marks the current file as obsolete. The file is not deleted completely until `cleanup()` is called.

  Throws:
    `jcontrol.io.BadFormatException` - if the flash was not formatted correctly.
    `IOException` - if the flash couldn't be initialized.
  See Also:
    `cleanup()`

### findNext

    public TlvFile findNext(TlvFile file)
                     throws IOException

  Finds the next file.

  Parameters:
    `file` - The file where the search will start. If this parameter is `null`, the search will start at the beginning.
  Returns:
    The file object that was found, null if there are no more files.
  Throws:
    `jcontrol.io.BadFormatException` - if the flash was not formatted correctly.
    `IOException` - if the flash couldn't be initialized.

### findNext

    public TlvFile findNext(TlvFile file,
                            byte tag)
                     throws IOException

  Finds the next file with the specified tag.

  Parameters:
    `file` - The file where the search will start. If this parameter is `null`, the search will start at the beginning.
    `tag` - The tag to search for.
  Returns:
    The file object that was found, null if nothing was found.
  Throws:
    `jcontrol.io.BadFormatException` - if the flash was not formatted correctly.
    `IOException` - if the flash couldn't be initialized.

### format

    public void format(int size)
                throws IOException

  Formats the available flash.

  Parameters:
    `size` - maximum FlashTlv size or `ALL` if all space may be used.
  Throws:
    `IOException` - if the flash couldn't be initialized.

### isFormated

    public boolean isFormated()
                       throws IOException

  Checks if the the flash is prepared for the FlashTlv.

  Returns:
    true if the flash is formatted for the FlashTlv, false otherwise.
  Throws:
    `IOException` - if the flash couldn't be initialized.

### open

    public boolean open(TlvFile file)
                 throws IOException

  Opens the specified file for reading.

  Parameters:
    `file` - The file to read.
  Returns:
    true if file could be read, false otherwise.
  Throws:
    `IOException` - if the flash couldn't be initialized.

### read

    public byte[] read()
                throws IOException

  Returns the data of the current file.

  Returns:
    the data as byte[].
  Throws:
    `jcontrol.io.BadFormatException` - if the flash was not formatted correctly.
    `IOException` - if the flash couldn't be initialized.

### write

    public boolean write(byte[] newdata)
                  throws IOException

  Writes data to the specified file.

  Parameters:
    `newdata` - the data.
  Returns:
    true, if writing was successful.
  Throws:
    `jcontrol.io.BadFormatException` - if the flash was not formatted correctly.
    `IOException` - if the flash couldn't be initialized.

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