• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Data类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jivesoftware.smackx.bytestreams.ibb.packet.Data的典型用法代码示例。如果您正苦于以下问题:Java Data类的具体用法?Java Data怎么用?Java Data使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Data类属于org.jivesoftware.smackx.bytestreams.ibb.packet包,在下文中一共展示了Data类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: accept

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
public boolean accept(Stanza packet) {
    // sender equals remote peer
    if (!packet.getFrom().equalsIgnoreCase(remoteJID)) {
        return false;
    }

    DataPacketExtension data;
    if (packet instanceof Data) {
        data = ((Data) packet).getDataPacketExtension();
    } else {
        // stanza contains data packet extension
        data = packet.getExtension(
                DataPacketExtension.ELEMENT,
                DataPacketExtension.NAMESPACE);
        if (data == null) {
            return false;
        }
    }

    // session ID equals this session ID
    if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
        return false;
    }

    return true;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:27,代码来源:InBandBytestreamSession.java


示例2: handleIQRequest

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
@Override
public IQ handleIQRequest(IQ iqRequest) {
    Data data = (Data) iqRequest;
    InBandBytestreamSession ibbSession = this.manager.getSessions().get(
                    data.getDataPacketExtension().getSessionID());
    try {
        if (ibbSession == null) {
            this.manager.replyItemNotFoundPacket(data);
        }
        else {
            ibbSession.processIQPacket(data);
        }
    }
    catch (NotConnectedException e) {
        return null;
    }
    return null;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:19,代码来源:DataListener.java


示例3: writeToXML

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
@Override
protected synchronized void writeToXML(DataPacketExtension data) throws IOException {
    // create IQ stanza containing data packet
    IQ iq = new Data(data);
    iq.setTo(remoteJID);

    try {
        connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
    }
    catch (Exception e) {
        // close session unless it is already closed
        if (!this.isClosed) {
            InBandBytestreamSession.this.close();
            // Sadly we are unable to use the IOException(Throwable) constructor because this
            // constructor is only supported from Android API 9 on.
            IOException ioException = new IOException();
            ioException.initCause(e);
            throw ioException;
        }
    }

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:23,代码来源:InBandBytestreamSession.java


示例4: shouldConfirmReceivedDataPacket

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * Valid data packets should be confirmed.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldConfirmReceivedDataPacket() throws Exception {
    // verify data packet confirmation is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);

    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);

    listener.processPacket(data);

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:InBandBytestreamSessionTest.java


示例5: writeToXML

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
@Override
protected synchronized void writeToXML(DataPacketExtension data) throws IOException {
    // create IQ stanza containing data packet
    IQ iq = new Data(data);
    iq.setTo(remoteJID);

    try {
        SyncPacketSend.getReply(connection, iq);
    }
    catch (XMPPException e) {
        // close session unless it is already closed
        if (!this.isClosed) {
            InBandBytestreamSession.this.close();
            throw new IOException("Error while sending Data: " + e.getMessage());
        }
    }

}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:19,代码来源:InBandBytestreamSession.java


示例6: writeToXML

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
@Override
protected synchronized void writeToXML(DataPacketExtension data)
		throws IOException {
	// create IQ stanza containing data packet
	IQ iq = new Data(data);
	iq.setTo(remoteJID);

	try {
		SyncPacketSend.getReply(connection, iq);
	} catch (XMPPException e) {
		// close session unless it is already closed
		if (!this.isClosed) {
			InBandBytestreamSession.this.close();
			throw new IOException("Error while sending Data: "
					+ e.getMessage());
		}
	}

}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:20,代码来源:InBandBytestreamSession.java


示例7: parse

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
@Override
public Data parse(XmlPullParser parser, int initialDepth)
                throws XmlPullParserException, IOException,
                SmackException {
    DataPacketExtension data = packetExtensionProvider.parse(parser);
    Data iq = new Data(data);
    return iq;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:9,代码来源:DataPacketProvider.java


示例8: getDataPacketFilter

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
protected StanzaFilter getDataPacketFilter() {
    /*
     * filter all IQ stanzas having type 'SET' (represented by Data class), containing a
     * data stanza(/packet) extension, matching session ID and recipient
     */
    return new AndFilter(new StanzaTypeFilter(Data.class), new IBBDataPacketFilter());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:8,代码来源:InBandBytestreamSession.java


示例9: shouldReplyErrorIfSessionIsUnknown

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * If a data stanza(/packet) of an unknown session is received it should be replied
 * with an <item-not-found/> error.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReplyErrorIfSessionIsUnknown() throws Exception {

    // mock connection
    XMPPConnection connection = mock(XMPPConnection.class);

    // initialize InBandBytestreamManager to get the DataListener
    InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);

    // get the DataListener from InBandByteStreamManager
    DataListener dataListener = Whitebox.getInternalState(byteStreamManager,
                    DataListener.class);

    DataPacketExtension dpe = new DataPacketExtension("unknownSessionID", 0, "Data");
    Data data = new Data(dpe);
    data.setFrom(initiatorJID);
    data.setTo(targetJID);

    dataListener.handleIQRequest(data);

    // wait because packet is processed in an extra thread
    Thread.sleep(200);

    // capture reply to the In-Band Bytestream close request
    ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
    verify(connection).sendStanza(argument.capture());

    // assert that reply is the correct error packet
    assertEquals(initiatorJID, argument.getValue().getTo());
    assertEquals(IQ.Type.error, argument.getValue().getType());
    assertEquals(XMPPError.Condition.item_not_found,
                    argument.getValue().getError().getCondition());

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:41,代码来源:DataListenerTest.java


示例10: setup

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * Initialize fields used in the tests.
 * @throws XMPPException 
 * @throws SmackException 
 */
@Before
public void setup() throws XMPPException, SmackException {

    // build protocol verifier
    protocol = new Protocol();

    // create mocked XMPP connection
    connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID, xmppServer);

    // initialize InBandBytestreamManager to get the InitiationListener
    byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);

    // create a In-Band Bytestream open packet
    initBytestream = new Open(sessionID, blockSize);
    initBytestream.setFrom(initiatorJID);
    initBytestream.setTo(targetJID);

    incrementingSequence = new Verification<Data, IQ>() {

        long lastSeq = 0;

        public void verify(Data request, IQ response) {
            assertEquals(lastSeq++, request.getDataPacketExtension().getSeq());
        }

    };

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:34,代码来源:InBandBytestreamSessionTest.java


示例11: shouldSendDataCorrectly

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * Test that the data is correctly chunked.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldSendDataCorrectly() throws Exception {
    // create random data
    Random rand = new Random();
    final byte[] controlData = new byte[256 * blockSize];
    rand.nextBytes(controlData);

    // compares the data of each packet with the control data
    Verification<Data, IQ> dataVerification = new Verification<Data, IQ>() {

        public void verify(Data request, IQ response) {
            byte[] decodedData = request.getDataPacketExtension().getDecodedData();
            int seq = (int) request.getDataPacketExtension().getSeq();
            for (int i = 0; i < decodedData.length; i++) {
                assertEquals(controlData[(seq * blockSize) + i], decodedData[i]);
            }
        }

    };

    // set acknowledgments for the data packets
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
    for (int i = 0; i < controlData.length / blockSize; i++) {
        protocol.addResponse(resultIQ, incrementingSequence, dataVerification);
    }

    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);

    OutputStream outputStream = session.getOutputStream();
    outputStream.write(controlData);
    outputStream.flush();

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:42,代码来源:InBandBytestreamSessionTest.java


示例12: shouldNotCloseBothStreamsIfOutputStreamIsClosed

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * If the input stream is closed the output stream should not be closed as well.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldNotCloseBothStreamsIfOutputStreamIsClosed() throws Exception {

    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    OutputStream outputStream = session.getOutputStream();
    outputStream.close();

    // verify data packet confirmation is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);

    // insert data to read
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);
    listener.processPacket(data);

    // verify no packet send
    protocol.verifyAll();

    try {
        outputStream.flush();
        fail("should throw an exception");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("closed"));
    }

    assertTrue(inputStream.read() != 0);

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:39,代码来源:InBandBytestreamSessionTest.java


示例13: shouldReplyWithErrorIfAlreadyUsedSequenceIsReceived

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * If the data stanza(/packet) has a sequence that is already used an 'unexpected-request' error should
 * be returned. See XEP-0047 Section 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReplyWithErrorIfAlreadyUsedSequenceIsReceived() throws Exception {
    // verify reply to first valid data packet is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);

    // verify reply to invalid data packet is an error
    protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() {

        public void verify(IQ request, IQ response) {
            assertEquals(XMPPError.Condition.unexpected_request,
                            request.getError().getCondition());
        }

    });

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build data packets
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data1 = new Data(dpe);
    Data data2 = new Data(dpe);

    // notify listener
    listener.processPacket(data1);
    listener.processPacket(data2);

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:41,代码来源:InBandBytestreamSessionTest.java


示例14: shouldReplyWithErrorIfDataIsInvalid

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * If the data stanza(/packet) contains invalid Base64 encoding an 'bad-request' error should be
 * returned. See XEP-0047 Section 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReplyWithErrorIfDataIsInvalid() throws Exception {
    // verify reply to invalid data packet is an error
    protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() {

        public void verify(IQ request, IQ response) {
            assertEquals(XMPPError.Condition.bad_request,
                            request.getError().getCondition());
        }

    });

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build data packets
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, "AA=BB");
    Data data = new Data(dpe);

    // notify listener
    listener.processPacket(data);

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:35,代码来源:InBandBytestreamSessionTest.java


示例15: shouldSendCloseRequestIfInvalidSequenceReceived

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * If a data stanza(/packet) is received out of order the session should be closed. See XEP-0047 Section
 * 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldSendCloseRequestIfInvalidSequenceReceived() throws Exception {
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);

    // confirm data packet with invalid sequence
    protocol.addResponse(resultIQ);

    // confirm close request
    protocol.addResponse(resultIQ, Verification.requestTypeSET,
                    Verification.correspondingSenderReceiver);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build invalid packet with out of order sequence
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 123, base64Data);
    Data data = new Data(dpe);

    // add data packets
    listener.processPacket(data);

    // read until exception is thrown
    try {
        inputStream.read();
        fail("exception should be thrown");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("Packets out of sequence"));
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:44,代码来源:InBandBytestreamSessionTest.java


