/** * {@inheritDoc} */ @Override public void close() throws IOException { if ( this.connection != null ) { this.connection.close(); this.connection = null; } }
public void start(IchtyometerClient client) throws IOException { Preconditions.checkNotNull(client, "client can not be null"); Preconditions.checkState(client.isOpen(), "client must be opened"); this.client = client; // create a service executor this.service = Executors.newSingleThreadScheduledExecutor(); // get bluetooth connection this.connection = client.openConnection(); // get input stream (to read) this.dataInputStream = connection.openDataInputStream(); // get output stream (to write) this.dataOutputStream = connection.openDataOutputStream(); // engine is ready if (log.isDebugEnabled()) { log.debug("Ready to read remote device..."); } }
StreamConnection conn = (StreamConnection)Connector.open(url); DataOutputStream output= new DataOutputStream(conn.openOutputStream()); DataInputStream input = new DataInputStream(conn.openInputStream());
inputStream = connection.openDataInputStream(); outputStream = connection.openDataOutputStream(); connection.close();
.getRemoteDevice(connection); BluetoothStreamReaderThreadImpl bluetoothConnection = new BluetoothStreamReaderThreadImpl( serverListener, connection.openDataInputStream(), remoteDevice); BluetoothConnectionHandler.UTIL.addConnection(bluetoothConnection); connection.close();
/** * {@inheritDoc} */ @Override public InputStream openInputStream( final String aName ) throws IOException { return openStreamConnection( aName ).openInputStream(); }
public void start(IchtyometerClient client) throws IOException { Preconditions.checkNotNull(client, "client can not be null"); Preconditions.checkState(client.isOpen(), "client must be opened"); this.client = client; // get connection StreamConnection connection = client.openConnection(); // get input stream DataInputStream dataInputStream = connection.openDataInputStream(); // create the reader runnable readingRunnable = new ReadingRunnable(dataInputStream); // start the reader thread new Thread(readingRunnable).start(); if (log.isDebugEnabled()) { log.debug("Ready to read remote device..."); } }
/** * {@inheritDoc} */ @Override public OutputStream openOutputStream( final String aName ) throws IOException { return openStreamConnection( aName ).openOutputStream(); }
/** * {@inheritDoc} */ @Override public Void call() throws Exception { LOG.info( "Prematurely finishing RLE-enabled capture ..." ); final DataOutputStream outputStream = this.connection.openDataOutputStream(); // Write a single command to stop RLE from doing its job... outputStream.writeByte( CMD_RLE_FINISH_NOW ); // Make sure nothing keeps lingering in the streams' buffer... outputStream.flush(); return null; } }
ServerSocketConnection listener = (ServerSocketConnection)Connector.open("socket://:1235"); System.out.println("Waiting for connection..."); StreamConnection server = listener.acceptAndOpen(); InputStream is = server.openInputStream(); //Now comes the fake BufferedReader equivalent part int ch = 0; StringBuffer sb = new StringBuffer(); while ((ch = is.read()) != -1){ sb.append((char)ch); if(sb.charAt(sb.length()-1) == 13 ) { //Carriage return was received or ENTER was pressed break; //Exit loop and print input } }
// code at sender side StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open( url ); //System.out.println("opened"); StreamConnection con = (StreamConnection) service.acceptAndOpen(); OutputStream outputStream = con.openOutputStream(); // file to send Scanner in = new Scanner(inFile); //just count lines String s=null; int countLines=0; while(in.hasNext()) { s=in.nextLine(); countLines++; } //send num of lines outputStream.write(Integer.toHexString(countLines).getBytes()); try{Thread.sleep(100);} catch(InterruptedException e){} //send lines in = new Scanner(inFile); for(int i=0; i<countLines; i++) { s=in.nextLine()+"\n"; outputStream.write(s.getBytes()); Thread.sleep(100); }
private void connection() throws IOException{ StreamConnection connection = (StreamConnection)Connector.open("socket://127.0.0.1:6789"); in = connection.openInputStream(); } private void setupStreams() throws IOException{ PrintStream output = new PrintStream(connection.openOutputStream()); output.println("Test"); output.flush(); }
while (true) { StreamConnection sc = scn.acceptAndOpen(); final RemoteDevice rd = RemoteDevice.getRemoteDevice(sc); new Thread() { public void run() { treatConnection(rd); } }.start(); } private void treatConnection(RemoteDevice rd) { DataInputStream input = sc.openDataInputStream(); DataOutputStream output = sc.openDataOutputStream(); String inMsg = input.readUTF(); while (inMsg != null) { // not sure about this stop condition... System.out.println(inMsg + " recived at " + new Date().toString()); output.writeUTF("Hey client Sent at " + new Date().toString()); output.flush(); inMsg = input.readUTF(); } }
public void closeConnection(StreamConnection connection) throws IOException { checkIsOpened(); boolean remove = connections.remove(connection); if (!remove) { throw new IllegalArgumentException("Connection is not coming from this client, won't close it!"); } connection.close(); }
= docBuilderFactory.newDocumentBuilder(); docBuilder.isValidating(); doc = docBuilder.parse(conn.openInputStream()); doc.getDocumentElement ().normalize (); NodeList list=doc.getElementsByTagName("*");
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.io.*; import javax.microedition.io.*; StreamConnection connection = (StreamConnection) Connector.open("socket://IP:Port"); PrintStream output = new PrintStream(connection.openOutputStream()); output.println("Request"); output.flush(); InputStream in = connection.openInputStream(); int ch; String recx; while( ( ch = in.read() ) != 13 ) { recx = recx + (char)ch; } in.close(); output.close(); connection.close();
this.outputStream = new SumpCommandWriter( this.config, conn.openDataOutputStream() ); this.inputStream = new SumpResultReader( conn.openDataInputStream() );
public void close() { if (mGlassReaderThread != null) { mGlassReaderThread.interrupt(); try { mGlassReaderThread.join(10000); } catch (InterruptedException e1) { e1.printStackTrace(); } } if (mStreamConnection != null) { try { mStreamConnection.close(); mStreamConnection = null; mOutStream = null; mInStream = null; } catch (IOException e) { e.printStackTrace(); } } }
UUID serialUUID = new UUID("1101", true); String serviceURL = "btspp://localhost:" + serialUUID + ";name=Android BT Server;authorize=false;authenticate=false"; StreamConnectionNotifier connectionNotifier = (StreamConnectionNotifier) Connector .open(serviceURL); // Blocking method will wait for client to connect StreamConnection connection = connectionNotifier.acceptAndOpen(); RemoteDevice remoteDevice = RemoteDevice.getRemoteDevice(connection); InputStream btInput = connection.openInputStream(); OutputStream btOutput = connection.openOutputStream();
conn.close();