|
SunSPOT API V3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.spot.flashmanagement.FlashFile
public class FlashFile
FlashFile
This class is the main entry point to the flash memory filing system. This class is modelled on java.io.File from j2se. As for File in j2se, a FlashFile does not represent the file itself, but merely a handle or name for a file. Creating a FlashFile object does not create the file.
A flash-based file comprises one or more sectors of flash memory. An underlying flash manager takes care of allocating sectors for files. Allocation is recorded in a File Allocation Table (FAT) managed by the flash manager. One important difference between File and FlashFile is that when creating a new file the size of the file must be specified, and files are not extended automatically.
For some uses (e.g. storing suites) it is important that a file appears to occupy a contiguous range of
memory addresses and starts at a specific address. Such a file is called a "mapped" file, and the flash filing
system uses the MMU to map the file's sectors to the correct addresses. To make a file mapped
use setVirtualAddress(int)
and then map()
.
Rather than deleting a file and thereby releasing the sectors it occupies, a file can be marked as "obsolete". The space occupied by obsolete files is reclaimed at the next reboot. This is useful if the file contains the bytecodes of an active suite.
The current implementation does not provide file locking: it is possible for two users simultaneously to access the same file, possibly with disastrous consequences.
Field Summary | |
---|---|
static long |
FIRST_FILE_VIRTUAL_ADDRESS
The lowest valid virtual address that can be allocated to a file |
static long |
LAST_FILE_VIRTUAL_ADDRESS
The highest valid virtual address that can be allocated to a file |
static int |
VIRTUAL_ADDRESS_FILE_SPACING
The size of the virtual address space allocated to a mapped file |
Constructor Summary | |
---|---|
FlashFile(String name)
Create a FlashFile with the specified name. |
Method Summary | |
---|---|
void |
commit()
Ensure all changes to this file's descriptor are written persistently. |
boolean |
createNewFile(int size)
Create a new file of the specified size, whose name is the name of this FlashFile object. |
void |
delete()
Delete the file with this name |
boolean |
exists()
Check whether a file with this name exists |
int |
getAllocatedSpace()
Determine the space allocated for the file with this name |
String |
getComment()
Get the comment for this file |
static IFAT |
getFAT()
Get a read-only representation of the FAT |
int |
getFirstSectorBaseAddress()
For test purposes only |
String |
getName()
Get the name of this file |
int |
getVirtualAddress()
Get the virtual address of a mapped file |
boolean |
isAddressed()
Check whether this file has a virtual address. |
boolean |
isMapped()
Check whether this file is mapped. |
boolean |
isObsolete()
Check whether the file with this name is obsolete |
long |
lastModified()
Get the time at which this file was last modified |
int |
length()
Get the length of the file with this name |
void |
map()
Cause the file with this name to become a mapped file. |
boolean |
renameTo(FlashFile dest)
Rename the file with this name so that it has a different name |
static void |
resetFAT()
Overwrite the existing FAT with a new empty one. |
void |
setComment(String comment)
Set a comment for this file |
static void |
setNorFlashSectorFactory(INorFlashSectorFactory norFlashSectorFactory)
Set the INorFlashSectorFactory to be used by FlashFile when creating a FlashManager. |
void |
setObsolete(boolean b)
Set whether or not the file with this name is obsolete. |
void |
setVirtualAddress(int virtualAddress)
Set the virtual address that the file gets mapped to. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int VIRTUAL_ADDRESS_FILE_SPACING
public static final long FIRST_FILE_VIRTUAL_ADDRESS
public static final long LAST_FILE_VIRTUAL_ADDRESS
Constructor Detail |
---|
public FlashFile(String name)
createNewFile(int)
to do that.
name
- the name of the fileMethod Detail |
---|
public static void setNorFlashSectorFactory(INorFlashSectorFactory norFlashSectorFactory) throws IOException
norFlashSectorFactory
- the factory to use
IOException
public static void resetFAT() throws IOException
IOException
public static IFAT getFAT()
public boolean createNewFile(int size) throws InsufficientFlashMemoryException
size
- the size in bytes of the file to create
InsufficientFlashMemoryException
- if the space requested cannot be allocatedpublic boolean exists()
public void delete() throws IOException
IOException
public int length() throws IOException
length
in interface IFlashFileInfo
IOException
public void commit() throws IOException
IOException
public void setVirtualAddress(int virtualAddress) throws IOException
map()
is invoked. The virtual address must be one
of the valid addresses defined by FIRST_FILE_VIRTUAL_ADDRESS
, LAST_FILE_VIRTUAL_ADDRESS
and VIRTUAL_ADDRESS_FILE_SPACING
.
virtualAddress
- the virtual address for the file, or 0 if it should not be a mapped file
IOException
public void setComment(String comment) throws IOException
comment
- the comment to be attached to the descriptor of the file
IOException
public int getVirtualAddress() throws IOException
getVirtualAddress
in interface IFlashFileInfo
IOException
public String getComment() throws IOException
getComment
in interface IFlashFileInfo
IOException
public long lastModified() throws IOException
lastModified
in interface IFlashFileInfo
IOException
public void setObsolete(boolean b) throws IOException
b
- true if this file is to be marked obsolete, false if it is not
IOException
public boolean isObsolete() throws IOException
isObsolete
in interface IFlashFileInfo
IOException
public void map() throws IOException
map()
is called before a virtual address has been specified
using setVirtualAddress(int)
then a free virtual address will be allocated (and can be
discovered after the map()
call using getVirtualAddress()
.
IOException
public boolean isMapped() throws IOException
IOException
public boolean isAddressed() throws IOException
IOException
public int getAllocatedSpace() throws IOException
IOException
public String getName()
getName
in interface IFlashFileInfo
public boolean renameTo(FlashFile dest) throws IOException
dest
- the new name for the file
IOException
public int getFirstSectorBaseAddress() throws IOException
IOException
|
SunSPOT API V3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |