当前位置: 首页>>代码示例>>Java>>正文


Java Connection类代码示例

本文整理汇总了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;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:23,代码来源:Protocol.java

示例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;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:37,代码来源:Protocol.java

示例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();
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:25,代码来源:GameCanvasImplementation.java

示例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();
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:25,代码来源:BlackBerryImplementation.java

示例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();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:18,代码来源:LocalDeviceImpl.java

示例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;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:20,代码来源:BluetoothConnection.java

示例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.");
        }
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:25,代码来源:BluetoothConnection.java

示例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();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:17,代码来源:RemoteDevice.java

示例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());
	}
}
 
开发者ID:BombusMod,项目名称:BombusMod,代码行数:19,代码来源:ConnectorImpl.java

示例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));
}
 
开发者ID:BombusMod,项目名称:BombusMod,代码行数:22,代码来源:ConnectorImpl.java

示例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;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:10,代码来源:Protocol.java

示例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
        }
    }

}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:15,代码来源:BTTransportMethod.java

示例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);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:11,代码来源:BluetoothProtocol.java

示例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);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:12,代码来源:SessionNotifierImpl.java

示例15: getTransport

import javax.microedition.io.Connection; //导入依赖的package包/类
public Connection getTransport()
    throws IOException {
    if (transport == null) {
        throw new IOException("connection error");
    }
    return transport.getUnderlyingConnection();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:8,代码来源:ObexPacketStream.java


注:本文中的javax.microedition.io.Connection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。