jcontrol.storage
Class FlashTlv

java.lang.Object
  extended byjcontrol.storage.FlashTlv

public class FlashTlv
extends java.lang.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, finalize, 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 java.io.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:
java.io.IOException - if the flash couldn't be initialized.
Method Detail

cleanup

public void cleanup()
             throws java.io.IOException
This method will delete all obsolete data.

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

close

public void close()
           throws java.io.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:
java.io.IOException - if the flash couldn't be initialized.

create

public void create(byte tag)
            throws java.io.IOException
Creates a new file object.

Parameters:
tag - The tag of the new file.
Throws:
java.io.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 java.io.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.
java.io.IOException - if the flash couldn't be initialized.
See Also:
cleanup()

findNext

public TlvFile findNext(TlvFile file)
                 throws java.io.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.
java.io.IOException - if the flash couldn't be initialized.

findNext

public TlvFile findNext(TlvFile file,
                        byte tag)
                 throws java.io.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.
java.io.IOException - if the flash couldn't be initialized.

format

public void format(int size)
            throws java.io.IOException
Formats the available flash.

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

isFormated

public boolean isFormated()
                   throws java.io.IOException
Checks if the the flash is prepared for the FlashTlv.

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

open

public boolean open(TlvFile file)
             throws java.io.IOException
Opens the specified file for reading.

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

read

public byte[] read()
            throws java.io.IOException
Returns the data of the current file.

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

write

public boolean write(byte[] newdata)
              throws java.io.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.
java.io.IOException - if the flash couldn't be initialized.