⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 streaminitiation.java

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $RCSfile$ * $Revision: 2407 $ * $Date: 2004-11-02 17:37:00 -0600 (Tue, 02 Nov 2004) $ * * Copyright 2003-2004 Jive Software. * * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.jivesoftware.smackx.packet;import org.jivesoftware.smack.packet.IQ;import org.jivesoftware.smack.util.*;import org.jivesoftware.smackx.*;import org.jivesoftware.smackx.filetransfer.*;import java.io.*;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.util.Iterator;/** *  represents information passed in <si> (stream initiation) packet * *@author     Lukasz Wiechec *@version    1.0 */public class StreamInitiation extends IQ {    private final static String NAMESPACE = "http://jabber.org/protocol/si";    private final static String PROFILE =    "http://jabber.org/protocol/si/profile/file-transfer";        private FileDetails fileDetails = null;    private Feature feature = null;    private String id = null;    private int preferred = -1;            /**     *  Creates a new StreamInitiation object and sets a random session id     */    public StreamInitiation(int type) {        this.preferred = type;        setType(IQ.Type.SET);        id = StringUtils.randomString(20);        feature = new Feature(type);    }        public StreamInitiation()    {        this(-1);    }            /**     *  Returns details about the file in the stream initiation     *     *@return    The details of the file in this stream initiation     */    public FileDetails getFileDetails() {        return fileDetails;    }            /**     *  Sets the file details of the file sent/received in this packet     *     *@param  aFile  The new file details     */    public void setFileDetails(FileDetails aFile) {        fileDetails = aFile;    }        /**     *  Returns the session id for this packet     *     *@return   The session id     */    public String getSid() {        return id;    }        /**     *  Sets the feature for this packet     *     *@param  aFeature  the new feature     */    public void setFeature(Feature aFeature) {        feature = aFeature;    }        /**     * Returns the features of this packet     *@return Feature of this packet     */    public Feature getFeature() { return feature; }        /**     *  Sets the session id for this packet     *     *@param  aID  The new session id     */    public void setSid(String aID) {        id = aID;    }            /**     *  Returns the XML representation of this packet     *     *@return    The XML representation of this packet     */    public String getChildElementXML() {        StringBuffer buf = new StringBuffer();        buf.append("<si xmlns=\"" + NAMESPACE + "\" profile=\"" + PROFILE + "\"");        if (id != null) {            buf.append(" id=\"" + id + "\"");        }        buf.append(">");        if (fileDetails != null) {            buf.append(fileDetails.getXML());        }        if (feature != null) {            buf.append(feature.getXML());        }        buf.append("</si>");        return buf.toString();    }            /**     *  helper method for creating "confirmation" <si> messages     *     *@return    StreamInitiation message of type RESULT     */    public StreamInitiation createConfirmationMessage(int type) {                // prepare a confirmation <si> message; it should have null stream id        // now we're replying, so to=from and vice versa        StreamInitiation confirmSI = new StreamInitiation();        confirmSI.setFrom(getTo());        confirmSI.setTo(getFrom());        confirmSI.setType(IQ.Type.RESULT);        confirmSI.setPacketID(getPacketID());        Feature feature = new Feature("submit");        FormField formfield = new FormField("stream-method");        formfield.setType(null);                if(this.feature.providesBytestreamOption() || type == FileTransferManager.TYPE_SOCKS5)        {            formfield.addValue("http://jabber.org/protocol/bytestreams");        }        else if(this.feature.providesIBBOption() || type == FileTransferManager.TYPE_IBB);        {            formfield.addValue("http://jabber.org/protocol/ibb");        }        feature.getDataForm().addField(formfield);        confirmSI.setFeature(feature);        confirmSI.setSid(null);                return confirmSI;    }         /**     *  helper method for creating "confirmation" <si> messages     *     *@return    StreamInitiation message of type RESULT     */    public StreamInitiation createConfirmationMessage() {        return createConfirmationMessage(-1);    }            /**     *  subclass that carry file information     */    public static class FileDetails {        private File fFile;        private String fFileName;        private long fFileSize = 0;        private String fDescription;        private String fHash;        private String fDate = DateTimeUtils.getDateTime();        private File fDestFile;                /**         *  Creates a file details based on name, description, size         *         *@param  name         The name of the file         *@param  description  Description of file         *@param  size         Size of the file         */        public FileDetails(String name, String description, long size) {            fFileSize = size;            fDescription = description;            fFileName = name;        }                        /**         *  Creates a file details object based on a <tt>File</tt> object         *         *@param  aFile  The file for which to create the details         */        public FileDetails(File aFile) {            fFile = aFile;            fFileName = aFile.getName();            fFileSize = aFile.length();            fHash = createMD5Sum();            fDestFile = new File(aFile.getName());        }                        /**         *  Creates a FileDetails object based on the location of the file         *         *@param  aFilename        The location of the file         *@throws  FileNotFoundException  if the file cannot be found         */        public FileDetails(String aFilename) throws FileNotFoundException {            fFile = new File(aFilename);            fFileName = fFile.getName();            fFileSize = fFile.length();            fHash = new String();            fDestFile = new File(aFilename);        }                        /**         *  Gets the name of the file         *         *@return    The name of the file         */        public String getFileName() {            return fFileName;        }                        /**         *  Sets the name of the file         *         *@param  aFileName  The new name of the file         */        public void setFileName(String aFileName) {            this.fFileName = aFileName;        }                        /**         *  Gets the size of the file         *         *@return    The size of the file         */        public long getFileSize() {            return fFileSize;        }                        /**         *  Sets the size of a file         *         *@param  aFileSize  The new size of the file         */        public void setFileSize(long aFileSize) {            this.fFileSize = aFileSize;        }                        /**         *  Gets the description of the file         *         *@return    The description of the file         */        public String getDescription() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -