| 
 | " 2013 FRC Java API" | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.squawk.io.ConnectionBase
com.sun.squawk.io.ConnectionBaseAdapter
com.sun.squawk.io.j2me.file.Protocol
public class Protocol
This class implements the necessary functionality for a File connection. This version extends JSR 75 FileConnections by allowing relative pathnames, and having the host and root sections of the path be optional. The result is that a URI that starts with 3 or 4 slashes is treated as an absolute path, while a URI that starts with two slashes is treated as relative.
| Field Summary | 
|---|
| Fields inherited from class com.sun.squawk.io.ConnectionBaseAdapter | 
|---|
| connectionOpen, iStreams, maxIStreams, maxOStreams, oStreams | 
| Constructor Summary | |
|---|---|
| Protocol()Constructor for file connection implementation. | |
| Method Summary | |
|---|---|
|  int | available()Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. | 
| protected  void | checkReadPermission()Checks that the application has permission to read. | 
| protected  void | checkRootReadPermission()Checks that the application has permission to read the root path. | 
| protected  void | checkWritePermission()Checks that the application has permission to write. | 
| protected  void | closeInputStream()Called once by each child input stream. | 
| protected  void | closeOutputStream()Called once by each child output stream. | 
| protected  void | connect(String name,
        int mode,
        boolean timeouts)Establishes the connection. | 
|  void | create() | 
| static void | create(String name)Create a file for writing | 
|  void | delete() | 
| protected  void | disconnect()Free up the connection resources. | 
| protected  void | ensureConnected()Checks that the connection is already open. | 
| protected  void | ensureOpenAndConnected()Checks that the connection is already open and connected. | 
|  boolean | exists() | 
| static boolean | exists(String name)return true if the specified file exists | 
|  long | fileSize() | 
| protected  void | flush()Forces any buffered output bytes to be written out. | 
|  String | getName() | 
|  String | getPath() | 
|  String | getURL() | 
|  boolean | isDirectory() | 
|  boolean | isOpen() | 
|  Connection | open(String protocol,
     String name,
     int mode,
     boolean timeouts)Open the connection | 
|  InputStream | openInputStream()Open and return an input stream for a connection. | 
|  OutputStream | openOutputStream()Open and return an output stream for a connection. | 
|  OutputStream | openOutputStream(long byteOffset) | 
|  Connection | openPrim(String name,
         int mode,
         boolean timeouts)Opens the file connection. | 
| protected  int | readBytes(byte[] b,
          int off,
          int len)Reads up to lenbytes of data from the input stream into
 an array of bytes, blocks until at least one byte is available. | 
| protected  int | writeBytes(byte[] b,
           int off,
           int len)Writes lenbytes from the specified byte array
 starting at offsetoffto this output stream. | 
| Methods inherited from class com.sun.squawk.io.ConnectionBaseAdapter | 
|---|
| close, ensureOpen, initStreamConnection, mark, markSupported, notifyClosedInput, notifyClosedOutput, openDataInputStream, openDataOutputStream, reset | 
| Methods inherited from class java.lang.Object | 
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Methods inherited from interface com.sun.squawk.microedition.io.FileConnection | 
|---|
| openDataInputStream, openDataOutputStream | 
| Methods inherited from interface javax.microedition.io.Connection | 
|---|
| close | 
| Constructor Detail | 
|---|
public Protocol()
| Method Detail | 
|---|
public int available()
              throws IOException
available in class ConnectionBaseAdapterIOException - if an I/O error occurs.
public Connection open(String protocol,
                       String name,
                       int mode,
                       boolean timeouts)
                throws IOException
open in class ConnectionBasename - the target for the connection. It must be in this
        format: "//mode - read/write mode of the connection (currently ignored).timeouts - A flag to indicate that the called wants timeout
        exceptions (currently ignored).protocol - The URL protocol
IOException
ConnectionNotFoundException - If the connection cannot
                                        be found.
public Connection openPrim(String name,
                           int mode,
                           boolean timeouts)
                    throws IOException
openPrim in class ConnectionBaseAdaptername - URL path fragmentmode - access modetimeouts - flag to indicate that timeouts allowed
IOException - if some other kind of I/O error occurs.public boolean isOpen()
isOpen in interface FileConnection
public InputStream openInputStream()
                            throws IOException
openInputStream in interface FileConnectionopenInputStream in interface InputConnectionopenInputStream in class ConnectionBaseAdapterIOException - if an I/O error occurs, if the method is invoked
          on a directory, if the connection's target does not
          yet exist, or the connection's target is not accessible.
