J2ME CDC

javax.microedition.io
Interface RandomAccessConnection

All Superinterfaces:
Connection, DataInput, DataOutput, InputConnection, OutputConnection
All Known Subinterfaces:
DirectoryConnection

public interface RandomAccessConnection
extends InputConnection, OutputConnection, DataInput, DataOutput

A connection to a random access memory


Method Summary
 long getLength()
          Get the length of the data
 long getPosition()
          Returns the current offset into the data.
 boolean isSelected()
          Test to see if a record in the collection is selected.
 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.
 void seek(long pos)
          Sets the position pointer offset, measured from the beginning of the data, at which the next read or write occurs.
 void setLength(long len)
          Set the length of the data (for truncation).
 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.
 
Methods inherited from interface javax.microedition.io.InputConnection
openDataInputStream, openInputStream
 
Methods inherited from interface javax.microedition.io.Connection
close
 
Methods inherited from interface javax.microedition.io.OutputConnection
openDataOutputStream, openOutputStream
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 
Methods inherited from interface java.io.DataOutput
write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 

Method Detail

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.

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

setLength

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

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.

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.

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
Parameters:
b - the byte to be written.
Throws:
IOException - if an I/O error occurs.

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
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.

J2ME CDC

Java is a trademark or registred trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,
Palo, Alto, California, 94303, U.S.A All Rights Reserved.