当前位置: 首页>>代码示例>>Java>>正文


Java DataElement.addElement方法代码示例

本文整理汇总了Java中javax.bluetooth.DataElement.addElement方法的典型用法代码示例。如果您正苦于以下问题:Java DataElement.addElement方法的具体用法?Java DataElement.addElement怎么用?Java DataElement.addElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.bluetooth.DataElement的用法示例。


在下文中一共展示了DataElement.addElement方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public static synchronized byte[] serialize(ServiceRecord record) {
    DataElement seq = new DataElement(DataElement.DATSEQ);
    int[] attrIDs = record.getAttributeIDs();
    for (int i = 0; i < attrIDs.length; i++) {
        DataElement attrID = new DataElement(DataElement.U_INT_2,
                attrIDs[i]);
        DataElement attrValue = record.getAttributeValue(attrIDs[i]);
        if (attrValue != null) {
            seq.addElement(attrID);
            seq.addElement(attrValue);
        }
    }
    try {
        return des.serialize(seq);
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:19,代码来源:ServiceRecordSerializer.java

示例2: ClientServiceSearchAttributeTransaction

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public ClientServiceSearchAttributeTransaction(JavaSDPClient client, int transactionID,
        SDPResponseListener listener, int[] attrSet,
        UUID[] uuidSet) {
    super(client, SDPClientTransaction.SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST, transactionID,
            listener);
    attrData = new DataElement(DataElement.DATSEQ);
    uuidData = new DataElement(DataElement.DATSEQ);
    for (int i = 0; i < attrSet.length; i++) {
        attrData.addElement(new DataElement(DataElement.U_INT_2,
                attrSet[i]));
    }
    for (int i = 0; i < uuidSet.length; i++) {
        uuidData.addElement(new DataElement(DataElement.UUID,
                uuidSet[i]));
    }
    parameterLength = super.client.getConnection().getReaderWriter().getDataSize(attrData) +
            super.client.getConnection().getReaderWriter().getDataSize(uuidData) + 2;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:19,代码来源:ClientServiceSearchAttributeTransaction.java

示例3: testDATSEQ

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public void testDATSEQ() throws IOException {
	DataElement seq1 = new DataElement(DataElement.DATSEQ);
	seq1.addElement(new DataElement(DataElement.STRING, "BlueCove-seq1"));
	seq1.addElement(new DataElement(DataElement.U_INT_1, 0x12));
	seq1.addElement(new DataElement(DataElement.URL, "http://blueCove/"));
	seq1.addElement(new DataElement(DataElement.STRING, stringUTFData));
	seq1.addElement(new DataElement(DataElement.UUID, new UUID("B10C0BE1111111111111111111110001", false)));

	DataElement seq2 = new DataElement(DataElement.DATSEQ);
	seq2.addElement(new DataElement(DataElement.U_INT_8, new byte[] { 1, -2, 3, 4, -5, 6, 7, -8 }));
	seq2.addElement(new DataElement(DataElement.STRING, getLongString(0x100 + 2)));
	seq2.addElement(new DataElement(DataElement.U_INT_2, 0x14));

	DataElement seq3 = new DataElement(DataElement.DATSEQ);
	seq3.addElement(new DataElement(DataElement.U_INT_4, 0x15));
	seq3.addElement(new DataElement(DataElement.STRING, stringUTFData));
	seq3.addElement(new DataElement(DataElement.UUID, new UUID(0x1105)));
	seq3.addElement(new DataElement(DataElement.INT_8, 0x16));

	seq1.addElement(seq2);
	seq1.addElement(seq3);
	seq1.addElement(new DataElement(DataElement.INT_4, 0x1BCDEF35l));
	validateConversion(seq1);
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:25,代码来源:SDPStreamTest.java

示例4: dataElementCopy

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
private DataElement dataElementCopy(DataElement original) {
    if ((original.getDataType() == DataElement.DATSEQ)
            || (original.getDataType() == DataElement.DATALT)) {
        DataElement copy = new DataElement(original.getDataType());
        Enumeration elements = (Enumeration) original.getValue();

        while (elements.hasMoreElements()) {
            copy.addElement(dataElementCopy((DataElement)
                    elements.nextElement()));
        }
        return copy;
    } else {
        return original;
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:16,代码来源:ServiceRecordImpl.java

示例5: ClientServiceSearchTransaction

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public ClientServiceSearchTransaction(JavaSDPClient client, int transactionID,
        SDPResponseListener listener, UUID[] uuidSet) {
    super(client, SDPClientTransaction.SDP_SERVICE_SEARCH_REQUEST, transactionID, listener);
    serviceSearchPattern = new DataElement(DataElement.DATSEQ);
    for (int i = 0; i < uuidSet.length; i++) {
        serviceSearchPattern.addElement(new DataElement(
                DataElement.UUID, uuidSet[i]));
    }
    parameterLength = super.des.getDataSize(serviceSearchPattern) + 2;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:11,代码来源:ClientServiceSearchTransaction.java

示例6: ClientServiceAttributeTransaction

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
ClientServiceAttributeTransaction(JavaSDPClient client, int transactionID,
        SDPResponseListener listener, int recordHandle,
        int[] attrSet) {
    super(client, SDPClientTransaction.SDP_SERVICE_ATTRIBUTE_REQUEST, transactionID, listener);
    serviceRecordHandle = recordHandle;
    attributeIDList = new DataElement(DataElement.DATSEQ);
    for (int i = 0; i < attrSet.length; i++) {
        attributeIDList.addElement(new DataElement(
                DataElement.U_INT_2, attrSet[i]));
    }
    parameterLength = super.client.getConnection().getReaderWriter().getDataSize(attributeIDList) + 6;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:13,代码来源:ClientServiceAttributeTransaction.java

示例7: populateL2CAPAttributes

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
void populateL2CAPAttributes(int handle, int channel, UUID uuid, String name) {

		this.populateAttributeValue(BluetoothConsts.ServiceRecordHandle, new DataElement(DataElement.U_INT_4, handle));

		/*
		 * service class ID list
		 */

		DataElement serviceClassIDList = new DataElement(DataElement.DATSEQ);
		serviceClassIDList.addElement(new DataElement(DataElement.UUID, uuid));

		this.populateAttributeValue(BluetoothConsts.ServiceClassIDList, serviceClassIDList);

		/*
		 * protocol descriptor list
		 */
		DataElement protocolDescriptorList = new DataElement(DataElement.DATSEQ);

		DataElement L2CAPDescriptor = new DataElement(DataElement.DATSEQ);
		L2CAPDescriptor.addElement(new DataElement(DataElement.UUID, BluetoothConsts.L2CAP_PROTOCOL_UUID));
		L2CAPDescriptor.addElement(new DataElement(DataElement.U_INT_2, channel));
		protocolDescriptorList.addElement(L2CAPDescriptor);

		this.populateAttributeValue(BluetoothConsts.ProtocolDescriptorList, protocolDescriptorList);

		if (name != null) {
			this.populateAttributeValue(BluetoothConsts.AttributeIDServiceName, new DataElement(DataElement.STRING,
					name));
		}
	}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:31,代码来源:ServiceRecordImpl.java

示例8: testDATSEQ16

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public void testDATSEQ16() throws IOException {
	DataElement seq = new DataElement(DataElement.DATSEQ);
	// INT_8 = 9 bytes;
	int nElements = (0xFF / 9) + 1;
	for (int i = 0; i < nElements; i++) {
		seq.addElement(new DataElement(DataElement.INT_8, i));
	}
	int l = SDPOutputStream.getLength(seq);
	assertTrue("DATSEQ16 len(" + l + ")>0xFF", l > 0xFF);
	assertTrue("DATSEQ16 len(" + l + ")<0xFFFF", l < 0xFFFF);
	validateConversion(seq);
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:13,代码来源:SDPStreamTest.java

示例9: testDATSEQ32

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public void testDATSEQ32() throws IOException {
	DataElement seq = new DataElement(DataElement.DATSEQ);
	// INT_8 = 9 bytes;
	int nElements = (0xFFFF / 9) + 1;
	for (int i = 0; i < nElements; i++) {
		seq.addElement(new DataElement(DataElement.INT_8, i));
	}
	int l = SDPOutputStream.getLength(seq);
	assertTrue("DATSEQ32 len(" + l + ")>0xFFFF", l > 0xFFFF);
	validateConversion(seq);
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:12,代码来源:SDPStreamTest.java

示例10: populateServicesRecordAttributeValues

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public boolean populateServicesRecordAttributeValues(ServiceRecordImpl serviceRecord, int[] attrIDs) throws IOException {
    if (attrIDs.length > ATTR_RETRIEVABLE_MAX) {
        throw new IllegalArgumentException();
    }
    boolean anyRetrived = false;
    for (int i = 0; i < attrIDs.length; i++) {
        int id = attrIDs[i];
        try {
            byte[] sdpStruct = getServiceAttribute(id, serviceRecord.getHandle());
            if (sdpStruct != null) {
                if (BluetoothStackWIDCOMMSDPInputStream.debug) {
                    DebugLog.debug("decode attribute " + id + " Ox" + Integer.toHexString(id));
                }
                DataElement element = (new BluetoothStackWIDCOMMSDPInputStream(new ByteArrayInputStream(sdpStruct))).readElement();

                // Do special case conversion for only one element in the
                // list.
                if (id == BluetoothConsts.ProtocolDescriptorList) {
                    Enumeration protocolsSeqEnum = (Enumeration) element.getValue();
                    if (protocolsSeqEnum.hasMoreElements()) {
                        DataElement protocolElement = (DataElement) protocolsSeqEnum.nextElement();
                        if (protocolElement.getDataType() != DataElement.DATSEQ) {
                            DataElement newMainSeq = new DataElement(DataElement.DATSEQ);
                            newMainSeq.addElement(element);
                            element = newMainSeq;
                        }
                    }
                }

                serviceRecord.populateAttributeValue(id, element);
                anyRetrived = true;
            } else {
                if (BluetoothStackWIDCOMMSDPInputStream.debug) {
                    DebugLog.debug("no data for attribute " + id + " Ox" + Integer.toHexString(id));
                }
            }
        } catch (Throwable e) {
            if (BluetoothStackWIDCOMMSDPInputStream.debug) {
                DebugLog.error("error populate attribute " + id + " Ox" + Integer.toHexString(id), e);
            }
        }
    }
    return anyRetrived;
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:45,代码来源:BluetoothStackWIDCOMM.java

示例11: populateRFCOMMAttributes

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
/**
 * Internal implementation function
 */
void populateRFCOMMAttributes(long handle, int channel, UUID uuid, String name, boolean obex) {

	this.populateAttributeValue(BluetoothConsts.ServiceRecordHandle, new DataElement(DataElement.U_INT_4, handle));

	/*
	 * service class ID list
	 */

	DataElement serviceClassIDList = new DataElement(DataElement.DATSEQ);
	serviceClassIDList.addElement(new DataElement(DataElement.UUID, uuid));
	if (!obex) {
		serviceClassIDList.addElement(new DataElement(DataElement.UUID, BluetoothConsts.SERIAL_PORT_UUID));
	}

	this.populateAttributeValue(BluetoothConsts.ServiceClassIDList, serviceClassIDList);

	/*
	 * protocol descriptor list
	 */

	DataElement protocolDescriptorList = new DataElement(DataElement.DATSEQ);

	DataElement L2CAPDescriptor = new DataElement(DataElement.DATSEQ);
	L2CAPDescriptor.addElement(new DataElement(DataElement.UUID, BluetoothConsts.L2CAP_PROTOCOL_UUID));
	protocolDescriptorList.addElement(L2CAPDescriptor);

	DataElement RFCOMMDescriptor = new DataElement(DataElement.DATSEQ);
	RFCOMMDescriptor.addElement(new DataElement(DataElement.UUID, BluetoothConsts.RFCOMM_PROTOCOL_UUID));
	RFCOMMDescriptor.addElement(new DataElement(DataElement.U_INT_1, channel));
	protocolDescriptorList.addElement(RFCOMMDescriptor);

	if (obex) {
		DataElement OBEXDescriptor = new DataElement(DataElement.DATSEQ);
		OBEXDescriptor.addElement(new DataElement(DataElement.UUID, BluetoothConsts.OBEX_PROTOCOL_UUID));
		protocolDescriptorList.addElement(OBEXDescriptor);
	}

	this.populateAttributeValue(BluetoothConsts.ProtocolDescriptorList, protocolDescriptorList);

	if (name != null) {
		this.populateAttributeValue(BluetoothConsts.AttributeIDServiceName, new DataElement(DataElement.STRING,
				name));
	}
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:48,代码来源:ServiceRecordImpl.java

示例12: testServiceClassIDList

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public void testServiceClassIDList() throws IOException {
    /*
     * DATSEQ { UUID 0000110100001000800000805f9b34fb (SERIAL_PORT) }
     */
    DataElement expect = new DataElement(DataElement.DATSEQ);
    expect.addElement(new DataElement(DataElement.UUID, new UUID("1101", true)));

    BluetoothStackWIDCOMMSDPOutputStream bos = new BluetoothStackWIDCOMMSDPOutputStream();
    int valueSize = BluetoothStackWIDCOMMSDPInputStream.MAX_ATTR_LEN_OLD;
    bos.writeInt(valueSize);

    bos.writeInt(1); // num_elem
    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_UUID); // type
    bos.writeInt(2); // len
    bos.writeInt(1); // start_of_seq
    bos.writeLong(0x1101, 2);
    bos.flush();

    DataElement element = (new BluetoothStackWIDCOMMSDPInputStream(new ByteArrayInputStream(bos.toByteArray())))
            .readElement();

    assertEquals("Element stream 1 item", expect, element);

    /*
     * DATSEQ { UUID 0000110100001000800000805f9b34fb (SERIAL_PORT) UUID 0000120300001000800000805f9b34fb }
     */
    expect.addElement(new DataElement(DataElement.UUID, new UUID("1203", true)));

    bos = new BluetoothStackWIDCOMMSDPOutputStream();
    bos.writeInt(valueSize);

    bos.writeInt(2); // num_elem
    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_UUID); // type
    bos.writeInt(2); // len
    bos.writeInt(1); // start_of_seq
    bos.writeLong(0x1101, 2);
    bos.write0(valueSize - 2);
    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_UUID); // type
    bos.writeInt(2); // len
    bos.writeInt(0); // start_of_seq
    bos.writeLong(0x1203, 2);
    bos.flush();

    element = (new BluetoothStackWIDCOMMSDPInputStream(new ByteArrayInputStream(bos.toByteArray()))).readElement();

    assertEquals("Element stream 2 items", expect, element);
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:48,代码来源:BluetoothStackWIDCOMMSDPInputStreamTest.java

示例13: testProtocolDescriptorList

import javax.bluetooth.DataElement; //导入方法依赖的package包/类
public void testProtocolDescriptorList() throws IOException {
    /*
     * DATSEQ { DATSEQ { UUID 0000010000001000800000805f9b34fb (L2CAP) } DATSEQ { UUID
     * 0000000300001000800000805f9b34fb (RFCOMM) U_INT_1 0x9 } DATSEQ { UUID 0000000800001000800000805f9b34fb (OBEX) } }
     */

    DataElement expect = new DataElement(DataElement.DATSEQ);
    DataElement e1 = new DataElement(DataElement.DATSEQ);
    e1.addElement(new DataElement(DataElement.UUID, new UUID("0100", true)));
    DataElement e2 = new DataElement(DataElement.DATSEQ);
    e2.addElement(new DataElement(DataElement.UUID, new UUID("0003", true)));
    e2.addElement(new DataElement(DataElement.U_INT_1, 9));
    DataElement e3 = new DataElement(DataElement.DATSEQ);
    e3.addElement(new DataElement(DataElement.UUID, new UUID("0008", true)));
    expect.addElement(e1);
    expect.addElement(e2);
    expect.addElement(e3);

    BluetoothStackWIDCOMMSDPOutputStream bos = new BluetoothStackWIDCOMMSDPOutputStream();

    int valueSize = BluetoothStackWIDCOMMSDPInputStream.MAX_ATTR_LEN_OLD;
    bos.writeInt(valueSize);

    bos.writeInt(4); // num_elem

    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_UUID); // type
    bos.writeInt(2); // len
    bos.writeInt(1); // start_of_seq
    bos.writeLong(0x0100, 2);
    bos.write0(valueSize - 2);

    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_UUID); // type
    bos.writeInt(2); // len
    bos.writeInt(1); // start_of_seq
    bos.writeLong(0x0003, 2);
    bos.write0(valueSize - 2);

    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_INT); // type
    bos.writeInt(1); // len
    bos.writeInt(0); // start_of_seq
    bos.writeLong(9, 1);
    bos.write0(valueSize - 1);

    bos.writeInt(BluetoothStackWIDCOMMSDPInputStream.ATTR_TYPE_UUID); // type
    bos.writeInt(2); // len
    bos.writeInt(1); // start_of_seq
    bos.writeLong(0x0008, 2);
    bos.write0(valueSize - 2);

    bos.flush();

    DataElement element = (new BluetoothStackWIDCOMMSDPInputStream(new ByteArrayInputStream(bos.toByteArray())))
            .readElement();

    assertEquals("Element stream", expect, element);
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:57,代码来源:BluetoothStackWIDCOMMSDPInputStreamTest.java


注:本文中的javax.bluetooth.DataElement.addElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。