com.sun.cdc.io.j2me.file
Class ProtocolBase

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.DataOutputStream
              extended by com.sun.cdc.io.GeneralBase
                  extended by com.sun.cdc.io.ConnectionBase
                      extended by com.sun.cdc.io.j2me.file.ProtocolBase
All Implemented Interfaces:
ConnectionBaseInterface, DataInput, DataOutput, Connection, InputConnection, OutputConnection, StreamConnection
Direct Known Subclasses:
ProtocolNative

public abstract class ProtocolBase
extends ConnectionBase
implements InputConnection, OutputConnection, StreamConnection

This implements the default "file:" protocol J2ME


Field Summary
protected static int O_RAND
          Operation mode
protected static int O_READ
           
protected static int O_WRITE
           
protected  int openMode
          Open mode
protected  int operationMode
           
 
Fields inherited from class java.io.DataOutputStream
written
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ProtocolBase()
           
 
Method Summary
abstract  int available0()
           
 boolean canRead()
          Test to see if the selected item can be read
abstract  boolean canRead0()
           
 boolean canWrite()
          Test to see if the selected item can be written
abstract  boolean canWrite0()
           
protected  void checkPermission(String name, String params, int mode)
           
 void close()
          Close the connection.
abstract  void close0()
           
 void create()
          Create a data item in the collection with a randomly chosen unique name and select it
 void create(int i)
          Create an item with the supplied number
 void create(String name)
          Create a data item with the supplied name and select it
abstract  void create0()
           
 void createDirectory(String name)
          Create a directory with the supplied name
abstract  void createDirectory0(String name)
           
abstract  void createName0(String name)
           
abstract  void createNameByInt0(int i)
           
 void delete()
          Delete the current data item from the collection
abstract  void delete0()
           
 void deleteDirectory()
          Delete the current data item from the collection
 void deselectItem()
          Unselect the current item.
abstract  void deselectItem0()
           
protected  void ensureDirectory()
           
protected  void ensureNotDirectory()
           
protected  void ensureOpen()
           
protected  void ensureOpenAndSelected()
           
protected  void ensureOpenForReading()
           
protected  void ensureOpenForReadingAndSelected()
           
protected  void ensureOpenForWriting()
           
protected  void ensureOpenForWritingAndSelected()
           
 long getAvailableSpace()
          Return the size in bytes that the collection can grow to
abstract  long getAvailableSpace0()
           
 int getItemCount()
          Return the number of items in the collection
abstract  int getItemCount0()
           
 String getItemName()
          Return the name of the currently selected item
abstract  String getItemName0()
           
 int getItemNumber()
          Return the number of the current item
abstract  int getItemNumber0()
           
 long getLength()
          Get the length of the data
abstract  long getLength0()
           
 long getModificationDate()
          Return the date that the item was last modified
abstract  long getModificationDate0()
           
 long getPosition()
          Returns the current offset into the data.
abstract  long getPosition0()
           
protected  void inputStreamPermissionCheck()
           
 boolean isDirectory()
          Test to see if the current item a directory
abstract  boolean isDirectory0()
           
 boolean isSelected()
          Test to see if a record in the collection is selected.
abstract  boolean isSelected0()
           
 void open(String name, int mode, boolean timeouts)
          Open a connection to a target.
abstract  Connection open0(String openName, String parms, int mode)
          \ Native Methods * \
 InputStream openInputStream()
          Returns an input stream for a database record
 OutputStream openOutputStream()
          Returns an output stream for this socket.
 Connection openPrim(String name, int mode, boolean timeouts)
          Open a connection to a target.
protected  void outputStreamPermissionCheck()
           
 int read()
          Reads a byte of data.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data into an array of bytes.
abstract  int read0()
           
 int read0(byte[] b, int off, int len)
          Reads up to len bytes of data into an array of bytes.
abstract  int readBytes0(byte[] b, int off, int len)
           
 void rename(int i)
          Rename the current data item
 void rename(String newName)
          Rename the current data item
abstract  void rename0(String name2)
           
abstract  void renameByInt0(int i)
           
 void renameDirectory(String newName)
          Rename a directory with the supplied name
abstract  void renameDirectory0(String name2)
           
 void seek(long pos)
          Sets the position pointer offset, measured from the beginning of the data, at which the next read or write occurs.
abstract  void seek0(long pos)
           
 boolean selectFirstItem()
          Select the first record int the database
abstract  boolean selectFirstItem0()
           
 boolean selectItem(int i)
          Select an item in the collection
 boolean selectItem(String name)
          Select an item in the collection
abstract  boolean selectItem0(String name)
           
abstract  boolean selectItemByInt0(int i)
           
 boolean selectNextItem()
          Select the next record int the database
abstract  boolean selectNextItem0()
           
 void setLength(long len)
          Set the length of the data (for truncation).
