本文整理汇总了Java中de.javawi.jstun.util.UtilityException类的典型用法代码示例。如果您正苦于以下问题:Java UtilityException类的具体用法?Java UtilityException怎么用?Java UtilityException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UtilityException类属于de.javawi.jstun.util包,在下文中一共展示了UtilityException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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");
}
}
示例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;
}
示例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");
}
}
示例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;
}
示例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");
}
}
示例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);
}
示例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;
}
示例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 + ".");
}