本文整理汇总了Java中javax.microedition.io.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于javax.microedition.io包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import javax.microedition.io.Connection; //导入依赖的package包/类
public Connection open(String protocol, String url, int mode, boolean timeouts) throws IOException {
if(protocol == null || protocol.length()==0){
throw new IllegalArgumentException("Protocol cannot be null or empty");
}
if (mode != Connector.READ && mode != Connector.WRITE && mode != Connector.READ_WRITE) {
throw new IllegalArgumentException("illegal mode: " + mode);
}
if (opened) {
throw new IOException("already connected");
}
this.url = url;
this.mode = mode;
this.timeouts = timeouts;
parseURL();
opened=true;
opens++;
return this;
}
示例2: open
import javax.microedition.io.Connection; //导入依赖的package包/类
/**
* Sets up the state of the connection, but
* does not actually connect to the server until there's something
* to do.
*
* @param theUrl URL object
* @param mode The access mode, ignored
* timeout exceptions, ignored
*
* @return reference to this connection
*
* @exception IllegalArgumentException If a parameter is invalid.
* @exception ConnectionNotFoundException If the connection cannot be
* found.
* @exception IOException If some other kind of I/O error occurs.
*/
private Connection open(HttpUrl theUrl, int mode)
throws IOException, IllegalArgumentException,
ConnectionNotFoundException {
url = theUrl;
initStreamConnection(mode);
if (url.port == -1) {
url.port = default_port;
}
if (url.host == null) {
throw new IllegalArgumentException("missing host in URL");
}
hostAndPort = url.host + ":" + url.port;
return this;
}
示例3: cleanup
import javax.microedition.io.Connection; //导入依赖的package包/类
/**
* @inheritDoc
*/
public void cleanup(Object o) {
try {
if(o != null) {
if(o instanceof Connection) {
((Connection) o).close();
return;
}
if(o instanceof RecordEnumeration) {
((RecordEnumeration) o).destroy();
return;
}
if(o instanceof RecordStore) {
((RecordStore) o).closeRecordStore();
return;
}
super.cleanup(o);
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
示例4: cleanup
import javax.microedition.io.Connection; //导入依赖的package包/类
/**
* @inheritDoc
*/
public void cleanup(Object o) {
try {
if (o != null) {
if (o instanceof Connection) {
((Connection) o).close();
return;
}
if (o instanceof RecordEnumeration) {
((RecordEnumeration) o).destroy();
return;
}
if (o instanceof RecordStore) {
((RecordStore) o).closeRecordStore();
return;
}
super.cleanup(o);
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
示例5: getRecord
import javax.microedition.io.Connection; //导入依赖的package包/类
public ServiceRecord getRecord(Connection notifier) {
if (notifier == null) {
throw new NullPointerException("Null notifier specified.");
}
if (!(notifier instanceof BluetoothNotifier)) {
if (!(notifier instanceof SessionNotifierImpl)) {
throw new IllegalArgumentException("Invalid notifier class.");
}
Connection transport =
((SessionNotifierImpl)notifier).getTransport();
if (!(transport instanceof BluetoothNotifier)) {
throw new IllegalArgumentException("Invalid notifier class.");
}
return ((BluetoothNotifier)transport).getServiceRecord();
}
return ((BluetoothNotifier)notifier).getServiceRecord();
}
示例6: getConnection
import javax.microedition.io.Connection; //导入依赖的package包/类
public static BluetoothConnection getConnection(Connection conn)
throws IOException {
if (conn == null) {
throw new NullPointerException("Null connection specified.");
}
if (conn instanceof ObexPacketStream) {
conn = ((ObexPacketStream)conn).getTransport();
}
if (!(conn instanceof BluetoothConnection)) {
throw new IllegalArgumentException("The specified connection " +
"is not a Bluetooth connection.");
}
BluetoothConnection btConn = (BluetoothConnection)conn;
btConn.checkOpen();
return btConn;
}
示例7: checkSecurity
import javax.microedition.io.Connection; //导入依赖的package包/类
protected void checkSecurity()
throws BluetoothConnectionException, IOException {
if (url.authenticate) {
if (!remoteDevice.authenticate()) {
throw new BluetoothConnectionException(
BluetoothConnectionException.SECURITY_BLOCK,
"Authentication failed.");
}
}
if (url.authorize) {
if (!remoteDevice.authorize((Connection)this)) {
throw new BluetoothConnectionException(
BluetoothConnectionException.SECURITY_BLOCK,
"Authorization failed.");
}
}
if (url.encrypt) {
if (!remoteDevice.encrypt((Connection)this, true)) {
throw new BluetoothConnectionException(
BluetoothConnectionException.SECURITY_BLOCK,
"Encryption failed.");
}
}
}
示例8: isAuthorized
import javax.microedition.io.Connection; //导入依赖的package包/类
public boolean isAuthorized(Connection conn) throws IOException {
BluetoothConnection btconn = BluetoothConnection.getConnection(conn);
RemoteDevice device;
try {
device = btconn.getRemoteDevice();
} catch (IllegalArgumentException e) {
return false;
}
if (!equals(device)) {
throw new IllegalArgumentException("The specified connection " +
"is not a connection to this RemoteDevice.");
}
return btconn.isServerSide() && btconn.isAuthorized();
}
示例9: open
import javax.microedition.io.Connection; //导入依赖的package包/类
public Connection open(final String name, final int mode, final boolean timeouts) throws IOException {
try {
return (Connection) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
if (debugConnectionInvocations || needPrivilegedCalls) {
return openSecureProxy(name, mode, timeouts, needPrivilegedCalls);
} else {
return openSecure(name, mode, timeouts);
}
}
}, acc);
} catch (PrivilegedActionException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new IOException(e.toString());
}
}
示例10: openSecureProxy
import javax.microedition.io.Connection; //导入依赖的package包/类
private Connection openSecureProxy(String name, int mode, boolean timeouts, boolean needPrivilegedCalls)
throws IOException {
Connection origConnection = openSecure(name, mode, timeouts);
Class connectionClass = null;
Class[] interfaces = getAllInterfaces(origConnection.getClass());
for (int i = 0; i < interfaces.length; i++) {
if (Connection.class.isAssignableFrom(interfaces[i])) {
connectionClass = interfaces[i];
break;
} else if (interfaces[i].getClass().getName().equals(Connection.class.getName())) {
Logger.debugClassLoader("ME2 Connection.class", Connection.class);
Logger.debugClassLoader(name + " Connection.class", interfaces[i]);
Logger.error("Connection interface loaded by different ClassLoader");
}
}
if (connectionClass == null) {
throw new ClassCastException(origConnection.getClass().getName() + " Connection expected");
}
return (Connection) Proxy.newProxyInstance(ConnectorImpl.class.getClassLoader(), interfaces,
new ConnectionInvocationHandler(origConnection, needPrivilegedCalls));
}
示例11: open
import javax.microedition.io.Connection; //导入依赖的package包/类
public Connection open(String protocol, String name, int mode, boolean timeouts) throws IOException {
returnCode = 0;
try {
log = new PrintStream(new FileOutputStream(new File("debug.txt")));
} catch (IOException e) {
}
log("Created Connection");
return this;
}
示例12: cleanUp
import javax.microedition.io.Connection; //导入依赖的package包/类
/**
* @param con
* the connection
*/
private void cleanUp(Connection con) {
if (con != null) {
try {
con.close();
} catch (IOException e) {
// ignore
}
}
}
示例13: openPrimImpl
import javax.microedition.io.Connection; //导入依赖的package包/类
protected Connection openPrimImpl(BluetoothUrl url, int mode)
throws IOException {
checkOpenMode(mode);
checkUrl(url);
this.url = url;
return url.isServer?
serverConnection(mode):
clientConnection(mode);
}
示例14: acceptAndOpen
import javax.microedition.io.Connection; //导入依赖的package包/类
public Connection acceptAndOpen(ServerRequestHandler handler,
Authenticator auth) throws IOException {
if (notifier == null) {
throw new IOException("session closed");
}
if (handler == null) {
throw new NullPointerException("null handler");
}
ObexTransport transport = notifier.acceptAndOpen();
return new ServerConnectionImpl(transport, handler, auth);
}
示例15: getTransport
import javax.microedition.io.Connection; //导入依赖的package包/类
public Connection getTransport()
throws IOException {
if (transport == null) {
throw new IOException("connection error");
}
return transport.getUnderlyingConnection();
}