Methods Summary |
---|
public 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. The next caller might be the same thread or
another thread. This classes implementation always returns
0 . It is up to subclasses to override this method.
return 0;
|
public void | checkForPermission(java.lang.String name)Check for the required permission, if needed.
Scheduler scheduler;
MIDletSuite midletSuite;
if (permissionChecked) {
return;
}
permissionChecked = true;
if (requiredPermission == -1) {
return;
}
scheduler = Scheduler.getScheduler();
midletSuite = scheduler.getMIDletSuite();
// there is no suite running when installing from the command line
if (midletSuite != null) {
if (protocol != null) {
name = protocol + ":" + name;
}
try {
midletSuite.checkForPermission(requiredPermission, name);
} catch (InterruptedException ie) {
throw new InterruptedIOException(
"Interrupted while trying to ask the user permission");
}
}
|
public void | close()Close the connection.
if (connectionOpen) {
connectionOpen = false;
closeCommon();
}
|
void | closeCommon()Disconnect if the connection and all the streams and the closed.
if (!connectionOpen && iStreams == 0 && oStreams == 0) {
disconnect();
}
|
protected void | closeInputStream()Called once by each child input stream.
If the input stream is marked open, it will be marked closed and
the if the connection and output stream are closed the disconnect
method will be called.
iStreams--;
closeCommon();
|
protected void | closeOutputStream()Called once by each child output stream.
If the output stream is marked open, it will be marked closed and
the if the connection and input stream are closed the disconnect
method will be called.
oStreams--;
closeCommon();
|
protected abstract void | connect(java.lang.String name, int mode, boolean timeouts)Connect to a target.
|
protected abstract void | disconnect()Free up the connection resources.
|
protected void | ensureOpen()Check if the connection is open.
if (!connectionOpen) {
throw new IOException("Connection closed");
}
|
protected void | flush()Forces any buffered output bytes to be written out.
The general contract of 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.
|
public java.io.DataInputStream | openDataInputStream()Open and return a data input stream for a connection.
return new DataInputStream(openInputStream());
|
public java.io.DataOutputStream | openDataOutputStream()Open and return a data output stream for a connection.
return new DataOutputStream(openOutputStream());
|
public java.io.InputStream | openInputStream()Returns an input stream.
InputStream i;
ensureOpen();
if (maxIStreams == 0) {
throw new IOException("no more input streams available");
}
i = new BaseInputStream(this);
maxIStreams--;
iStreams++;
return i;
|
public java.io.OutputStream | openOutputStream()Returns an output stream.
OutputStream o;
ensureOpen();
if (maxOStreams == 0) {
throw new IOException("no more output streams available");
}
o = new BaseOutputStream(this);
maxOStreams--;
oStreams++;
return o;
|
public Connection | openPrim(java.lang.String name, int mode, boolean timeouts)Check for required permission and open a connection to a target.
checkForPermission(name);
switch (mode) {
case Connector.READ:
case Connector.WRITE:
case Connector.READ_WRITE:
break;
default:
throw new IllegalArgumentException("Illegal mode");
}
connect(name, mode, timeouts);
connectionOpen = true;
return this;
|
public Connection | openPrim(SecurityToken token, java.lang.String name, int mode, boolean timeouts)Check for the required permission and open a connection to a target.
This method can be used with permissions greater than
the current MIDlet suite.
if (requiredPermission != -1) {
token.checkIfPermissionAllowed(requiredPermission);
}
permissionChecked = true;
return openPrim(name, mode, timeouts);
|
public Connection | openPrim(SecurityToken token, java.lang.String name)Check for required permission and open a connection to a target.
This method can be used with permissions greater than
the current MIDlet suite. Assume read/write and no timeouts.
return openPrim(token, name, Connector.READ_WRITE, false);
|
protected abstract int | readBytes(byte[] b, int off, int len)Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
|
protected void | verifyPermissionCheck()Lets a subclass know that the security check was done.
Called by the connect method of subclasses that require permission.
This method is needed since the security check must be put off
until connection since the name of the resource must be
presented to the user in the permission question.
An attacker could directly construct a in a subclass of the
protocol and then call its connect method. A subclass can detect
this attack by calling this method.
if (permissionChecked) {
return;
}
throw new SecurityException("The permission check was bypassed");
|
protected abstract int | writeBytes(byte[] b, int off, int len)Writes 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.
|