moka.io
Class File

java.lang.Object
  |
  +--moka.lang.Object
        |
        +--moka.io.IOStream
              |
              +--moka.io.File

public class File
extends IOStream

An abstract representation of file and directory pathnames.

Since:
MDK1.0a

Field Summary
 short mode
          The file mode.
static short MODE_APPEND
          Append (binary); open for writing at end of file, or create for writing if the file does not exist.
static short MODE_APPEND_TEXT
          Append (text); open for writing at end of file, or create for writing if the file does not exist.
static short MODE_OPEN_READ
          Open for reading only (binary).
static short MODE_OPEN_READ_TEXT
          Open for reading only (text).
static short MODE_OPEN_UPDATE
          Open an existing file for update (reading and writing) (binary).
static short MODE_OPEN_UPDATE_TEXT
          Open an existing file for update (reading and writing) (text).
static short MODE_UPDATE
          Create a new file for update (reading and writing) (binary).
static short MODE_UPDATE_APPEND
          Open for append (binary); open for update at the end of the file, or create if the file does not exist.
static short MODE_UPDATE_APPEND_TEXT
          Open for append (text); open for update at the end of the file, or create if the file does not exist.
static short MODE_UPDATE_TEXT
          Create a new file for update (reading and writing) (text).
static short MODE_WRITE
          Create for writing (binary).
static short MODE_WRITE_TEXT
          Create for writing (text).
 java.lang.String name
          The name of the file.
 java.lang.String type
          The type of the file to appear in the VAR-LINK menu.
 
Fields inherited from class moka.io.IOStream
error, opened
 
Constructor Summary
File(java.lang.String pathname)
          Creates a new File instance by using the given pathname string.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from this file.
 void close()
          Closes the stream.
 boolean delete()
          Deletes the file denoted by this abstract pathname.
 boolean exists()
          Tests whether the file denoted by this abstract pathname exists.
static void export(java.lang.String name, boolean b)
          Exports the boolean argument to a TIOS variable.
static void export(java.lang.String name, byte b)
          Exports the byte argument to a TIOS variable.
static void export(java.lang.String name, char c)
          Exports the char argument to a TIOS variable.
static void export(java.lang.String name, double d)
          Exports the double argument to a TIOS variable.
static void export(java.lang.String name, int i)
          Exports the int argument to a TIOS variable.
static void export(java.lang.String name, long l)
          Exports the long argument to a TIOS variable.
static void export(java.lang.String name, short s)
          Exports the short argument to a TIOS variable.
static void export(java.lang.String name, java.lang.String s)
          Exports the String argument to a TIOS variable.
static void exportExpr(java.lang.String name, java.lang.String expr)
          Exports an expression to a TIOS variable.
 void finalize()
          Frees the memory of system ressources used by this File object.
 boolean isArchived()
          Tests whether the file named by this abstract pathname is archived.
 boolean isHidden()
          Tests whether the file named by this abstract pathname is hidden.
 boolean isLocked()
          Tests whether the file named by this abstract pathname is locked.
 int length()
          Returns the length of the file denoted by this abstract pathname.
 boolean mkdir()
          Creates the directory named by this abstract pathname.
 void open()
          Opens an existing binary file in the current I/O mode (read only by default).
 void open(short mode)
          Opens a binary file.
 char readByte()
          Reads an 8 bit byte.
 void readBytes(moka.io.char_p buffer, short len)
          Copies to a buffer of bytes up to the specified length bytes read from the stream.
 boolean renameTo(java.lang.String dest)
          Renames the file denoted by this abstract pathname.
 boolean rmdir()
          Removes the directory named by this abstract pathname including all files in it.
 void seek(int pos)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
 boolean setArchived(boolean b)
          Sets if the file named by this abstract pathname is archived (in the archive memory instead of the RAM).
 boolean setHidden(boolean b)
          Sets if the file named by this abstract pathname is hidden (invisible for the TI-BASIC programs).
 boolean setLocked(boolean b)
          Sets if the file named by this abstract pathname is locked (cannot be altered).