示例16: shouldReadAllReceivedData2

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * Test the input stream read() method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData2() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // set data packet acknowledgment and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        protocol.addResponse(resultIQ);
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Data data = new Data(dpe);
        listener.processPacket(data);
    }

    // read data
    byte[] bytes = new byte[3 * blockSize];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (byte) inputStream.read();
    }

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:44,代码来源:InBandBytestreamSessionTest.java


示例17: shouldNotCloseBothStreamsIfInputStreamIsClosed

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
/**
 * If the output stream is closed the input stream should not be closed as well.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldNotCloseBothStreamsIfInputStreamIsClosed() throws Exception {
    // acknowledgment for data packet
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
    protocol.addResponse(resultIQ);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build data packet
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);

    // add data packets
    listener.processPacket(data);

    inputStream.close();

    protocol.verifyAll();

    try {
        while (inputStream.read() != -1) {
        }
        inputStream.read();
        fail("should throw an exception");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("closed"));
    }

    session.getOutputStream().flush();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:43,代码来源:InBandBytestreamSessionTest.java


示例18: processPacket

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
public void processPacket(Packet packet) {
    Data data = (Data) packet;
    InBandBytestreamSession ibbSession = this.manager.getSessions().get(
                    data.getDataPacketExtension().getSessionID());
    if (ibbSession == null) {
        this.manager.replyItemNotFoundPacket(data);
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:9,代码来源:DataListener.java


示例19: getDataPacketFilter

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
protected PacketFilter getDataPacketFilter() {
    /*
     * filter all IQ stanzas having type 'SET' (represented by Data class), containing a
     * data packet extension, matching session ID and recipient
     */
    return new AndFilter(new PacketTypeFilter(Data.class), new IBBDataPacketFilter());
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:8,代码来源:InBandBytestreamSession.java


示例20: processPacket

import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; //导入依赖的package包/类
public void processPacket(Packet packet) {
	Data data = (Data) packet;
	InBandBytestreamSession ibbSession = this.manager.getSessions().get(
			data.getDataPacketExtension().getSessionID());
	if (ibbSession == null) {
		this.manager.replyItemNotFoundPacket(data);
	}
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:9,代码来源:DataListener.java



注:本文中的org.jivesoftware.smackx.bytestreams.ibb.packet.Data类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RuntimeMapPropertyInfo类代码示例发布时间:2022-05-23
下一篇:
Java LocatableEvent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap