本文整理汇总了Java中javax.bluetooth.DataElement.URL属性的典型用法代码示例。如果您正苦于以下问题:Java DataElement.URL属性的具体用法?Java DataElement.URL怎么用?Java DataElement.URL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.bluetooth.DataElement
的用法示例。
在下文中一共展示了DataElement.URL属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataSize
public long getDataSize(DataElement data) {
int type = data.getDataType();
long size = getPureDataSize(data);
if ((type == DataElement.NULL) || (type == DataElement.BOOL)
|| (type == DataElement.INT_1) || (type == DataElement.U_INT_1)
|| (type == DataElement.INT_2) || (type == DataElement.U_INT_2)
|| (type == DataElement.INT_4) || (type == DataElement.U_INT_4)
|| (type == DataElement.INT_8) || (type == DataElement.U_INT_8)
|| (type == DataElement.INT_16)
|| (type == DataElement.U_INT_16)
|| (type == DataElement.UUID)) {
return size + 1;
} else if ((type == DataElement.DATSEQ)
|| (type == DataElement.DATALT) || (type == DataElement.STRING)
|| (type == DataElement.URL)) {
if (size <= 0xffL) {
return size + 2;
} else if (size <= 0xffffL) {
return size + 3;
} else if (size <= 0xffffffffL) {
return size + 5;
} else {
throw new RuntimeException("Data size is too large.");
}
} else {
throw new RuntimeException("Unexpected data type.");
}
}
示例2: getPureDataSize
public long getPureDataSize(DataElement data) {
switch (data.getDataType()) {
case DataElement.NULL:
return 0;
case DataElement.BOOL:
case DataElement.INT_1:
case DataElement.U_INT_1:
return 1;
case DataElement.INT_2:
case DataElement.U_INT_2:
return 2;
case DataElement.INT_4:
case DataElement.U_INT_4:
return 4;
case DataElement.INT_8:
case DataElement.U_INT_8:
return 8;
case DataElement.INT_16:
case DataElement.U_INT_16:
return 16;
case DataElement.DATSEQ:
case DataElement.DATALT:
long size = 0;
Enumeration elements = (Enumeration)data.getValue();
while (elements.hasMoreElements()) {
size += getDataSize((DataElement)elements.nextElement());
}
return size;
case DataElement.STRING:
case DataElement.URL:
return ((String)data.getValue()).length();
case DataElement.UUID:
return 16;
default:
throw new RuntimeException("Unknown data type.");
}
}
示例3: validateConversion
/**
* Tests for simple types
*/
private void validateConversion(DataElement element) throws IOException {
int type = element.getDataType();
switch (type) {
case DataElement.NULL:
validateConversion(element, 0, type, 0, null);
break;
case DataElement.BOOL:
validateConversion(element, 0, type, element.getBoolean() ? 1 : 0, null);
break;
case DataElement.U_INT_1:
case DataElement.INT_1:
case DataElement.U_INT_2:
case DataElement.INT_2:
case DataElement.U_INT_4:
case DataElement.INT_4:
case DataElement.INT_8:
validateConversion(element, 0, type, element.getLong(), null);
break;
case DataElement.U_INT_8:
case DataElement.U_INT_16:
case DataElement.INT_16:
validateConversion(element, 0, type, 0, (byte[]) element.getValue());
break;
case DataElement.UUID:
validateConversion(element, 0, type, 0, Utils.UUIDToByteArray((UUID) element.getValue()));
break;
case DataElement.STRING:
byte[] bs = Utils.getUTF8Bytes((String) element.getValue());
validateConversion(element, 0, type, 0, bs);
break;
case DataElement.URL:
byte[] bu = Utils.getASCIIBytes((String) element.getValue());
validateConversion(element, 0, type, 0, bu);
break;
default:
throw new IllegalArgumentException();
}
}
示例4: sdpServiceAddAttribute
private void sdpServiceAddAttribute(long handle, char handleType, int attrID, DataElement element) throws ServiceRegistrationException {
int type = element.getDataType();
switch (type) {
case DataElement.NULL:
sdpServiceAddAttribute(handle, handleType, attrID, type, 0, null);
break;
case DataElement.BOOL:
sdpServiceAddAttribute(handle, handleType, attrID, type, element.getBoolean() ? 1 : 0, null);
break;
case DataElement.U_INT_1:
case DataElement.INT_1:
case DataElement.U_INT_2:
case DataElement.INT_2:
case DataElement.U_INT_4:
case DataElement.INT_4:
case DataElement.INT_8:
sdpServiceAddAttribute(handle, handleType, attrID, type, element.getLong(), null);
break;
case DataElement.U_INT_8:
case DataElement.U_INT_16:
case DataElement.INT_16:
sdpServiceAddAttribute(handle, handleType, attrID, type, 0, (byte[]) element.getValue());
break;
case DataElement.UUID:
sdpServiceAddAttribute(handle, handleType, attrID, type, 0, Utils.UUIDToByteArray((UUID) element.getValue()));
break;
case DataElement.STRING:
byte[] bs = Utils.getUTF8Bytes((String) element.getValue());
sdpServiceAddAttribute(handle, handleType, attrID, type, 0, bs);
break;
case DataElement.URL:
byte[] bu = Utils.getASCIIBytes((String) element.getValue());
sdpServiceAddAttribute(handle, handleType, attrID, type, 0, bu);
break;
case DataElement.DATSEQ:
case DataElement.DATALT:
sdpServiceSequenceAttributeStart(handle, handleType, attrID, type);
for (Enumeration e = (Enumeration) element.getValue(); e.hasMoreElements();) {
DataElement child = (DataElement) e.nextElement();
sdpServiceAddAttribute(handle, handleType, -1, child);
}
sdpServiceSequenceAttributeEnd(handle, handleType, attrID);
break;
default:
throw new IllegalArgumentException();
}
}
示例5: equals
public static boolean equals(DataElement de1, DataElement de2) {
if ((de1 == null) || (de2 == null)) {
return false;
}
try {
if (de1.getDataType() != de2.getDataType()) {
return false;
}
switch (de1.getDataType()) {
case DataElement.U_INT_1:
case DataElement.U_INT_2:
case DataElement.U_INT_4:
case DataElement.INT_1:
case DataElement.INT_2:
case DataElement.INT_4:
case DataElement.INT_8:
return (de1.getLong() == de2.getLong());
case DataElement.URL:
case DataElement.STRING:
case DataElement.UUID:
return de1.getValue().equals(de2.getValue());
case DataElement.INT_16:
case DataElement.U_INT_8:
case DataElement.U_INT_16:
byte[] byteAray1 = (byte[]) de1.getValue();
byte[] byteAray2 = (byte[]) de2.getValue();
if (byteAray1.length != byteAray2.length) {
return false;
}
for (int k = 0; k < byteAray1.length; k++) {
if (byteAray1[k] != byteAray2[k]) {
return false;
}
}
return true;
case DataElement.NULL:
return true;
case DataElement.BOOL:
return (de1.getBoolean() == de2.getBoolean());
case DataElement.DATSEQ:
case DataElement.DATALT:
Enumeration en1 = (Enumeration) de1.getValue();
Enumeration en2 = (Enumeration) de2.getValue();
for (; en1.hasMoreElements() && en2.hasMoreElements();) {
DataElement d1 = (DataElement) en1.nextElement();
DataElement d2 = (DataElement) en2.nextElement();
if (!equals(d1, d2)) {
return false;
}
}
if (en1.hasMoreElements() || en2.hasMoreElements()) {
return false;
}
return true;
default:
return false;
}
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
示例6: assertEquals
public static void assertEquals(String message, DataElement de1, DataElement de2) {
if ((de1 == null) || (de2 == null)) {
fail(message + "NULL elements");
}
assertEquals(message + "Type", de1.getDataType(), de2.getDataType());
switch (de1.getDataType()) {
case DataElement.U_INT_1:
case DataElement.U_INT_2:
case DataElement.U_INT_4:
case DataElement.INT_1:
case DataElement.INT_2:
case DataElement.INT_4:
case DataElement.INT_8:
assertEquals(message + "long", de1.getLong(), de2.getLong());
return;
case DataElement.URL:
case DataElement.STRING:
case DataElement.UUID:
assertEquals(message + "value", de1.getValue(), de2.getValue());
return;
case DataElement.INT_16:
case DataElement.U_INT_8:
case DataElement.U_INT_16:
byte[] byteAray1 = (byte[]) de1.getValue();
byte[] byteAray2 = (byte[]) de2.getValue();
assertEquals(message + "length", byteAray1.length, byteAray2.length);
for (int k = 0; k < byteAray1.length; k++) {
assertEquals(message + "byteAray[" + k + "]", byteAray1[k], byteAray2[k]);
}
return;
case DataElement.NULL:
return;
case DataElement.BOOL:
assertEquals(message + "boolean", de1.getBoolean(), de2.getBoolean());
return;
case DataElement.DATSEQ:
case DataElement.DATALT:
int i = 0;
Enumeration en1 = (Enumeration) de1.getValue();
Enumeration en2 = (Enumeration) de2.getValue();
for (; en1.hasMoreElements() && en2.hasMoreElements();) {
DataElement d1 = (DataElement) en1.nextElement();
DataElement d2 = (DataElement) en2.nextElement();
assertEquals(message + "DataElement[" + i + "]", d1, d2);
i++;
}
if (en1.hasMoreElements() || en2.hasMoreElements()) {
fail(message + "unknown hasMoreElements");
}
return;
default:
fail(message + "unknown type");
}
}