xmpp openfire android客户端迷茫中!求助 OutgoingFileTransfe

//发送文件-----------------------------------------------------
        private  void sendFile(String user_to,File file) throws Exception{
                //1. 首先通过 Connection对象得到文件传输管理类 FileTansferManager 
                //2. 实例化向外文件传输类     OutgoingFileTransfer
                //3. 通OutgoingFileTransfer的sendFile() 方法 发送文件
                //4. 注意的事项:   实例化 向外文件传输类的时候 需要输入的参数类型 为 jid+客户端名称以及版本号  shen@locahost/Spark 2.6.3
                
                OutgoingFileTransfer transfer = 
                        fileTransferManager.createOutgoingFileTransfer(user_to+"/Spark 2.6.3"); 
                System.out.println(user_to);
                transfer.sendFile(file,"demo");
                while(!transfer.isDone()){  
                    if(transfer.getStatus().equals(Status.error)){  
                        System.out.println("ERROR!!! " + transfer.getError());  
                    }else{  
                         System.out.println(transfer.getStatus()+"进度 "+transfer.getProgress());  
                    }  
                     Thread.sleep(1000);   
                }  
            }
      
             


07-11 11:59:49.470: E/AndroidRuntime(1024): FATAL EXCEPTION: File Transfer jsi_5902858178163684659
07-11 11:59:49.470: E/AndroidRuntime(1024): java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to org.jivesoftware.smackx.packet.StreamInitiation
07-11 11:59:49.470: E/AndroidRuntime(1024): 	
at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.negotiateOutgoingTransfer(FileTransferNegotiator.java:423)
07-11 11:59:49.470: E/AndroidRuntime(1024): 	
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.negotiateStream(OutgoingFileTransfer.java:359)
07-11 11:59:49.470: E/AndroidRuntime(1024): 	
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.access$100(OutgoingFileTransfer.java:35)
07-11 11:59:49.470: E/AndroidRuntime(1024): 	
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer$2.run(OutgoingFileTransfer.java:214)
07-11 11:59:49.470: E/AndroidRuntime(1024): 	at java.lang.Thread.run(Thread.java:856)

以为是耗时操作开要线程   我看了源码

/**
     * This method handles the stream negotiation process and transmits the file
     * to the remote user. It returns immediately and the progress of the file
     * transfer can be monitored through several methods:
     *
     * <UL>
     * <LI>{@link FileTransfer#getStatus()}
     * <LI>{@link FileTransfer#getProgress()}
     * <LI>{@link FileTransfer#isDone()}
     * </UL>
     *
     * @param file the file to transfer to the remote entity.
     * @param description a description for the file to transfer.
     * @throws XMPPException
     *             If there is an error during the negotiation process or the
     *             sending of the file.
     */
    public synchronized void sendFile(final File file, final String description)
            throws XMPPException {
        checkTransferThread();
        if (file == null || !file.exists() || !file.canRead()) {
            throw new IllegalArgumentException("Could not read file");
        } else {
            setFileInfo(file.getAbsolutePath(), file.getName(), file.length());
        }

        transferThread = new Thread(new Runnable() {
            public void run() {
                try {
                    outputStream = negotiateStream(file.getName(), file
                            .length(), description);
                } catch (XMPPException e) {
                    handleXMPPException(e);
                    return;
                }
                if (outputStream == null) {
                    return;
                }

                if (!updateStatus(Status.negotiated, Status.in_progress)) {
                    return;
                }

                InputStream inputStream = null;
                try {
                    inputStream = new FileInputStream(file);
                    writeToStream(inputStream, outputStream);
                } catch (FileNotFoundException e) {
                    setStatus(FileTransfer.Status.error);
                    setError(Error.bad_file);
                    setException(e);
                } catch (XMPPException e) {
                    setStatus(FileTransfer.Status.error);
                    setException(e);
                } finally {
                    try {
                        if (inputStream != null) {
                            inputStream.close();
                        }

                        outputStream.flush();
                        outputStream.close();
                    } catch (IOException e) {
                        /* Do Nothing */
                    }
                }
                updateStatus(Status.in_progress, FileTransfer.Status.complete);
                }

        }, "File Transfer " + streamID);
        transferThread.start();
    }

我调他中午到现在还没吃饭,虽然还是学生,我不想让家人失望。

你可能感兴趣的:(XMPP)