streaminitiationlistener.java

来自「网站即时通讯系统」· Java 代码 · 共 73 行

JAVA
73
字号
package com.valhalla.jbother.jabber.smack;import org.jivesoftware.smack.PacketListener;import org.jivesoftware.smack.filter.PacketFilter;import org.jivesoftware.smack.filter.PacketTypeFilter;import org.jivesoftware.smack.packet.IQ;import org.jivesoftware.smack.packet.Packet;import org.jivesoftware.smack.packet.XMPPError;import com.valhalla.gui.*;import com.valhalla.jbother.*;/** * Created by IntelliJ IDEA. * User: luke * Date: Jan 18, 2005 * Time: 10:27:42 AM *//** * incoming StreamInitiation packets are processed by this class. the main task * is to reply to it offering byteatream to the caller */public class StreamInitiationListener implements PacketListener {    private static String fId = "$Id$";    public static final String BYTESTREAMS = "http://jabber.org/protocol/bytestreams";    public StreamInitiationListener() {    }    public void processPacket(Packet packet) {        // <si type="set">        if (packet instanceof StreamInitiation                && ((IQ) packet).getType() == IQ.Type.SET) {            StreamInitiation si = (StreamInitiation) packet;            if (si.getFeature().providesBytestreamOption()) {                // inform the user that someone wants to send him/her a file                // popup "accept file" window. It will take the action from here                FileReceiveDialog frd = new FileReceiveDialog(si);                PacketFilter filter = new PacketTypeFilter(Streamhost.class);                BuddyList.getInstance().getConnection().addPacketListener(frd,                        filter);                frd.setVisible(true);            } else // seems that Initiator is using some other method for                   // sending files than byte streams...            {                IQ errorPacket = new IQ() {                    public String getChildElementXML() {                        return null;                    }                };                errorPacket.setTo(si.getFrom());                errorPacket.setFrom(si.getTo());                errorPacket.setType(IQ.Type.ERROR);                errorPacket.setPacketID(packet.getPacketID());                //          errorPacket.setError(new XMPPError(400,"<bad-request                // xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>\n"                //            + "<bad-profile xmlns=\"http://jabber.org/protocol/si\">"));                errorPacket.setError(new XMPPError(400, "bad-request"));                // send the response                if (BuddyList.getInstance().checkConnection()) {                    BuddyList.getInstance().getConnection().sendPacket(                            errorPacket);                }                return;            }        }    }}

⌨️ 快捷键说明

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