abstract  void setLength0(long len)
           
protected  void setProtocolBaseDirectory(String name)
           
 void setReadable(boolean tf)
          Set or clear the read bit
abstract  void setReadable0(boolean tf)
           
 void setWritable(boolean tf)
          Set or clear the write bit
abstract  void setWritable0(boolean tf)
           
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to the data
 void write(int b)
          Writes the specified byte to this file.
abstract  void write0(int b)
           
abstract  void writeBytes0(byte[] b, int off, int len)
           
 
Methods inherited from class com.sun.cdc.io.ConnectionBase
openDataInputStream, openDataOutputStream
 
Methods inherited from class com.sun.cdc.io.GeneralBase
flush, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skip, skipBytes
 
Methods inherited from class java.io.DataOutputStream
size, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.microedition.io.InputConnection
openDataInputStream
 
Methods inherited from interface javax.microedition.io.OutputConnection
openDataOutputStream
 
Methods inherited from interface java.io.DataOutput
write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 

Field Detail

openMode

protected int openMode
Open mode


O_RAND

protected static final int O_RAND
Operation mode

See Also:
Constant Field Values

O_READ

protected static final int O_READ
See Also:
Constant Field Values

O_WRITE

protected static final int O_WRITE
See Also:
Constant Field Values

operationMode

protected int operationMode
Constructor Detail

ProtocolBase

public ProtocolBase()
Method Detail

open

public void open(String name,
                 int mode,
                 boolean timeouts)
          throws IOException
Description copied from class: ConnectionBase
Open a connection to a target.

Specified by:
open in class ConnectionBase
Parameters:
name - the target of the connection
mode - the access mode
timeouts - A flag to indicate that the called wants timeout exceptions
Throws:
ConnectionNotFoundException - If the connection cannot be found.
IOException - If some other kind of I/O error occurs.

checkPermission

protected void checkPermission(String name,
                               String params,
                               int mode)

outputStreamPermissionCheck

protected void outputStreamPermissionCheck()
                                    throws IOException
Throws:
IOException

inputStreamPermissionCheck

protected void inputStreamPermissionCheck()

openPrim

public Connection openPrim(String name,
                           int mode,
                           boolean timeouts)
                    throws IOException
Description copied from class: ConnectionBase
Open a connection to a target.

Specified by:
openPrim in interface ConnectionBaseInterface
Overrides:
openPrim in class ConnectionBase
Parameters:
name - the target of the connection
mode - the access mode
timeouts - A flag to indicate that the called wants timeout exceptions
Returns:
A new Connection object
Throws:
ConnectionNotFoundException - If the connection cannot be found.
IOException - If some other kind of I/O error occurs.

ensureOpen

protected void ensureOpen()
                   throws IOException
Throws:
IOException

ensureOpenForReading

protected void ensureOpenForReading()
                             throws IOException
Throws:
IOException

ensureOpenForWriting

protected void ensureOpenForWriting()
                             throws IOException
Throws:
IOException

ensureOpenAndSelected

protected void ensureOpenAndSelected()
                              throws IOException
Throws:
IOException

ensureOpenForReadingAndSelected

protected void ensureOpenForReadingAndSelected()
                                        throws IOException
Throws:
IOException

ensureOpenForWritingAndSelected

protected void ensureOpenForWritingAndSelected()
                                        throws IOException
Throws:
IOException

ensureDirectory

protected void ensureDirectory()
                        throws IOException
Throws:
IOException

ensureNotDirectory

protected void ensureNotDirectory()
                           throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Close the connection.

Specified by:
close in interface Connection
Overrides:
close in class GeneralBase
Throws:
IOException - if an I/O error occurs when closing the connection.
See Also:
FilterOutputStream.flush(), FilterOutputStream.out

setProtocolBaseDirectory

protected void setProtocolBaseDirectory(String name)

openInputStream

public InputStream openInputStream()
                            throws IOException
Returns an input stream for a database record

Specified by:
openInputStream in interface InputConnection
Overrides:
openInputStream in class ConnectionBase
Returns:
an input stream for reading bytes from this record.
Throws:
IOException - if an I/O error occurs when creating the input stream.

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Returns an output stream for this socket.

Specified by:
openOutputStream in interface OutputConnection
Overrides:
openOutputStream in class ConnectionBase
Parameters:
True - if appending
Returns:
an output stream for writing bytes to this socket.
Throws:
IOException - if an I/O error occurs when creating the output stream.

isSelected

public boolean isSelected()
                   throws IOException
Test to see if a record in the collection is selected. Until this is done none of the data access methods below will work. Some random access connection are always selected, but other ones, such as a MetadataConncetion may require a specific record to be selected before I/O can commence.

Returns:
true if the connection is selected, otherwise false.
Throws:
IOException

seek