static moka.io.File showVarLinkDialog()
          Shows the VAR-LINK dialog and return a file object, associated to the TIOS variable selected in the dialog.
 void skip(int n)
          Skips over n bytes of data from this file.
 void writeByte(char val)
          Writes an 8 bit byte.
 void writeBytes(moka.io.char_p buffer, short len)
          Writes a buffer of bytes up to the specified length.
 
Methods inherited from class moka.io.IOStream
readBoolean, readChar, readChars, readDouble, readInt, readLong, readObject, readShort, readString, writeBoolean, writeChar, writeChars, writeDouble, writeInt, writeLong, writeObject, writeShort, writeString
 
Methods inherited from class moka.lang.Object
equals, getClassName, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODE_OPEN_READ

public static final short MODE_OPEN_READ
Open for reading only (binary).

See Also:
Constant Field Values

MODE_WRITE

public static final short MODE_WRITE
Create for writing (binary). If a file by that name already exists, it will be overwritten.

See Also:
Constant Field Values

MODE_APPEND

public static final short MODE_APPEND
Append (binary); open for writing at end of file, or create for writing if the file does not exist.

See Also:
Constant Field Values

MODE_OPEN_UPDATE

public static final short MODE_OPEN_UPDATE
Open an existing file for update (reading and writing) (binary).

See Also:
Constant Field Values

MODE_UPDATE

public static final short MODE_UPDATE
Create a new file for update (reading and writing) (binary). If a file by that name already exists, it will be overwritten.

See Also:
Constant Field Values

MODE_UPDATE_APPEND

public static final short MODE_UPDATE_APPEND
Open for append (binary); open for update at the end of the file, or create if the file does not exist.

See Also:
Constant Field Values

MODE_OPEN_READ_TEXT

public static final short MODE_OPEN_READ_TEXT
Open for reading only (text).

See Also:
Constant Field Values

MODE_WRITE_TEXT

public static final short MODE_WRITE_TEXT
Create for writing (text). If a file by that name already exists, it will be overwritten.

See Also:
Constant Field Values

MODE_APPEND_TEXT

public static final short MODE_APPEND_TEXT
Append (text); open for writing at end of file, or create for writing if the file does not exist.

See Also:
Constant Field Values

MODE_OPEN_UPDATE_TEXT

public static final short MODE_OPEN_UPDATE_TEXT
Open an existing file for update (reading and writing) (text).

See Also:
Constant Field Values

MODE_UPDATE_TEXT

public static final short MODE_UPDATE_TEXT
Create a new file for update (reading and writing) (text). If a file by that name already exists, it will be overwritten.

See Also:
Constant Field Values

MODE_UPDATE_APPEND_TEXT

public static final short MODE_UPDATE_APPEND_TEXT
Open for append (text); open for update at the end of the file, or create if the file does not exist.

See Also:
Constant Field Values

mode

public short mode
The file mode. Should be only read.


name

public java.lang.String name
The name of the file. Should be only read.


type

public java.lang.String type
The type of the file to appear in the VAR-LINK menu.

Constructor Detail

File

public File(java.lang.String pathname)
Creates a new File instance by using the given pathname string. If the pathname string object risk to be used later, use a copy of the string object instead of the original.

Parameters:
pathname - A pathname string
Method Detail

showVarLinkDialog

public static moka.io.File showVarLinkDialog()
Shows the VAR-LINK dialog and return a file object, associated to the TIOS variable selected in the dialog. Using this method will force the main class of a project to implement the No_ROMCallsOptimization interface (otherwise the program would crash).

Returns:
a file object associated to the TIOS variable selected in the dialog, or null if no file was selected.

export

public static void export(java.lang.String name,
                          long l)
Exports the long argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable l The long to export


export

public static void export(java.lang.String name,
                          int i)
Exports the int argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable i The int to export


export

public static void export(java.lang.String name,
                          short s)
Exports the short argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable s The short to export


export

public static void export(java.lang.String name,
                          byte b)
Exports the byte argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable b The byte to export


export

public static void export(java.lang.String name,
                          double d)
Exports the double argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable d The double to export


export

public static void export(java.lang.String name,
                          char c)
Exports the char argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable c The char to export


export

public static void export(java.lang.String name,
                          boolean b)
Exports the boolean argument to a TIOS variable. If the name string object risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable b The boolean to export


export

