本文整理汇总了Java中de.javawi.jstun.util.UtilityException类的典型用法代码示例。如果您正苦于以下问题:Java UtilityException类的具体用法?Java UtilityException怎么用?Java UtilityException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UtilityException类属于de.javawi.jstun.util包,在下文中一共展示了UtilityException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: bindingRequest
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public boolean bindingRequest(final int port) {
DatagramSocket socket = null;
try {
if (port <= 0) {
socket = new DatagramSocket();
} else {
socket = new DatagramSocket(port);
}
socket.connect(InetAddress.getByName(mStunServer), mPort);
socket.setSoTimeout(mTimeout);
return bindingCommunicationInitialSocket(socket);
} catch (IOException | UtilityException | MessageHeaderParsingException | MessageAttributeParsingException e) {
if (DEBUG) {
Log.e(TAG, "Failed to binding Request." + e.getMessage(), e);
}
return false;
} finally {
if (socket != null) {
socket.close();
}
}
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:23,代码来源:StunClient.java
示例2: getBytes
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public byte[] getBytes() throws UtilityException {
int length = 0;
if (unkown.size()%2 == 1) {
length = 2 * (unkown.size() + 1) + 4;
} else {
length = 2 * unkown.size() + 4;
}
byte[] result = new byte[length];
// message attribute header
// type
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
// length
System.arraycopy(Utility.integerToTwoBytes(length - 4), 0, result, 2, 2);
// unkown attribute header
Iterator<MessageAttributeType> it = unkown.iterator();
while(it.hasNext()) {
MessageAttributeType attri = it.next();
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(attri)), 0, result, 4, 2);
}
// padding
if (unkown.size()%2 == 1) {
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(unkown.elementAt(1))), 0, result, 4, 2);
}
return result;
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:27,代码来源:UnknownAttribute.java
示例3: getBytes
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public byte[] getBytes() throws UtilityException {
int length = reason.length();
// length adjustment
if ((length % 4) != 0) {
length += 4 - (length % 4);
}
// message attribute header
length += 4;
byte[] result = new byte[length];
// message attribute header
// type
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
// length
System.arraycopy(Utility.integerToTwoBytes(length-4), 0, result, 2, 2);
// error code header
int classHeader = (int) Math.floor(((double)responseCode)/100);
result[6] = Utility.integerToOneByte(classHeader);
result[7] = Utility.integerToOneByte(responseCode%100);
byte[] reasonArray = reason.getBytes();
System.arraycopy(reasonArray, 0, result, 8, reasonArray.length);
return result;
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:24,代码来源:ErrorCode.java
示例4: parse
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public static ErrorCode parse(byte[] data) throws MessageAttributeParsingException {
try {
if (data.length < 4) {
throw new MessageAttributeParsingException("Data array too short");
}
byte classHeaderByte = data[3];
int classHeader = Utility.oneByteToInteger(classHeaderByte);
if ((classHeader < 1) || (classHeader > 6)) throw new MessageAttributeParsingException("Class parsing error");
byte numberByte = data[4];
int number = Utility.oneByteToInteger(numberByte);
if ((number < 0) || (number > 99)) throw new MessageAttributeParsingException("Number parsing error");
int responseCode = (classHeader * 100) + number;
ErrorCode result = new ErrorCode();
result.setResponseCode(responseCode);
return result;
} catch (UtilityException ue) {
throw new MessageAttributeParsingException("Parsing error");
} catch (MessageAttributeException mae) {
throw new MessageAttributeParsingException("Parsing error");
}
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:22,代码来源:ErrorCode.java
示例5: getBytes
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public byte[] getBytes() throws UtilityException {
int length = password.length();
// password header
if ((length % 4) != 0) {
length += 4 - (length % 4);
}
// message attribute header
length += 4;
byte[] result = new byte[length];
// message attribute header
// type
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
// length
System.arraycopy(Utility.integerToTwoBytes(length - 4), 0, result, 2, 2);
// password header
byte[] temp = password.getBytes();
System.arraycopy(temp, 0, result, 4, temp.length);
return result;
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:21,代码来源:Password.java
示例6: getBytes
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public byte[] getBytes() throws UtilityException {
int length = username.length();
// username header
if ((length % 4) != 0) {
length += 4 - (length % 4);
}
// message attribute header
length += 4;
byte[] result = new byte[length];
// message attribute header
// type
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
// length
System.arraycopy(Utility.integerToTwoBytes(length-4), 0, result, 2, 2);
// username header
byte[] temp = username.getBytes();
System.arraycopy(temp, 0, result, 4, temp.length);
return result;
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:21,代码来源:Username.java
示例7: parseAttributes
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public void parseAttributes(byte[] data) throws MessageAttributeParsingException {
try {
byte[] lengthArray = new byte[2];
System.arraycopy(data, 2, lengthArray, 0, 2);
int length = Utility.twoBytesToInteger(lengthArray);
System.arraycopy(data, 4, id, 0, 16);
byte[] cuttedData;
int offset = 20;
while (length > 0) {
cuttedData = new byte[length];
System.arraycopy(data, offset, cuttedData, 0, length);
MessageAttribute ma = MessageAttribute.parseCommonHeader(cuttedData);
addMessageAttribute(ma);
length -= ma.getLength();
offset += ma.getLength();
}
} catch (UtilityException ue) {
throw new MessageAttributeParsingException("Parsing error");
}
}
开发者ID:tking,项目名称:JSTUN,代码行数:21,代码来源:MessageHeader.java
示例8: parseHeader
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public static MessageHeader parseHeader(byte[] data) throws MessageHeaderParsingException {
try {
MessageHeader mh = new MessageHeader();
byte[] typeArray = new byte[2];
System.arraycopy(data, 0, typeArray, 0, 2);
int type = Utility.twoBytesToInteger(typeArray);
switch (type) {
case BINDINGREQUEST: mh.setType(MessageHeaderType.BindingRequest); LOGGER.debug("Binding Request received."); break;
case BINDINGRESPONSE: mh.setType(MessageHeaderType.BindingResponse); LOGGER.debug("Binding Response received."); break;
case BINDINGERRORRESPONSE: mh.setType(MessageHeaderType.BindingErrorResponse); LOGGER.debug("Binding Error Response received."); break;
case SHAREDSECRETREQUEST: mh.setType(MessageHeaderType.SharedSecretRequest); LOGGER.debug("Shared Secret Request received."); break;
case SHAREDSECRETRESPONSE: mh.setType(MessageHeaderType.SharedSecretResponse); LOGGER.debug("Shared Secret Response received."); break;
case SHAREDSECRETERRORRESPONSE: mh.setType(MessageHeaderType.SharedSecretErrorResponse); LOGGER.debug("Shared Secret Error Response received.");break;
default: throw new MessageHeaderParsingException("Message type " + type + "is not supported");
}
return mh;
} catch (UtilityException ue) {
throw new MessageHeaderParsingException("Parsing error");
}
}
开发者ID:tking,项目名称:JSTUN,代码行数:21,代码来源:MessageHeader.java
示例9: test
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public DiscoveryInfo test() throws UtilityException, SocketException, UnknownHostException, IOException, MessageAttributeParsingException, MessageAttributeException, MessageHeaderParsingException{
ma = null;
ca = null;
nodeNatted = true;
socketTest1 = null;
di = new DiscoveryInfo(sourceIaddress);
if (test1()) {
if (test2()) {
if (test1Redo()) {
test3();
}
}
}
socketTest1.close();
return di;
}
开发者ID:tking,项目名称:JSTUN,代码行数:20,代码来源:DiscoveryTest.java
示例10: parse
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public static UnknownAttribute parse(byte[] data) throws MessageAttributeParsingException {
try {
UnknownAttribute result = new UnknownAttribute();
if (data.length % 4 != 0) throw new MessageAttributeParsingException("Data array too short");
for (int i = 0; i < data.length; i += 4) {
byte[] temp = new byte[4];
System.arraycopy(data, i, temp, 0, 4);
long attri = Utility.fourBytesToLong(temp);
result.addAttribute(MessageAttribute.intToType(attri));
}
return result;
} catch (UtilityException ue) {
throw new MessageAttributeParsingException("Parsing error");
}
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:16,代码来源:UnknownAttribute.java
示例11: getBytes
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public byte[] getBytes() throws UtilityException {
byte[] result = new byte[lengthValue + 4];
// message attribute header
// type
System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
// length
System.arraycopy(Utility.integerToTwoBytes(lengthValue), 0, result, 2, 2);
return result;
}
开发者ID:idwanglu2010,项目名称:openfire,代码行数:10,代码来源:Dummy.java
示例12: parseCommonHeader
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public static MessageAttribute parseCommonHeader(byte[] data) throws MessageAttributeParsingException {
try {
byte[] typeArray = new byte[2];
System.arraycopy(data, 0, typeArray, 0, 2);
int type = Utility.twoBytesToInteger(typeArray);
byte[] lengthArray = new byte[2];
System.arraycopy(data, 2, lengthArray, 0, 2);
int lengthValue = Utility.twoBytesToInteger(lengthArray);
byte[] valueArray = new byte[lengthValue];
System.arraycopy(data, 4, valueArray, 0, lengthValue);
MessageAttribute ma;
switch (type) {
case MAPPEDADDRESS: ma = MappedAddress.parse(valueArray); break;
case RESPONSEADDRESS: ma = ResponseAddress.parse(valueArray); break;
case CHANGEREQUEST: ma = ChangeRequest.parse(valueArray); break;
case SOURCEADDRESS: ma = SourceAddress.parse(valueArray); break;
case CHANGEDADDRESS: ma = ChangedAddress.parse(valueArray); break;
case USERNAME: ma = Username.parse(valueArray); break;
case PASSWORD: ma = Password.parse(valueArray); break;
case MESSAGEINTEGRITY: ma = MessageIntegrity.parse(valueArray); break;
case ERRORCODE: ma = ErrorCode.parse(valueArray); break;
case UNKNOWNATTRIBUTE: ma = UnknownAttribute.parse(valueArray); break;
case REFLECTEDFROM: ma = ReflectedFrom.parse(valueArray); break;
default:
if (type <= 0x7fff) {
throw new UnknownMessageAttributeException("Unkown mandatory message attribute", intToType(type));
} else {
LOGGER.debug("MessageAttribute with type " + type + " unkown.");
ma = Dummy.parse(valueArray);
break;
}
}
return ma;
} catch (UtilityException ue) {
throw new MessageAttributeParsingException("Parsing error");
}
}
开发者ID:tking,项目名称:JSTUN,代码行数:38,代码来源:MessageAttribute.java
示例13: generateTransactionID
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public void generateTransactionID() throws UtilityException {
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 0, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 2, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 4, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 6, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 8, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 10, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 12, 2);
System.arraycopy(Utility.integerToTwoBytes((int)(Math.random() * 65536)), 0, id, 14, 2);
}
开发者ID:tking,项目名称:JSTUN,代码行数:11,代码来源:MessageHeader.java
示例14: Candidate
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public Candidate(Address address, short componentId) throws SocketException, UnknownHostException, UtilityException {
this.socket = new DatagramSocket(0, address.getInetAddress());
this.type = CandidateType.Local;
this.componentId = componentId;
this.priority = 0;
this.base = this;
this.isInUse = false;
}
开发者ID:tking,项目名称:JSTUN,代码行数:9,代码来源:Candidate.java
示例15: test
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public void test() throws UtilityException, SocketException, UnknownHostException, IOException, MessageAttributeParsingException, MessageAttributeException, MessageHeaderParsingException {
initialSocket = new DatagramSocket();
initialSocket.connect(InetAddress.getByName(stunServer), port);
initialSocket.setSoTimeout(timeout);
if (bindingCommunicationInitialSocket()) {
return;
}
BindingLifetimeTask task = new BindingLifetimeTask();
timer.schedule(task, binarySearchLifetime);
LOGGER.debug("Timer scheduled initially: " + binarySearchLifetime + ".");
}
开发者ID:tking,项目名称:JSTUN,代码行数:13,代码来源:BindingLifetimeTest.java
示例16: bindingCommunicationInitialSocket
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
private boolean bindingCommunicationInitialSocket() throws UtilityException, IOException, MessageHeaderParsingException, MessageAttributeParsingException {
MessageHeader sendMH = new MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
sendMH.generateTransactionID();
ChangeRequest changeRequest = new ChangeRequest();
sendMH.addMessageAttribute(changeRequest);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length, InetAddress.getByName(stunServer), port);
initialSocket.send(send);
LOGGER.debug("Binding Request sent.");
MessageHeader receiveMH = new MessageHeader();
while (!(receiveMH.equalTransactionID(sendMH))) {
DatagramPacket receive = new DatagramPacket(new byte[200], 200);
initialSocket.receive(receive);
receiveMH = MessageHeader.parseHeader(receive.getData());
receiveMH.parseAttributes(receive.getData());
}
ma = (MappedAddress) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress);
ErrorCode ec = (ErrorCode) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
if (ec != null) {
LOGGER.debug("Message header contains an Errorcode message attribute.");
return true;
}
if (ma == null) {
LOGGER.debug("Response does not contain a Mapped Address message attribute.");
return true;
}
return false;
}
开发者ID:tking,项目名称:JSTUN,代码行数:31,代码来源:BindingLifetimeTest.java
示例17: bindingCommunicationInitialSocket
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
private boolean bindingCommunicationInitialSocket(final DatagramSocket socket) throws UtilityException, IOException, MessageHeaderParsingException, MessageAttributeParsingException {
MessageHeader sendMH = new MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
sendMH.setTransactionID(mUniqueId);
ChangeRequest changeRequest = new ChangeRequest();
sendMH.addMessageAttribute(changeRequest);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length, InetAddress.getByName(mStunServer), mPort);
socket.send(send);
if (DEBUG) {
Log.i(TAG, "Binding Request sent.");
}
final byte[] buf = new byte[256];
MessageHeader receiveMH = new MessageHeader();
while (!(receiveMH.equalTransactionID(sendMH))) {
DatagramPacket receive = new DatagramPacket(buf, buf.length);
socket.receive(receive);
receiveMH = MessageHeader.parseHeader(receive.getData());
receiveMH.parseAttributes(receive.getData());
}
mMappedAddress = (MappedAddress) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress);
ErrorCode ec = (ErrorCode) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
if (ec != null) {
if (DEBUG) {
Log.e(TAG, "Message header contains an ErrorCode message attribute. ErrorCode=" + ec);
}
return false;
}
if (mMappedAddress == null) {
if (DEBUG) {
Log.e(TAG, "Response does not contain a Mapped Address message attribute.");
}
return false;
}
if (DEBUG) {
Log.i(TAG, "Address: " + mMappedAddress.getAddress().toString());
Log.i(TAG, "Port: " + mMappedAddress.getPort());
}
return true;
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:44,代码来源:StunClient.java
示例18: getLength
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public int getLength() throws UtilityException {
int length = getBytes().length;
return length;
}
开发者ID:tking,项目名称:JSTUN,代码行数:5,代码来源:MessageAttribute.java
示例19: getLength
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public int getLength() throws UtilityException {
return getBytes().length;
}
开发者ID:tking,项目名称:JSTUN,代码行数:4,代码来源:MessageHeader.java
示例20: getAddress
import de.javawi.jstun.util.UtilityException; //导入依赖的package包/类
public Address getAddress() throws UtilityException {
return new Address(socket.getLocalAddress().getAddress());
}
开发者ID:tking,项目名称:JSTUN,代码行数:4,代码来源:Candidate.java
注:本文中的de.javawi.jstun.util.UtilityException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论