本文整理汇总了Java中com.isode.stroke.base.ByteArray类的典型用法代码示例。如果您正苦于以下问题:Java ByteArray类的具体用法?Java ByteArray怎么用?Java ByteArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteArray类属于com.isode.stroke.base包,在下文中一共展示了ByteArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
public ByteArray serialize() {
ByteArray result = new ByteArray();
for(Map.Entry<String, ByteArray> entry : properties.entrySet()) {
if(entry.getKey() != properties.firstKey()) {
result.append((byte)(','));
}
result.append(new ByteArray(entry.getKey()));
result.append((byte)('='));
if (isQuoted(entry.getKey())) {
result.append(new ByteArray("\""));
result.append(entry.getValue()); //It does not iterate over all values possible for this key. So no need for MultiMap. Also serialize test also indicates the same.
result.append(new ByteArray("\""));
}
else {
result.append(entry.getValue());
}
}
return result;
}
示例2: testSerialize_FileInfo_withAllVariables
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testSerialize_FileInfo_withAllVariables() {
JingleFileTransferHashSerializer testling = new JingleFileTransferHashSerializer();
JingleFileTransferHash hash = new JingleFileTransferHash();
JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
fileInfo.setName("Isaac");
fileInfo.setDescription("It is good.");
fileInfo.setMediaType("MediaAAC");
fileInfo.setSize(513L);
fileInfo.setDate(new Date(1434056150620L));
fileInfo.setSupportsRangeRequests(true);
fileInfo.setRangeOffset(566L);
fileInfo.addHash(new HashElement("MD5", new ByteArray()));
hash.setFileInfo(fileInfo);
String expectedResult = "<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date>" +
"<desc>It is good.</desc><media-type>MediaAAC</media-type><name>Isaac</name><range offset=\"566\"/>" +
"<size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>";
assertEquals(expectedResult, testling.serialize(hash));
}
示例3: testDataStreamResumeAfterPauseSendsData
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testDataStreamResumeAfterPauseSendsData() {
SOCKS5BytestreamServerSession testling = createSession();
testling.setChunkSize(3);
stream1.setDataComplete(false);
StartStopper<SOCKS5BytestreamServerSession> stopper =
new StartStopper<SOCKS5BytestreamServerSession>(testling);
bytestreams.setHasBytestream("abcdef", true);
authenticate();
request("abcdef");
eventLoop.processEvents();
testling.startSending(stream1);
eventLoop.processEvents();
skipHeader("abcdef");
stream1.addData(new ByteArray("xyz"));
eventLoop.processEvents();
assertEquals(new ByteArray("abcdefgxyz"),receivedData);
assertFalse(finished);
assertNull(error);
}
示例4: test_OnlyIBBTransferReceiveWorks
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void test_OnlyIBBTransferReceiveWorks() {
// 1 Create your test incoming file transfer
JingleFileTransferDescription desc = new JingleFileTransferDescription();
desc.setFileInfo(new JingleFileTransferFileInfo("foo.tx", "", 10));
jingleContentPayload.addDescription(desc);
JingleIBBTransportPayload tpRef = new JingleIBBTransportPayload();
tpRef.setSessionID("mysession");
jingleContentPayload.addTransport(tpRef);
IncomingJingleFileTransfer fileTransfer = createTestling();
// 2 Do 'accept' on a dummy writebytestream (you'll have to look if there already is one)
ByteArrayWriteBytestream byteStream = new ByteArrayWriteBytestream();
fileTransfer.accept(byteStream);;
// 3 Check whether accept has been called
getCall(FakeJingleSession.AcceptCall.class,0);
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBOpen("myession", 10),
new JID("[email protected]/baz"), "id-open"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 0, new ByteArray("abc")),
new JID("[email protected]/baz"), "id-open"));
assertEquals(new ByteArray("abc"),byteStream.getData());
}
示例5: testParse_with_Some_variables
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testParse_with_Some_variables() {
DummyEventLoop eventLoop = new DummyEventLoop();
PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
assertNotNull(parser.parse("<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
"<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>"));
JingleFileTransferDescription description = (JingleFileTransferDescription)parser.getPayload();
assertNotNull(description);
JingleFileTransferFileInfo fileInfo = description.getFileInfo();
assertNotNull(fileInfo);
assertEquals("Isaac", fileInfo.getName());
assertEquals("It is good.", fileInfo.getDescription());
assertEquals("MediaAAC", fileInfo.getMediaType());
assertEquals(0L, fileInfo.getSize());
assertNull(fileInfo.getDate());
assertEquals(false, fileInfo.getSupportsRangeRequests());
assertEquals(0L, fileInfo.getRangeOffset());
assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
}
示例6: testParse_Photo
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testParse_Photo() {
DummyEventLoop eventloop = new DummyEventLoop();
PayloadsParserTester parser = new PayloadsParserTester(eventloop);
assertNotNull(parser.parse(
"<vCard xmlns='vcard-temp'>" +
"<PHOTO>" +
"<TYPE>image/jpeg</TYPE>" +
"<BINVAL>" +
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" +
"EyMzQ1Njc4OTA=" +
"</BINVAL>" +
"</PHOTO>" +
"</vCard>"));
VCard payload = (VCard)(parser.getPayload());
assertEquals(("image/jpeg"), payload.getPhotoType());
assertEquals(new ByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload.getPhoto());
}
示例7: testReceiveLastData
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testReceiveLastData() {
IBBReceiveSession testling = createSession("[email protected]/baz", "mysession", 6);
testling.start();
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBOpen("mysession", 0x10),
new JID("[email protected]/baz"),
"id-open"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 0, new ByteArray("abc")),
new JID("[email protected]/baz"),
"id-a"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 1, new ByteArray("def")),
new JID("[email protected]/baz"),
"id-b"));
assertTrue(stanzaChannel.isResultAtIndex(2, "id-b"));
assertEquals(new ByteArray("abcdef"),bytestream.getData());
assertTrue(finished);
assertNull(error);
testling.stop();
}
示例8: testSerialize_withAllVariables
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testSerialize_withAllVariables() {
JingleFileTransferFileInfoSerializer testling = new JingleFileTransferFileInfoSerializer();
JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
fileInfo.setName("Isaac");
fileInfo.setDescription("It is good.");
fileInfo.setMediaType("MediaAAC");
fileInfo.setSize(513L);
fileInfo.setDate(new Date(1434056150620L));
fileInfo.setSupportsRangeRequests(true);
fileInfo.setRangeOffset(566L);
fileInfo.addHash(new HashElement("MD5", new ByteArray()));
String expectedResult = "<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
"<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
"<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>";
assertEquals(expectedResult, testling.serialize(fileInfo));
}
示例9: unhexify
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
public static ByteArray unhexify(String hexstring) {
if (hexstring.length() % 2 != 0) {
return new ByteArray();
}
byte[] result = new byte[hexstring.length() / 2];
for (int pos = 0; pos < hexstring.length() - 1; pos += 2) {
char c;
c = hexstring.charAt(pos);
int a = (c>='0'&&c<='9') ? c-'0' : (c>='A'&&c<='Z') ? c-'A' + 10 : (c>='a'&&c<='z') ? c-'a' + 10 : -1;
c = hexstring.charAt(pos+1);
int b = (c>='0'&&c<='9') ? c-'0' : (c>='A'&&c<='Z') ? c-'A' + 10 : (c>='a'&&c<='z') ? c-'a' + 10 : -1;
if (a == -1 || b == -1) return new ByteArray(); // fail
result[pos/2] = (byte) ((a << 4) | b);
}
return new ByteArray(result);
}
示例10: sendMoreData
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
private void sendMoreData() {
//try {
ByteArray data = bytestream.read(blockSize);
if (!data.isEmpty()) {
waitingForData = false;
IBBRequest request = IBBRequest.create(from, to, IBB.createIBBData(id, sequenceNumber, data), router);
sequenceNumber++;
request.onResponse.connect(new Slot2<IBB, ErrorPayload>() {
@Override
public void call(IBB b, ErrorPayload e) {
handleIBBResponse(b, e);
}
});
request.send();
onBytesSent.emit(data.getSize());
}
else {
waitingForData = true;
}
//}
//catch (BytestreamException e) {
// finish(new FileTransferError(FileTransferError.Type.ReadError));
//}
}
示例11: testRequest_UnknownBytestream
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testRequest_UnknownBytestream() {
SOCKS5BytestreamServerSession testling = createSession();
StartStopper<SOCKS5BytestreamServerSession> stopper =
new StartStopper<SOCKS5BytestreamServerSession>(testling);
authenticate();
ByteArray hostname = new ByteArray("abcdef");
SafeByteArray data = new SafeByteArray();
data.append(new byte[]{0x05,0x01,0x00,0x03});
data.append((byte)hostname.getSize());
data.append(hostname);
data.append(new byte[] {0x00,0x00});
receive(data);
ByteArray expected =
new ByteArray(new byte[] {0x05,0x04,0x00,0x03,0x06,0x61,0x62,
0x63,0x64,0x65,0x66,0x00,0x00});
assertEquals(expected,receivedData);
}
示例12: setUp
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Before
public void setUp() {
crypto = new JavaCryptoProvider();
ownJID = new JID("[email protected]/bum");
stanzaChannel = new DummyStanzaChannel();
stanzaChannel.setAvailable(true);
iqRouter = new IQRouter(stanzaChannel);
mucRegistry = new DummyMUCRegistry();
avatarStorage = new AvatarMemoryStorage();
vcardStorage = new VCardMemoryStorage(crypto);
vcardManager = new VCardManager(ownJID, iqRouter, vcardStorage);
avatar1 = new ByteArray("abcdefg");
avatar1Hash = Hexify.hexify(crypto.getSHA1Hash(avatar1));
changes = new Vector<JID>();
user1 = new JID("[email protected]/bla");
user2 = new JID("[email protected]/baz");
}
示例13: getAvatarHash
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Override
public String getAvatarHash(JID jid) {
JID avatarJID = getAvatarJID(jid);
String hash = vcardManager_.getPhotoHash(avatarJID);
if(hash.length() != 0) {
if (!avatarStorage_.hasAvatar(hash)) {
final VCard vCard = vcardManager_.getVCard(avatarJID);
final ByteArray photo = vCard != null ? vCard.getPhoto() : null;
if (photo != null) {
String newHash = Hexify.hexify(crypto_.getSHA1Hash(photo));
if (!newHash.equals(hash)) {
// Shouldn't happen, but sometimes seem to. Might be fixed if we
// move to a safer backend.
logger_.warning("Inconsistent vCard photo hash cache");
hash = newHash;
}
avatarStorage_.addAvatar(hash, photo);
}
else {
// Can happen if the cache is inconsistent.
hash = "";
}
}
}
return hash;
}
示例14: testReceiveMultipleData
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testReceiveMultipleData() {
IBBReceiveSession testling = createSession("[email protected]/baz", "mysession");
testling.start();
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBOpen("mysession", 0x10),
new JID("[email protected]/baz"),
"id-open"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 0, new ByteArray("abc")),
new JID("[email protected]/baz"),
"id-a"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 1, new ByteArray("def")),
new JID("[email protected]/baz"),
"id-b"));
assertTrue(stanzaChannel.isResultAtIndex(2, "id-b"));
assertEquals(new ByteArray("abcdef"),bytestream.getData());
assertFalse(finished);
testling.stop();
}
示例15: testReceiveDataOutOfOrder
import com.isode.stroke.base.ByteArray; //导入依赖的package包/类
@Test
public void testReceiveDataOutOfOrder() {
IBBReceiveSession testling = createSession("[email protected]/baz", "mysession");
testling.start();
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBOpen("mysession", 0x10),
new JID("[email protected]/baz"),
"id-open"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 0, new ByteArray("abc")),
new JID("[email protected]/baz"),
"id-a"));
stanzaChannel.onIQReceived.emit(createIBBRequest(
IBB.createIBBData("mysession", 0, new ByteArray("def")),
new JID("[email protected]/baz"),
"id-b"));
assertTrue(stanzaChannel.isErrorAtIndex(2, "id-b"));
assertTrue(finished);
assertNotNull(error);
testling.stop();
}