public static void export(java.lang.String name,
                          java.lang.String s)
Exports the String argument to a TIOS variable. If the name and s string objects risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable s The String to export


exportExpr

public static void exportExpr(java.lang.String name,
                              java.lang.String expr)
Exports an expression to a TIOS variable. If the name and expr string objects risk to be used later, use a copy of the string object instead of the original. name The name of the TIOS variable expr The String to export


open

public void open()
Opens an existing binary file in the current I/O mode (read only by default).

Specified by:
open in class IOStream

open

public void open(short mode)
Opens a binary file.

Parameters:
mode - The file mode

close

public void close()
Closes the stream.

Specified by:
close in class IOStream

available

public int available()
Returns the number of bytes that can be read from this file.

Returns:
the number of bytes that can be read from this file.

delete

public boolean delete()
Deletes the file denoted by this abstract pathname.

Returns:
true if and only if the file is successfully deleted; false otherwise

exists

public boolean exists()
Tests whether the file denoted by this abstract pathname exists.

Returns:
true if and only if the file denoted by this abstract pathname exists; false otherwise

isArchived

public boolean isArchived()
Tests whether the file named by this abstract pathname is archived.

Returns:
true if and only if the file denoted by this abstract pathname is archived

isHidden

public boolean isHidden()
Tests whether the file named by this abstract pathname is hidden.

Returns:
true if and only if the file denoted by this abstract pathname is hidden

isLocked

public boolean isLocked()
Tests whether the file named by this abstract pathname is locked.

Returns:
true if and only if the file denoted by this abstract pathname is locked

length

public int length()
Returns the length of the file denoted by this abstract pathname.

Returns:
The length, in bytes, of the file denoted by this abstract pathname

mkdir

public boolean mkdir()
Creates the directory named by this abstract pathname.

Returns:
true if and only if the directory was created; false otherwise

renameTo

public boolean renameTo(java.lang.String dest)
Renames the file denoted by this abstract pathname. If the dest string object risk to be used later, use a copy of the string object instead of the original.

Parameters:
dest - The new abstract pathname for the named file
Returns:
true if and only if the renaming succeeded; false otherwise

rmdir

public boolean rmdir()
Removes the directory named by this abstract pathname including all files in it.

Returns:
true if and only if the directory was removed; false otherwise

seek

public void seek(int pos)
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.

Parameters:
pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.

setArchived

public boolean setArchived(boolean b)
Sets if the file named by this abstract pathname is archived (in the archive memory instead of the RAM).

Parameters:
b - a flag indicating whether this file component is archived.
Returns:
true if and only if the operation succeeded; false otherwise

setHidden

public boolean setHidden(boolean b)
Sets if the file named by this abstract pathname is hidden (invisible for the TI-BASIC programs).

Parameters:
b - a flag indicating whether this file is Hidden.
Returns:
true if and only if the operation succeeded; false otherwise

setLocked

public boolean setLocked(boolean b)
Sets if the file named by this abstract pathname is locked (cannot be altered).

Parameters:
b - a flag indicating whether this file is locked.
Returns:
true if and only if the operation succeeded; false otherwise

skip

public void skip(int n)
Skips over n bytes of data from this file.

Parameters:
n - the number of bytes to be skipped.

writeByte

public void writeByte(char val)
Writes an 8 bit byte.

Specified by:
writeByte in class IOStream
Parameters:
val - the byte value to be written

writeBytes

public void writeBytes(moka.io.char_p buffer,
                       short len)
Writes a buffer of bytes up to the specified length.

Specified by:
writeBytes in class IOStream
Parameters:
buffer - the buffer of bytes to be written
len - the specified length

readByte

public char readByte()
Reads an 8 bit byte.

Specified by:
readByte in class IOStream
Returns:
the byte value read

readBytes

public void readBytes(moka.io.char_p buffer,
                      short len)
Copies to a buffer of bytes up to the specified length bytes read from the stream.

Specified by:
readBytes in class IOStream
Parameters:
buffer - the buffer of bytes where the bytes will be copied
len - the specified length

finalize

public void finalize()
Frees the memory of system ressources used by this File object. If the stream is opened, it will be closed first.

Overrides:
finalize in class IOStream