IllegalStateException - if the application does have read
             access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
SecurityException - If the application is not granted read
          access to the connection's target.
public OutputStream openOutputStream()
                              throws IOException
openOutputStream(long) should be used to position an output
 stream to a different position in the file.
 
 Changes made to a file through an output stream may not be immediately
 made to the actual file residing on the file system because
 platform and implementation specific use of caching and buffering of the
 data.  Stream contents and file length extensions are not necessarily
 visible outside of the application immediately unless
 flush() is called on the stream.? The returned output
  stream is automatically and synchronously flushed when it is closed.
 
openOutputStream in interface FileConnectionopenOutputStream in interface OutputConnectionopenOutputStream in class ConnectionBaseAdapterIOException - If an I/O error occurs, if the method is
             invoked on
          a directory, the file does not yet exist, or the connection's
          target is not accessible.
IllegalStateException - if the application does have write
             access
          to the connection's target but has opened the connection in
          Connector.READ mode.
SecurityException - If the application is not granted write
          access to the connection's target.openOutputStream(long)
public OutputStream openOutputStream(long byteOffset)
                              throws IOException
openOutputStream in interface FileConnectionIOException
public long fileSize()
              throws IOException
fileSize in interface FileConnectionIOException
public void create()
            throws IOException
create in interface FileConnectionIOExceptionpublic boolean exists()
exists in interface FileConnectionpublic boolean isDirectory()
isDirectory in interface FileConnection
public void delete()
            throws IOException
delete in interface FileConnectionIOExceptionpublic String getName()
getName in interface FileConnectionpublic String getPath()
getPath in interface FileConnectionpublic String getURL()
getURL in interface FileConnection
protected int readBytes(byte[] b,
                        int off,
                        int len)
                 throws IOException
len bytes of data from the input stream into
 an array of bytes, blocks until at least one byte is available.
readBytes in class ConnectionBaseAdapterb - the buffer into which the data is read.off - the start offset in array b
                   at which the data is written.len - the maximum number of bytes to read.
-1 if there is no more data because the end of
             the stream has been reached.
IOException - if an I/O error occurs.
protected int writeBytes(byte[] b,
                         int off,
                         int len)
                  throws IOException
len bytes from the specified byte array
 starting at offset off to this output stream.
 Polling the native code is done here to allow for simple asynchronous native code to be written. Not all implementations work this way (they block in the native code) but the same Java code works for both.
writeBytes in class ConnectionBaseAdapterb - the data.off - the start offset in the data.len - the number of bytes to write.
IOException - if an I/O error occurs. In particular,
             an IOException is thrown if the output
             stream is closed.
protected void flush()
              throws IOException
flush is
 that calling it is an indication that, if any bytes previously
 written that have been buffered by the connection,
 should immediately be written to their intended destination.
 
 The flush method of ConnectionBaseAdapter
 does nothing.
flush in class ConnectionBaseAdapterIOException - if an I/O error occurs.
protected void closeInputStream()
                         throws IOException
closeInputStream in class ConnectionBaseAdapterIOException - if the subclass throws one
protected void closeOutputStream()
                          throws IOException
closeOutputStream in class ConnectionBaseAdapterIOException - if the subclass throws one
protected void disconnect()
                   throws IOException
disconnect in class ConnectionBaseAdapterIOException - if an I/O error occurs.
protected void connect(String name,
                       int mode,
                       boolean timeouts)
                throws IOException
name - URL path fragmentmode - access modetimeouts - flag to indicate that timeouts allowed
IOException - if an error occurs
protected void ensureConnected()
                        throws IOException
IOException - if the connection is closedpublic static boolean exists(String name)
name - 
public static void create(String name)
                   throws IOException
name - full pathname to file
IOException - if file can't be created
protected void ensureOpenAndConnected()
                               throws IOException
ConnectionClosedException - if the connection is closed
IOException - if any error occurs while connecting
protected final void checkReadPermission()
                                  throws InterruptedIOException
InterruptedIOException - if the permission dialog is
                                terminated before completed
SecurityException - if read is not allowed
IllegalStateException - if connection is write only
protected final void checkRootReadPermission()
                                      throws InterruptedIOException
InterruptedIOException - if the permission dialog is
 terminated before completed
SecurityException - if read is not allowed
IllegalStateException - if connection is write only
protected final void checkWritePermission()
                                   throws InterruptedIOException
InterruptedIOException - if the permission dialog is
                                terminated before completed
SecurityException - if write is not allowed
IllegalStateException - if connection is read only| 
 | " 2013 FRC Java API" | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||