本文整理汇总了Java中javax.microedition.io.StreamConnection类的典型用法代码示例。如果您正苦于以下问题:Java StreamConnection类的具体用法?Java StreamConnection怎么用?Java StreamConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamConnection类属于javax.microedition.io包,在下文中一共展示了StreamConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createKeyAgreementConnection
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
@Override
public DuplexTransportConnection createKeyAgreementConnection(
byte[] commitment, BdfList descriptor, long timeout) {
if (!isRunning()) return null;
String address;
try {
address = parseAddress(descriptor);
} catch (FormatException e) {
LOG.info("Invalid address in key agreement descriptor");
return null;
}
// No truncation necessary because COMMIT_LENGTH = 16
String uuid = UUID.nameUUIDFromBytes(commitment).toString();
if (LOG.isLoggable(INFO))
LOG.info("Connecting to key agreement UUID " + uuid);
String url = makeUrl(address, uuid);
StreamConnection s = connect(url);
if (s == null) return null;
return new BluetoothTransportConnection(this, s);
}
示例2: call
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
@Override
public StreamConnection call() throws Exception {
// Repeat discovery until we connect or get interrupted
DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
while (true) {
if (!discoverySemaphore.tryAcquire())
throw new Exception("Discovery is already in progress");
try {
InvitationListener listener =
new InvitationListener(discoveryAgent, uuid);
discoveryAgent.startInquiry(GIAC, listener);
String url = listener.waitForUrl();
if (url != null) {
StreamConnection s = connect(url);
if (s != null) {
LOG.info("Outgoing connection");
return s;
}
}
} finally {
discoverySemaphore.release();
}
}
}
示例3: servicesDiscovered
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
if(servRecord!=null && servRecord.length>0){
connectionURL = servRecord[0].getConnectionURL(0,false);
}
isOK = true;
try {
StreamConnection streamConnection = (StreamConnection) Connector.open(connectionURL);
// send string
OutputStream outStream = streamConnection.openOutputStream();
out = new PrintWriter(new OutputStreamWriter(outStream));
// read response
InputStream inStream = streamConnection.openInputStream();
in = new BufferedReader(new InputStreamReader(inStream));
if(onConnectionSuccessful != null) onConnectionSuccessful.actionPerformed(new ActionEvent(this,ActionEvent.RESERVED_ID_MAX+1,""));
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: main
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
public static void main(String[] args) {
// Default to indicate error
int returnCode = -1;
try {
StreamConnection connection = (StreamConnection) Connector.open("uei:");
DataOutputStream out = connection.openDataOutputStream();
out.writeInt(args.length);
for (int i=0; i < args.length; i++) {
out.writeUTF(args[i]);
}
out.close();
InputStream in = connection.openInputStream();
returnCode = in.read();
in.close();
} catch (Throwable t) {
t.printStackTrace();
} finally {
System.exit(returnCode);
}
}
示例5: disconnect
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
/**
* Disconnect from the underlying socket transport.
* Closes the low level socket connection and the input and
* output streams used by the socket.
* <p>
* Warning: A subclass that implements connect, should also implement this
* method without calling this method.
*
* @param connection connection return from {@link #connect()}
* @param inputStream input stream opened from <code>connection</code>
* @param outputStream output stream opened from <code>connection</code>
* @exception IOException if an I/O error occurs while
* the connection is terminated.
* @exception IOException is thrown if the connection or
* associated streams cannot be closed
*/
protected void disconnect(StreamConnection connection,
InputStream inputStream, OutputStream outputStream)
throws IOException {
try {
if (connection != null) {
connection.close();
}
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
}
示例6: onMessage
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
public static void onMessage(final PushInputStream stream, final StreamConnection sc) {
if(pushCallback != null) {
new Thread() {
public void run() {
try {
final byte[] buffer = Util.readInputStream(stream);
try {
stream.accept();
Util.cleanup(stream);
sc.close();
} catch(Throwable t) {}
updateIndicator(unreadCount + 1);
Display.getInstance().callSerially(new Runnable() {
public void run() {
pushCallback.push(new String(buffer));
}
});
} catch(IOException err) {
err.printStackTrace();
}
}
}.start();
}
}
示例7: NodeConnection
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
/**
*
* Constructor.
* This constructor is called from the constructor in class Node.
*
* @param connection The connection to the node
* @param node The node that owns this NodeConnection
*/
public NodeConnection(StreamConnection connection, Node node){
// Fetches a instance of the Log
log = Log.getInstance();
// Sets the connection to connect to and fetches an instance of the currentNetwork
this.connection = connection;
this.node = node;
currentNetwork = Network.getInstance();
// Creates the sendQue
sendQueue = new Vector();
// The Input- and OutputStreams shall not do anything before the node is connected
// These values are toggled from ConnectionListener.run() and NodeConnection.sendDataPackage()
openInputStream = false;
openOutputStream = false;
// Starts a thread that processes the sendQue
outputThread = new OutputThread();
outputThread.setPriority(Thread.MAX_PRIORITY);
outputThread.start();
// Starts a thread constantly listening for incoming datapackages
inputThread = new InputThread();
inputThread.setPriority(Thread.MAX_PRIORITY);
inputThread.start();
}
示例8: run
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
public void run() {
try {
StreamConnectionNotifier server = (StreamConnectionNotifier) Connector.open("socket://:" + port);
Client currentClient = null;
while (true) {
StreamConnection connection = server.acceptAndOpen();
System.out.println("Client Connected.");
if (currentClient != null) {
currentClient.kill();
}
currentClient = new Client(connection);
currentClient.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: testMultipleSendsReceivesOnSameSocket
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
void testMultipleSendsReceivesOnSameSocket() throws IOException {
StreamConnection t = (StreamConnection)Connector.open(SOCKET_URL);
try {
SSLStreamConnection s =
new SSLStreamConnection(HOST, PORT, t.openInputStream(), t.openOutputStream(), KEY_STORE);
OutputStream os = s.openOutputStream();
InputStream is = s.openInputStream();
for (int i = 0; i < 100; i++) {
String message = "Message n." + i;
send(os, message);
th.check(receive(is), message);
}
os.close();
is.close();
s.close();
} finally {
t.close();
}
}
示例10: openFile
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException {
String url = "file:///" + filename;
int mode = readMode? Connector.READ: Connector.READ_WRITE;
StreamConnection conn = (StreamConnection) Connector.open( url, mode );
File f = readMode?
new FileImpl(conn, conn.openInputStream(), null):
new FileImpl(conn, conn.openInputStream(), conn.openOutputStream());
/*
if ( appendMode ) {
f.seek("end",0);
} else {
if ( ! readMode )
conn.truncate(0);
}
*/
return f;
}
示例11: acceptContactConnections
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
private void acceptContactConnections(StreamConnectionNotifier ss) {
while (true) {
StreamConnection s;
try {
s = ss.acceptAndOpen();
} catch (IOException e) {
// This is expected when the socket is closed
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
return;
}
backoff.reset();
callback.incomingConnectionCreated(wrapSocket(s));
if (!running) return;
}
}
示例12: poll
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
@Override
public void poll(final Collection<ContactId> connected) {
if (!running) return;
backoff.increment();
// Try to connect to known devices in parallel
Map<ContactId, TransportProperties> remote =
callback.getRemoteProperties();
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
final ContactId c = e.getKey();
if (connected.contains(c)) continue;
final String address = e.getValue().get(PROP_ADDRESS);
if (StringUtils.isNullOrEmpty(address)) continue;
final String uuid = e.getValue().get(PROP_UUID);
if (StringUtils.isNullOrEmpty(uuid)) continue;
ioExecutor.execute(new Runnable() {
@Override
public void run() {
if (!running) return;
StreamConnection s = connect(makeUrl(address, uuid));
if (s != null) {
backoff.reset();
callback.outgoingConnectionCreated(c, wrapSocket(s));
}
}
});
}
}
示例13: connect
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
private StreamConnection connect(String url) {
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + url);
try {
StreamConnection s = (StreamConnection) Connector.open(url);
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + url);
return s;
} catch (IOException e) {
if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + url);
return null;
}
}
示例14: createConnection
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
@Override
public DuplexTransportConnection createConnection(ContactId c) {
if (!running) return null;
TransportProperties p = callback.getRemoteProperties().get(c);
if (p == null) return null;
String address = p.get(PROP_ADDRESS);
if (StringUtils.isNullOrEmpty(address)) return null;
String uuid = p.get(PROP_UUID);
if (StringUtils.isNullOrEmpty(uuid)) return null;
String url = makeUrl(address, uuid);
StreamConnection s = connect(url);
if (s == null) return null;
return new BluetoothTransportConnection(this, s);
}
示例15: listen
import javax.microedition.io.StreamConnection; //导入依赖的package包/类
@Override
public Callable<KeyAgreementConnection> listen() {
return new Callable<KeyAgreementConnection>() {
@Override
public KeyAgreementConnection call() throws Exception {
StreamConnection s = ss.acceptAndOpen();
if (LOG.isLoggable(INFO))
LOG.info(ID.getString() + ": Incoming connection");
return new KeyAgreementConnection(
new BluetoothTransportConnection(
BluetoothPlugin.this, s), ID);
}
};
}