Package java.nio

Examples of java.nio.ShortBuffer


        byte[] name = new byte[256];
        ByteBuffer buffer = getTableBuffer(nameTag);

        if (buffer != null) {
            ShortBuffer sbuffer = buffer.asShortBuffer();
            sbuffer.get(); // format - not needed.
            short numRecords = sbuffer.get();

            /* The name table uses unsigned shorts. Many of these
             * are known small values that fit in a short.
             * The values that are sizes or offsets into the table could be
             * greater than 32767, so read and store those as ints
             */
            int stringPtr = ((int) sbuffer.get()) & 0xffff;
            for (int i=0; i<numRecords; i++) {
                short platformID = sbuffer.get();
                if (platformID != MS_PLATFORM_ID) {
                    sbuffer.position(sbuffer.position()+5);
                    continue; // skip over this record.
                }
                short encodingID = sbuffer.get();
                short langID     = sbuffer.get();
                short nameID     = sbuffer.get();
                int   nameLen    = ((int) sbuffer.get()) & 0xffff;
                int   namePtr    = (((int) sbuffer.get()) & 0xffff) + stringPtr;

                if (nameID == requestedID) {
                    buffer.position(namePtr);
                    buffer.get(name, 0, nameLen);
                    names.add(makeString(name, nameLen, encodingID));
View Full Code Here


        array.addShort((short) 4);
        MutableShortArray backedByArray = MutableShortArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 8).asShortBuffer();
        MutableShortArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedShortArray bigger = UnboundedShortArray.copyOf(array);
View Full Code Here

        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray());
    }

    @Test
    public void testAddAllNoBackingArray0() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 10).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(ShortArray.unsafeValueOf());
        assertEquals(8, notBackedByArray.length());
        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray());
View Full Code Here

        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray1() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 11).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(ShortArray.unsafeValueOf((short) 5));
        assertEquals(9, notBackedByArray.length());
        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray());
View Full Code Here

        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray2() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 11).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(ShortArray.unsafeValueOf((short) 5, (short) 5));
        assertEquals(10, notBackedByArray.length());
        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());
View Full Code Here

        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray3() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 11).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        try {
            notBackedByArray.addAll(ShortArray.unsafeValueOf((short) 5, (short) 5, (short) 5));
            fail();
View Full Code Here

    short cmd_data_size = (short) cmdDataBuffer.limit();

    IntBuffer rspDataBuffer = IntBuffer.wrap(rsp_data);

    rsp_data_size[0] = RSP_DATA_SIZE;
    ShortBuffer rspDataSizeBuffer = ShortBuffer.wrap(rsp_data_size);

    rspDataSizeBuffer.put(0, (short) RSP_DATA_SIZE);
    ecode = pm3CsafeCP.tkcmdsetCSAFE_command(unit_address, cmd_data_size,
        cmdDataBuffer, rspDataSizeBuffer, rspDataBuffer);

    if (ecode != 0) {
      PM3Exception pm3Exception = createException(ecode);
View Full Code Here

    num_communicating[0] = 0;
    short startAddress = 0;
    byte toWrap[] = TKCMDSET_PM3_PRODUCT_NAME2.getBytes();
    ByteBuffer byteBuffer = ByteBuffer.wrap(toWrap);
   
    ShortBuffer numCommunicatingBuffer = ShortBuffer
        .wrap(num_communicating);
   
    // ecode = pm3ddicp.tkcmdsetDDI_discover_pm3s(toWrap, 0, startAddress,
    // num_communicating, 0);
    ecode = pm3ddicp.tkcmdsetDDI_discover_pm3s(byteBuffer, startAddress,
        numCommunicatingBuffer);
    if (ecode == 0 && numCommunicatingBuffer.get(0) > 0) {
      // We discovered one or more PM3's
      numNewPM3Devices = numCommunicatingBuffer.get(0);
   
    }
    slf4jLogger.info(String.format("Number of %s is: %d",
        TKCMDSET_PM3_PRODUCT_NAME2, numNewPM3Devices));
   
    // Look for old style PM3 devices, starting numbering after the previous
    byteBuffer = ByteBuffer.wrap(TKCMDSET_PM3_PRODUCT_NAME.getBytes());
    ecode = pm3ddicp.tkcmdsetDDI_discover_pm3s(byteBuffer,
        numCommunicatingBuffer.get(0), numCommunicatingBuffer);
   
    if (ecode == 0 && numCommunicatingBuffer.get(0) > 0) {
      // We discovered one or more old PM3's
      numOldPM3Devices = numCommunicatingBuffer.get(0) - numNewPM3Devices;
    }
    slf4jLogger.info(String.format("Number of %s is: %d",
        TKCMDSET_PM3_PRODUCT_NAME, numOldPM3Devices));
   
    // Look for PM4 devices
    byteBuffer = ByteBuffer.wrap(TKCMDSET_PM4_PRODUCT_NAME.getBytes());
    ecode = pm3ddicp.tkcmdsetDDI_discover_pm3s(byteBuffer,
        numCommunicatingBuffer.get(0), numCommunicatingBuffer);
    if (ecode == 0 && numCommunicatingBuffer.get(0) > 0) {
      // We discovered one or more PM4's
      numPM4Devices = numCommunicatingBuffer.get(0) - numNewPM3Devices
          - numOldPM3Devices;
    }
    slf4jLogger.info(String.format("Number of %s is: %d",
        TKCMDSET_PM4_PRODUCT_NAME, numPM4Devices));
   
    numberPmsOnline = numCommunicatingBuffer.get(0);
     
    if(numberPmsOnline > 0){
      slf4jLogger.info(String.format("PM's discovered: %s\n", numberPmsOnline));     
    }else{
      slf4jLogger.error(String.format("No PMs found"));   
View Full Code Here

    private MutableShortArray array;

    @Before
    public void setUp() throws Exception {
        short[] a = new short[] {0, 0, 1, 1, 2, 1, 2, 3, 3, 4};
        ShortBuffer buffer = ShortBuffer.wrap(a, 1, 9);
        array = MutableShortArray.valueOf(buffer);
        array = serializeAndDeserialize(array); // Test serialization.
        array = Arrays.synchronizedArray(array, array);    // Test synchronized array.
        array = array.offset(1);
    }
View Full Code Here

        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray());
        MutableShortArray backedByArray = MutableShortArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 8).asShortBuffer();
        MutableShortArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedShortArray tooBig = UnboundedShortArray.copyOf(array);
View Full Code Here

TOP

Related Classes of java.nio.ShortBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.