setStatus(FileTransfer.Status.error); setException(e); return; try { outputStream = new FileOutputStream(file); setStatus(Status.in_progress); writeToStream(inputStream, outputStream); setStatus(Status.error); setError(Error.bad_file); setException(e); setStatus(Status.error); setError(Error.stream); setException(e); if (getStatus().equals(Status.in_progress)) { setStatus(Status.complete);
/** * When the file transfer request is acceptable, this method should be * invoked. It will create an IncomingFileTransfer which allows the * transmission of the file to proceed. * * @param request * The remote request that is being accepted. * @return The IncomingFileTransfer which manages the download of the file * from the transfer initiator. */ protected IncomingFileTransfer createIncomingFileTransfer( FileTransferRequest request) { if (request == null) { throw new NullPointerException("ReceiveRequest cannot be null"); } IncomingFileTransfer transfer = new IncomingFileTransfer(request, fileTransferNegotiator); transfer.setFileInfo(request.getFileName(), request.getFileSize()); return transfer; }
/** * Negotiates the stream method to transfer the file over and then returns * the negotiated stream. * * @return The negotiated InputStream from which to read the data. * @throws SmackException * @throws XMPPErrorException If there is an error in the negotiation process an exception * is thrown. * @throws InterruptedException */ public InputStream receiveFile() throws SmackException, XMPPErrorException, InterruptedException { if (inputStream != null) { throw new IllegalStateException("Transfer already negotiated!"); } try { inputStream = negotiateStream(); } catch (XMPPErrorException e) { setException(e); throw e; } return inputStream; }
private void handleXMPPException(XMPPException e) { setStatus(FileTransfer.Status.error); setException(e); }
IncomingFileTransfer transfer = request.accept(); File mf = Environment.getExternalStorageDirectory(); final File file = new File(mf.getAbsoluteFile() +"/"+ transfer.getFileName()); try{ transfer.recieveFile(file); while(!transfer.isDone()){ try{ Thread.sleep(1000); Log.e("", e.getMessage()); if(transfer.getStatus().equals(Status.error)) { Log.e("ERROR!!! ", transfer.getError() + ""); if(transfer.getException() != null) { transfer.getException().printStackTrace();
@Override public void cancel() { setStatus(Status.cancelled); }
private void updateonFinished(final FileTransferRequest request, final File downloadedFile) { if (transfer.getAmountWritten() >= request.getFileSize()) { transferDone(request, transfer); if (transfer.getStatus() == FileTransfer.Status.error) { if (transfer.getException() != null) { Log.error("There was an error during file transfer.", transfer.getException()); else if (transfer.getStatus() == FileTransfer.Status.refused) { transferMessage = Res.getString("message.transfer.refused"); else if (transfer.getStatus() == FileTransfer.Status.cancelled || transfer.getAmountWritten() < request.getFileSize()) { transferMessage = Res.getString("message.transfer.cancelled"); else if(transfer.getAmountWritten() >= request.getFileSize()) transferMessage = Res.getString("message.transfer.complete", transfer.getFileName());
@Override public void run() { if (transfer.getAmountWritten() >= request.getFileSize() || transfer.getStatus() == FileTransfer.Status.error || transfer.getStatus() == FileTransfer.Status.refused || transfer.getStatus() == FileTransfer.Status.cancelled || transfer.getStatus() == FileTransfer.Status.complete) { this.cancel(); timer.cancel(); _endtime = System.currentTimeMillis(); updateonFinished(request, downloadedFile); }else { // 100 % = Filesize // x % = Currentsize long p = (transfer.getAmountWritten() * 100 / transfer.getFileSize() ); progressBar.setValue(Math.round(p)); } } };
private void handleXMPPException(XMPPException e) { setStatus(Status.error); setException(e); }
private InputStream negotiateStream() throws SmackException, XMPPErrorException, InterruptedException { setStatus(Status.negotiating_transfer); final StreamNegotiator streamNegotiator = negotiator .selectStreamNegotiator(receiveRequest); setStatus(Status.negotiating_stream); FutureTask<InputStream> streamNegotiatorTask = new FutureTask<>( new Callable<InputStream>() { streamNegotiatorTask.cancel(true); setStatus(Status.negotiated); return inputStream;
@Override public void run() { if (transfer.getAmountWritten() >= request.getFileSize() || transfer.getStatus() == FileTransfer.Status.error || transfer.getStatus() == FileTransfer.Status.refused || transfer.getStatus() == FileTransfer.Status.cancelled || transfer.getStatus() == FileTransfer.Status.complete) bytesnow = transfer.getAmountWritten(); bytesRead = transfer.getAmountWritten(); if (bytesRead == -1) { bytesRead = 0; FileTransfer.Status status = transfer.getStatus(); if (status == FileTransfer.Status.in_progress) String est = TransferUtils.calculateEstimate(bytesnow, transfer.getFileSize(), _starttime, System.currentTimeMillis()); progressLabel.setText(Res.getString("message.transfer.progressbar.text.received", text, speed, est));
try { outputStream = new FileOutputStream(file); setStatus(Status.IN_PROGRESS); writeToStream(inputStream, outputStream); setStatus(FileTransfer.Status.ERROR); setError(Error.STREAM); setException(e); setStatus(FileTransfer.Status.ERROR); setError(Error.BAD_FILE); setException(e); if (getStatus().equals(Status.IN_PROGRESS)) setStatus(Status.COMPLETE); try { if (inputStream != null) {
/** * When the file transfer request is acceptable, this method should be * invoked. It will create an IncomingFileTransfer which allows the * transmission of the file to procede. * * @param request * The remote request that is being accepted. * @return The IncomingFileTransfer which manages the download of the file * from the transfer initiator. */ protected IncomingFileTransfer createIncomingFileTransfer( FileTransferRequest request) { if (request == null) { throw new NullPointerException("RecieveRequest cannot be null"); } IncomingFileTransfer transfer = new IncomingFileTransfer(request, fileTransferNegotiator); transfer.setFileInfo(request.getFileName(), request.getFileSize()); return transfer; }
/** * Negotiates the stream method to transfer the file over and then returns * the negotiated stream. * * @return The negotiated InputStream from which to read the data. * @throws XMPPException If there is an error in the negotiation process an exception * is thrown. */ public InputStream recieveFile() throws XMPPException { if (inputStream != null) { throw new IllegalStateException("Transfer already negotiated!"); } try { inputStream = negotiateStream(); } catch (XMPPException e) { setException(e); throw e; } return inputStream; }
private void handleXMPPException(XMPPException e) { setStatus(FileTransfer.Status.ERROR); setException(e); }
public void cancel() { setStatus(Status.CANCLED); }
try { outputStream = new FileOutputStream(file); setStatus(Status.in_progress); writeToStream(inputStream, outputStream); setStatus(Status.error); setError(Error.stream); setException(e); setStatus(Status.error); setError(Error.bad_file); setException(e); if (getStatus().equals(Status.in_progress)) { setStatus(Status.complete);
/** * When the file transfer request is acceptable, this method should be * invoked. It will create an IncomingFileTransfer which allows the * transmission of the file to procede. * * @param request * The remote request that is being accepted. * @return The IncomingFileTransfer which manages the download of the file * from the transfer initiator. */ protected IncomingFileTransfer createIncomingFileTransfer( FileTransferRequest request) { if (request == null) { throw new NullPointerException("RecieveRequest cannot be null"); } IncomingFileTransfer transfer = new IncomingFileTransfer(request, fileTransferNegotiator); transfer.setFileInfo(request.getFileName(), request.getFileSize()); return transfer; }
/** * Negotiates the stream method to transfer the file over and then returns * the negotiated stream. * * @return The negotiated InputStream from which to read the data. * @throws XMPPException If there is an error in the negotiation process an exception * is thrown. */ public InputStream recieveFile() throws XMPPException { if (inputStream != null) { throw new IllegalStateException("Transfer already negotiated!"); } try { inputStream = negotiateStream(); } catch (XMPPException e) { setException(e); throw e; } return inputStream; }
private void handleXMPPException(XMPPException e) { setStatus(FileTransfer.Status.error); setException(e); }