本文整理汇总了Java中org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension类的典型用法代码示例。如果您正苦于以下问题:Java DataPacketExtension类的具体用法?Java DataPacketExtension怎么用?Java DataPacketExtension使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataPacketExtension类属于org.jivesoftware.smackx.bytestreams.ibb.packet包,在下文中一共展示了DataPacketExtension类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: accept
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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: writeToXML
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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
示例3: setServiceEnabled
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
/**
* Enable the Jabber services related to file transfer on the particular
* connection.
*
* @param connection The connection on which to enable or disable the services.
* @param isEnabled True to enable, false to disable.
*/
private static void setServiceEnabled(final XMPPConnection connection,
final boolean isEnabled) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(DataPacketExtension.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Bytestream.NAMESPACE);
}
for (String namespace : namespaces) {
if (isEnabled) {
manager.addFeature(namespace);
} else {
manager.removeFeature(namespace);
}
}
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:28,代码来源:FileTransferNegotiator.java
示例4: isServiceEnabled
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
/**
* Checks to see if all file transfer related services are enabled on the
* connection.
*
* @param connection The connection to check
* @return True if all related services are enabled, false if they are not.
*/
public static boolean isServiceEnabled(final XMPPConnection connection) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(DataPacketExtension.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Bytestream.NAMESPACE);
}
for (String namespace : namespaces) {
if (!manager.includesFeature(namespace)) {
return false;
}
}
return true;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:26,代码来源:FileTransferNegotiator.java
示例5: shouldConfirmReceivedDataPacket
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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
示例6: accept
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
public boolean accept(Packet packet) {
// sender equals remote peer
if (!packet.getFrom().equalsIgnoreCase(remoteJID)) {
return false;
}
// stanza contains data packet extension
PacketExtension packetExtension = packet.getExtension(DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
if (packetExtension == null || !(packetExtension instanceof DataPacketExtension)) {
return false;
}
// session ID equals this session ID
DataPacketExtension data = (DataPacketExtension) packetExtension;
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
return false;
}
return true;
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:22,代码来源:InBandBytestreamSession.java
示例7: flushBuffer
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
private synchronized void flushBuffer() throws IOException {
// do nothing if no data to send available
if (bufferPointer == 0) {
return;
}
// create data packet
String enc = StringUtils.encodeBase64(buffer, 0, bufferPointer, false);
DataPacketExtension data = new DataPacketExtension(byteStreamRequest.getSessionID(),
this.seq, enc);
// write to XMPP stream
writeToXML(data);
// reset buffer pointer
bufferPointer = 0;
// increment sequence, considering sequence overflow
this.seq = (this.seq + 1 == 65535 ? 0 : this.seq + 1);
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:23,代码来源:InBandBytestreamSession.java
示例8: writeToXML
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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
示例9: accept
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
public boolean accept(Packet packet) {
// sender equals remote peer
if (!packet.getFrom().equalsIgnoreCase(remoteJID)) {
return false;
}
// stanza contains data packet extension
PacketExtension packetExtension = packet.getExtension(
DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
if (packetExtension == null
|| !(packetExtension instanceof DataPacketExtension)) {
return false;
}
// session ID equals this session ID
DataPacketExtension data = (DataPacketExtension) packetExtension;
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
return false;
}
return true;
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:24,代码来源:InBandBytestreamSession.java
示例10: flushBuffer
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
private synchronized void flushBuffer() throws IOException {
// do nothing if no data to send available
if (bufferPointer == 0) {
return;
}
// create data packet
String enc = StringUtils.encodeBase64(buffer, 0, bufferPointer,
false);
DataPacketExtension data = new DataPacketExtension(
byteStreamRequest.getSessionID(), this.seq, enc);
// write to XMPP stream
writeToXML(data);
// reset buffer pointer
bufferPointer = 0;
// increment sequence, considering sequence overflow
this.seq = (this.seq + 1 == 65535 ? 0 : this.seq + 1);
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:24,代码来源:InBandBytestreamSession.java
示例11: writeToXML
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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
示例12: parse
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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
示例13: getDataPacketListener
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
protected StanzaListener getDataPacketListener() {
return new StanzaListener() {
public void processPacket(Stanza packet) {
// get data packet extension
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
// check if encoded data is valid
if (data.getDecodedData() == null) {
/*
* TODO once a majority of XMPP server implementation support XEP-0079
* Advanced Message Processing the invalid message could be answered with an
* appropriate error. For now we just ignore the packet. Subsequent packets
* with an increased sequence will cause the input stream to close the
* stream/session.
*/
return;
}
// data is valid; add to data queue
dataQueue.offer(data);
// TODO confirm packet once XMPP servers support XEP-0079
}
};
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:30,代码来源:InBandBytestreamSession.java
示例14: flushBuffer
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
private synchronized void flushBuffer() throws IOException {
// do nothing if no data to send available
if (bufferPointer == 0) {
return;
}
// create data packet
String enc = Base64.encodeToString(buffer, 0, bufferPointer);
DataPacketExtension data = new DataPacketExtension(byteStreamRequest.getSessionID(),
this.seq, enc);
// write to XMPP stream
try {
writeToXML(data);
}
catch (NotConnectedException e) {
IOException ioException = new IOException();
ioException.initCause(e);
throw ioException;
}
// reset buffer pointer
bufferPointer = 0;
// increment sequence, considering sequence overflow
this.seq = (this.seq + 1 == 65535 ? 0 : this.seq + 1);
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:30,代码来源:InBandBytestreamSession.java
示例15: getSupportedProtocols
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
/**
* Returns a collection of the supported transfer protocols.
*
* @return Returns a collection of the supported transfer protocols.
*/
public static Collection<String> getSupportedProtocols() {
List<String> protocols = new ArrayList<String>();
protocols.add(DataPacketExtension.NAMESPACE);
if (!IBB_ONLY) {
protocols.add(Bytestream.NAMESPACE);
}
return Collections.unmodifiableList(protocols);
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:14,代码来源:FileTransferNegotiator.java
示例16: getNegotiator
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
private StreamNegotiator getNegotiator(final FormField field)
throws NoAcceptableTransferMechanisms {
String variable;
boolean isByteStream = false;
boolean isIBB = false;
for (FormField.Option option : field.getOptions()) {
variable = option.getValue();
if (variable.equals(Bytestream.NAMESPACE) && !IBB_ONLY) {
isByteStream = true;
}
else if (variable.equals(DataPacketExtension.NAMESPACE)) {
isIBB = true;
}
}
if (!isByteStream && !isIBB) {
throw new FileTransferException.NoAcceptableTransferMechanisms();
}
if (isByteStream && isIBB) {
return new FaultTolerantNegotiator(connection(),
byteStreamTransferManager,
inbandTransferManager);
}
else if (isByteStream) {
return byteStreamTransferManager;
}
else {
return inbandTransferManager;
}
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:32,代码来源:FileTransferNegotiator.java
示例17: getOutgoingNegotiator
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
private StreamNegotiator getOutgoingNegotiator(final FormField field) throws NoAcceptableTransferMechanisms {
boolean isByteStream = false;
boolean isIBB = false;
for (String variable : field.getValues()) {
if (variable.equals(Bytestream.NAMESPACE) && !IBB_ONLY) {
isByteStream = true;
}
else if (variable.equals(DataPacketExtension.NAMESPACE)) {
isIBB = true;
}
}
if (!isByteStream && !isIBB) {
throw new FileTransferException.NoAcceptableTransferMechanisms();
}
if (isByteStream && isIBB) {
return new FaultTolerantNegotiator(connection(),
byteStreamTransferManager, inbandTransferManager);
}
else if (isByteStream) {
return byteStreamTransferManager;
}
else {
return inbandTransferManager;
}
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:28,代码来源:FileTransferNegotiator.java
示例18: createDefaultInitiationForm
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的package包/类
private DataForm createDefaultInitiationForm() {
DataForm form = new DataForm(DataForm.Type.form);
FormField field = new FormField(STREAM_DATA_FIELD_NAME);
field.setType(FormField.Type.list_single);
if (!IBB_ONLY) {
field.addOption(new FormField.Option(Bytestream.NAMESPACE));
}
field.addOption(new FormField.Option(DataPacketExtension.NAMESPACE));
form.addField(field);
return form;
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:12,代码来源:FileTransferNegotiator.java
示例19: shouldReplyErrorIfSessionIsUnknown
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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
示例20: setup
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; //导入依赖的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 with message stanza
initBytestream = new Open(sessionID, blockSize, StanzaType.MESSAGE);
initBytestream.setFrom(initiatorJID);
initBytestream.setTo(targetJID);
incrementingSequence = new Verification<Message, IQ>() {
long lastSeq = 0;
public void verify(Message request, IQ response) {
DataPacketExtension dpe = (DataPacketExtension) request.getExtension(
DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE);
assertEquals(lastSeq++, dpe.getSeq());
}
};
}
开发者ID:TTalkIM,项目名称:Smack,代码行数:36,代码来源:InBandBytestreamSessionMessageTest.java
注:本文中的org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论