public void run() { try { if (_data != null) { sendData(_data); } else { sendData(_fdata); } } catch (SerialConnectionException e) { // display error in gui } finally { _results.threadDone(EchoTestResultsDisplay.SEND_DONE, 0); } }
private void sendData(FileInputStream data) throws SerialConnectionException { int tosend = 0; byte[] databuff = new byte[_chunkSize]; _sent = 0; try { tosend = data.read(databuff); while (tosend != -1) { if (!_keepRunning) return; _os.write(databuff, 0, tosend); _savedStream.write(databuff, 0, tosend); _sent += tosend; // update GUI _results.updateBytesSent(_sent); tosend = data.read(databuff); } } catch (IOException e) { throw new SerialConnectionException("Error writing to i/o streams"); } }
private void sendData(byte[] data) throws SerialConnectionException { try { int size = data.length; int sent = 0; _sent = 0; long starttime = System.currentTimeMillis(); while (sent < size) { int tosend; if (!_keepRunning) return; if ((sent + _chunkSize) > size) { tosend = size - sent; } else { tosend = _chunkSize; } _os.write(data, sent, tosend); sent += tosend; _sent = sent; // update GUI _results.updateBytesSent(sent); } } catch (IOException e) { throw new SerialConnectionException("Error writing to i/o streams"); } }