|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectFileIO
public class FileIO
The FileIO class is used to handle files.
Three methods, namely read
, write
, and
append
, work in an asynchronous manner. Such methods return
immediately and this class calls the corresponding callback method once the
operation is achieved. This class uses a single Thread to fulfil all the
asynchronous operations. It is therefore not possible to launch a new request
before the previous one is finished.
Field Summary | |
---|---|
static int |
STATE_CONTENT_NULL
The given content is null . |
static int |
STATE_FILENAME_NULL
The given filename is null . |
static int |
STATE_NOT_READY
The class is not ready. |
static int |
STATE_OK
The operation finished successfully. |
static int |
STATE_PROBLEM
A problem occured during the operation. |
Constructor Summary | |
---|---|
FileIO(FileIOListener listener)
Constructs a new FileIO object. |
Method Summary | |
---|---|
void |
append(java.lang.String filename,
byte[] content)
Appends the specified bytes to the specified file. |
int |
create(java.lang.String filename)
Creates a new file. |
int |
exists(java.lang.String filename)
Checks if the specified file or directory exists. |
int |
mkdir(java.lang.String filename)
Creates a new directory. |
void |
read(java.lang.String filename)
Reads the specified file. |
void |
run()
|
void |
write(java.lang.String filename,
byte[] content)
Writes in the specified file. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STATE_OK
public static final int STATE_PROBLEM
public static final int STATE_NOT_READY
public static final int STATE_FILENAME_NULL
null
.
public static final int STATE_CONTENT_NULL
null
.
Constructor Detail |
---|
public FileIO(FileIOListener listener)
listener
- the listener that contains the callback methodsMethod Detail |
---|
public int mkdir(java.lang.String filename)
STATE_FILENAME_NULL
if the specified
filename is null
, STATE_PROBLEM
if a problem
occurs (like creating a directory that does already exist or specifying a
path to the new subdirectory that doesn't exist), and STATE_OK
if the new directory is created successfully.
filename
- the full filename
public int create(java.lang.String filename)
STATE_FILENAME_NULL
if the
specified filename is null
, STATE_PROBLEM
if a
problem occurs (like creating a file that does already exist or specifying
a path that doesn't exist), and STATE_OK
if the new file is
created successfully.
filename
- the full filename
public int exists(java.lang.String filename)
STATE_FILENAME_NULL
if the specified filename is
null
, STATE_PROBLEM
if a problem occurs or if the
specified file or directory does not exist, and STATE_OK
if
the file or directory exists.
filename
- the full filename
public void read(java.lang.String filename)
fileRead
callback method is called when the operation ends up.
filename
- the full filenameFileIOListener.fileRead(int state, byte[] content);
public void write(java.lang.String filename, byte[] content)
fileWritten
callback method is called
when the operation ends up.
filename
- the full filenamecontent
- the bytes to writeFileIOListener.fileWritten(int state);
public void append(java.lang.String filename, byte[] content)
fileAppended
callback method is called
when the operation ends up.
filename
- the full filenamecontent
- the bytes to appendFileIOListener.fileAppended(int state);
public void run()
run
in interface java.lang.Runnable
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |