protected void writeToStream(final InputStream in, final OutputStream out) throws IOException { final byte[] b = new byte[BUFFER_SIZE]; int count = 0; amountWritten = 0; while ((count = in.read(b)) > 0 && !getStatus().equals(Status.cancelled)) { out.write(b, 0, count); amountWritten += count; } // the connection was likely terminated abruptly if these are not equal if (!getStatus().equals(Status.cancelled) && getError() == Error.none && amountWritten != fileSize) { setStatus(Status.error); this.error = Error.connection; } }
if (getStatus().equals(Status.in_progress)) { setStatus(Status.complete);
protected void writeToStream(final InputStream in, final OutputStream out) throws XMPPException { final byte[] b = new byte[BUFFER_SIZE]; int count = 0; amountWritten = 0; do { // write to the output stream try { out.write(b, 0, count); } catch (IOException e) { throw new XMPPException("error writing to output stream", e); } amountWritten += count; // read more bytes from the input stream try { count = in.read(b); } catch (IOException e) { throw new XMPPException("error reading from input stream", e); } } while (count != -1 && !getStatus().equals(Status.cancelled)); // the connection was likely terminated abrubtly if these are not equal if (!getStatus().equals(Status.cancelled) && getError() == Error.none && amountWritten != fileSize) { setStatus(Status.error); this.error = Error.connection; } }
if (getStatus().equals(Status.in_progress)) { setStatus(Status.complete);
if (getStatus().equals(Status.in_progress)) { setStatus(Status.complete);
if (getStatus().equals(Status.in_progress)) { setStatus(Status.complete);
protected void writeToStream(final InputStream in, final OutputStream out) throws XMPPException { final byte[] b = new byte[BUFFER_SIZE]; int count = 0; amountWritten = 0; do { // write to the output stream try { out.write(b, 0, count); } catch (IOException e) { throw new XMPPException("error writing to output stream", e); } amountWritten += count; // read more bytes from the input stream try { count = in.read(b); } catch (IOException e) { throw new XMPPException("error reading from input stream", e); } } while (count != -1 && !getStatus().equals(Status.cancelled)); // the connection was likely terminated abrubtly if these are not equal if (!getStatus().equals(Status.cancelled) && getError() == Error.none && amountWritten != fileSize) { setStatus(Status.error); this.error = Error.connection; } }
protected void writeToStream(final InputStream in, final OutputStream out) throws XMPPException { final byte[] b = new byte[BUFFER_SIZE]; int count = 0; amountWritten = 0; do { // write to the output stream try { out.write(b, 0, count); } catch (IOException e) { throw new XMPPException("error writing to output stream", e); } amountWritten += count; // read more bytes from the input stream try { count = in.read(b); } catch (IOException e) { throw new XMPPException("error reading from input stream", e); } } while (count != -1 && !getStatus().equals(Status.cancelled)); // the connection was likely terminated abrubtly if these are not equal if (!getStatus().equals(Status.cancelled) && getError() == Error.none && amountWritten != fileSize) { setStatus(Status.error); this.error = Error.connection; } }
private void waitForTransfer(FileTransfer transfer, long timeout) throws SmackException, InterruptedException { double prevProgress = 0; long counter = 0; Thread.sleep(timeout / WAITING_CYCLES / 10); // optimistic while (!transfer.isDone()) { if (transfer.getStatus().equals(FileTransfer.Status.error)) { throw new SmackException(transfer.getError().toString(), transfer.getException()); } else { log.debug("Status: " + transfer.getStatus() + " " + transfer.getProgress()); } if (transfer.getProgress() <= prevProgress) { if (counter >= WAITING_CYCLES) { throw new SmackException("File transfer timed out"); } counter++; Thread.sleep(timeout / WAITING_CYCLES); } else { counter = 0; prevProgress = transfer.getProgress(); } } if (transfer.getProgress() == 0) { throw new SmackException("No data transferred"); } }
/** * Returns the output stream connected to the peer to transfer the file. It * is only available after it has been successfully negotiated by the * {@link StreamNegotiator}. * * @return Returns the output stream connected to the peer to transfer the * file. */ protected OutputStream getOutputStream() { if (getStatus().equals(Status.negotiated)) { return outputStream; } else { return null; } }
/** * Returns the output stream connected to the peer to transfer the file. It * is only available after it has been successfully negotiated by the * {@link StreamNegotiator}. * * @return Returns the output stream connected to the peer to transfer the * file. */ protected OutputStream getOutputStream() { if (getStatus().equals(FileTransfer.Status.negotiated)) { return outputStream; } else { return null; } }
/** * Returns the output stream connected to the peer to transfer the file. It * is only available after it has been succesfully negotiated by the * {@link StreamNegotiator}. * * @return Returns the output stream connected to the peer to transfer the * file. */ protected OutputStream getOutputStream() { if (getStatus().equals(FileTransfer.Status.negotiated)) { return outputStream; } else { return null; } }
/** * Returns the output stream connected to the peer to transfer the file. It * is only available after it has been successfully negotiated by the * {@link StreamNegotiator}. * * @return Returns the output stream connected to the peer to transfer the * file. */ protected OutputStream getOutputStream() { if (getStatus().equals(FileTransfer.Status.negotiated)) { return outputStream; } else { return null; } }