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

📄 streamhost.java

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA
字号:
/** * $RCSfile$ * $Revision: 2495 $ * $Date: 2005-05-30 10:14:25 -0500 (Mon, 30 May 2005) $ * * 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.provider.IQProvider;import org.jivesoftware.smackx.provider.DataFormProvider;import org.xmlpull.v1.XmlPullParser;import java.util.*;import java.net.*;import java.io.IOException;import java.nio.channels.SocketChannel;import java.nio.channels.FileChannel;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;/** * Represents information contained in <streamhost> message. *@author     Lukasz Wiechec */public class StreamHost extends IQ {        private static final String NAMESPACE = "http://jabber.org/protocol/bytestreams";        private ArrayList hosts = new ArrayList();    private String sid;        /**     * Creates a streamhost with the specified session id     *@param aSId a session id for this transfer     */    public StreamHost(String aSId) {        setType(Type.SET);        sid = aSId;    }         /**     * Gets the session id for this transfer     *@return the session id     */    public String getSid() {        return sid;    }        /**     * Sets the session id for this transfer     *@param aSId   the sesssion id     */    public void setSid(String aSId) {        sid = aSId;    }        /**     * Adds a new host to this packet     *@param host the new host     */    public synchronized void addHost(Host host) {        hosts.add(host);    }        /**     * Returns all the hosts contained in this packet     *@return the hosts     */    public synchronized ArrayList getHosts() { return hosts; }        /**     * Removes a host from this packet     *@param host   The host to remove     */    public synchronized void removeHost(Host host)    {        int index = hosts.indexOf(host);        if(index != -1) hosts.remove(index);    }        /**     * Returns the XML representation of this packet     *@return   the xml representation    */    public String getChildElementXML() {        StringBuffer buf = new StringBuffer();        buf.append("<query xmlns=\"").append(NAMESPACE).append("\" sid=\"")            .append(sid).append("\">");                for(int i = 0; i < hosts.size(); i++)        {            Host host = (Host)hosts.get(i);            String hostname = host.getHost();            String jid = host.getJid();            int port = host.getPort();                        if (hostname != null && port != -1 && jid != null) {                buf.append("<streamhost port=\"").append(port)                    .append("\" host=\"").append(hostname)                    .append("\" jid=\"").append(jid).append("\"/>");            }        }        buf.append("</query>");        return buf.toString();    }        /**     * Returns a specific Host for a jid     *@return the host, or <tt>null</tt> if it cannot be found     */    public Host getHostFor(String jid)    {        for(int i = 0; i < hosts.size(); i++)        {            Host host = (Host)hosts.get(i);            if(host.getJid().equals(jid)) return host;        }                return null;    }        /**     * Representation of a Host    */    public static class Host    {        String host;        String jid;        int port;                /**         * Creates a host object         *@param host   the address of the host         *@param jid    the JID of the host         *@param port   the port of the host        */                public Host(String host, String jid, int port)        {            this.host = host;            this.jid = jid;            this.port = port;        }                /**         * @return the address of the host        */        public String getHost() { return host; }                /**         * @return the JID of the host        */        public String getJid() { return jid; }                /**         * @return the port of the host        */        public int getPort() { return port; }    }    }

⌨️ 快捷键说明

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