public void seek(long pos)
          throws IOException
Sets the position pointer offset, measured from the beginning of the data, at which the next read or write occurs. The offset may be set beyond the end of the data. Setting the offset beyond the end of the data does not change the data length. The data length will change only by writing after the offset has been set beyond the end of the data.

Parameters:
pos - the offset position, measured in bytes from the beginning of the data, at which to set the position pointer.
Throws:
IOException - if pos is less than 0, if an I/O error occurs, or there is an input or output stream open on the data.

getPosition

public long getPosition()
                 throws IOException
Returns the current offset into the data.

Returns:
the offset from the beginning of the data, in bytes, at which the next read or write occurs.
Throws:
IOException - if an I/O error occurs.

getLength

public long getLength()
               throws IOException
Get the length of the data

Returns:
the length of the data
Throws:
IOException

setLength

public void setLength(long len)
               throws IOException
Set the length of the data (for truncation).

Parameters:
len - the new length of the data
Throws:
IOException

read

public int read()
         throws IOException
Reads a byte of data. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff). This method blocks if no input is yet available.

Overrides:
read in class GeneralBase
Returns:
the next byte of data, or -1 if the end of the data has been reached.
Throws:
IOException - if an I/O error occurs. Not thrown if end-of-data has been reached.

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads up to len bytes of data into an array of bytes. This method blocks until at least one byte of input is available.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the data has been reached.
Throws:
IOException - if an I/O error occurs.

read0

public int read0(byte[] b,
                 int off,
                 int len)
          throws IOException
Reads up to len bytes of data into an array of bytes. This method blocks until at least one byte of input is available.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the data has been reached.
Throws:
IOException - if an I/O error occurs.

write

public void write(int b)
           throws IOException
Writes the specified byte to this file. The write starts at the current position pointer.

Specified by:
write in interface DataOutput
Overrides:
write in class GeneralBase
Parameters:
b - the byte to be written.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterOutputStream.out

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to the data

Specified by:
write in interface DataOutput
Overrides:
write in class GeneralBase
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterOutputStream.out

getAvailableSpace

public long getAvailableSpace()
                       throws IOException
Return the size in bytes that the collection can grow to

Returns:
size
Throws:
IOException

getItemCount

public int getItemCount()
                 throws IOException
Return the number of items in the collection

Returns:
size
Throws:
IOException

selectFirstItem

public boolean selectFirstItem()
                        throws IOException
Select the first record int the database

Returns:
true if there was a record false if the collection was empty
Throws:
IOException - if an I/O error occurs.

selectNextItem

public boolean selectNextItem()
                       throws IOException
Select the next record int the database

Returns:
true if there was another record false otherwise
Throws:
IOException - if an I/O error occurs.

selectItem

public boolean selectItem(String name)
                   throws IOException
Select an item in the collection

Parameters:
name - the name of the item to select
Returns:
true if the record exists
Throws:
IOException - if an I/O error occurs.

selectItem

public boolean selectItem(int i)
                   throws IOException
Select an item in the collection

Parameters:
i - the record number
Returns:
true if the record exists
Throws:
IOException - if an I/O error occurs.

deselectItem

public void deselectItem()
                  throws IOException
Unselect the current item. This is a way to unlock a record without locking another one.

Throws:
IOException - if an I/O error occurs.

isDirectory

public boolean isDirectory()
                    throws IOException
Test to see if the current item a directory

Returns:
true if it is, false if it is not
Throws:
IOException

create

public void create()
            throws IOException
Create a data item in the collection with a randomly chosen unique name and select it

Throws:
IOException - if an I/O error occurs.

create

public void create(String name)
            throws IOException
Create a data item with the supplied name and select it

Parameters:
name - the name of the item to create
Throws:
IOException - if an I/O error occurs.

create

public void create(int i)
            throws IOException
Create an item with the supplied number

Parameters:
i - the record number
Throws:
IOException - if an I/O error occurs.

createDirectory

public void createDirectory(String name)
                     throws IOException
Create a directory with the supplied name

Parameters:
name - the name of the directory to create
Throws:
IOException - if an I/O error occurs.

delete

public void delete()
            throws IOException
Delete the current data item from the collection

Throws:
IOException - if an I/O error occurs.

deleteDirectory

public void deleteDirectory()
                     throws IOException
Delete the current data item from the collection

Throws:
IOException - if an I/O error occurs.

rename

public void rename(String newName)
            throws IOException
Rename the current data item

Parameters:
name - the new name for the item
Throws:
IOException - if an I/O error occurs.

rename

public void rename(int i)
            throws IOException
Rename the current data item

Parameters:
name - the new name for the item
Throws:
IOException - if an I/O error occurs.

renameDirectory

public void renameDirectory(String newName)
                     throws IOException
Rename a directory with the supplied name

Parameters:
newName - the new name for the directory
Throws:
IOException - if an I/O error occurs.

getItemName

public String getItemName()
                   throws IOException
Return the name of the currently selected item

Returns:
the name of the item or null if no item is selected
Throws:
IOException - if an I/O error occurs.

getItemNumber

public int getItemNumber()
                  throws IOException
Return the number of the current item

Returns:
the current item number
Throws:
IOException - if an I/O error occurs or if the item does not have a numeric name.

getModificationDate

public long getModificationDate()
                         throws IOException
Return the date that the item was last modified

Returns:
date or -1 if the record was undated.
Throws:
IOException - if an I/O error occurs.

canRead

public boolean canRead()
                throws IOException
Test to see if the selected item can be read

Returns:
true if the item can be read, else false.
Throws:
IOException - if an I/O error occurs.

setReadable

public void setReadable(boolean tf)
                 throws IOException
Set or clear the read bit

Parameters:
tf - the new value for the read bit
Throws:
IOException - if an I/O error occurs.

canWrite

public boolean canWrite()
                 throws IOException
Test to see if the selected item can be written

Returns:
true if the item can be written, else false.
Throws:
IOException - if an I/O error occurs.

setWritable

public void setWritable(boolean tf)
                 throws IOException
Set or clear the write bit

Parameters:
tf - the new value for the write bit
Throws:
IOException - if an I/O error occurs.

open0

public abstract Connection open0(String openName,
                                 String parms,
                                 int mode)
                          throws IOException
\ Native Methods * \

Throws:
IOException

close0

public abstract void close0()
                     throws IOException
Throws:
IOException

getAvailableSpace0

public abstract long getAvailableSpace0()
                                 throws IOException
Throws:
IOException

getItemCount0

public abstract int getItemCount0()
                           throws IOException
Throws:
IOException

selectFirstItem0

public abstract boolean selectFirstItem0()
                                  throws IOException
Throws:
IOException

selectNextItem0

public abstract boolean selectNextItem0()
                                 throws IOException
Throws:
IOException

selectItem0

public abstract boolean selectItem0(String name)
                             throws IOException
Throws:
IOException

selectItemByInt0

public abstract boolean selectItemByInt0(int i)
                                  throws IOException
Throws:
IOException

deselectItem0

public abstract void deselectItem0()
                            throws IOException
Throws:
IOException

isSelected0

public abstract boolean isSelected0()
                             throws IOException
Throws:
IOException

create0

public abstract void create0()
                      throws IOException
Throws:
IOException

createName0

public abstract void createName0(String name)
                          throws IOException
Throws:
IOException

createNameByInt0

public abstract void createNameByInt0(int i)
                               throws IOException
Throws:
IOException

createDirectory0

public abstract void createDirectory0(String name)
                               throws IOException
Throws:
IOException

delete0

public abstract void delete0()
                      throws IOException
Throws:
IOException

rename0

public abstract void rename0(String name2)
                      throws IOException
Throws:
IOException

renameByInt0

public abstract void renameByInt0(int i)
                           throws IOException
Throws:
IOException

renameDirectory0

public abstract void renameDirectory0(String name2)
                               throws IOException
Throws:
IOException

getLength0

public abstract long getLength0()
                         throws IOException
Throws:
IOException

setLength0

public abstract void setLength0(long len)
                         throws IOException
Throws:
IOException

getModificationDate0

public abstract long getModificationDate0()
                                   throws IOException
Throws:
IOException

getItemName0

public abstract String getItemName0()
                             throws IOException
Throws:
IOException

getItemNumber0

public abstract int getItemNumber0()
                            throws IOException
Throws:
IOException

isDirectory0

public abstract boolean isDirectory0()
                              throws IOException
Throws:
IOException

canRead0

public abstract boolean canRead0()
                          throws IOException
Throws:
IOException

canWrite0

public abstract boolean canWrite0()
                           throws IOException
Throws:
IOException

setReadable0

public abstract void setReadable0(boolean tf)
                           throws IOException
Throws:
IOException

setWritable0

public abstract void setWritable0(boolean tf)
                           throws IOException
Throws:
IOException

available0

public abstract int available0()
                        throws IOException
Throws:
IOException

seek0

public abstract void seek0(long pos)
                    throws IOException
Throws:
IOException

getPosition0

public abstract long getPosition0()
                           throws IOException
Throws:
IOException

read0

public abstract int read0()
                   throws IOException
Throws:
IOException

readBytes0

public abstract int readBytes0(byte[] b,
                               int off,
                               int len)
                        throws IOException
Throws:
IOException

write0

public abstract void write0(int b)
                     throws IOException
Throws:
IOException

writeBytes0

public abstract void writeBytes0(byte[] b,
                                 int off,
                                 int len)
                          throws IOException
Throws:
IOException