Package java.nio

Examples of java.nio.DoubleBuffer


        buf.clear();
        buf.order(ByteOrder.BIG_ENDIAN);
    }

    public void testAsDoubleBuffer() {
        DoubleBuffer doubleBuffer;
        byte bytes[] = new byte[8];
        double value;

        // test BIG_ENDIAN double buffer, read
        buf.clear();
        buf.order(ByteOrder.BIG_ENDIAN);
        doubleBuffer = buf.asDoubleBuffer();
        assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.order());
        while (doubleBuffer.remaining() > 0) {
            buf.get(bytes);
            value = doubleBuffer.get();
            if (!(Double.isNaN(bytes2double(bytes, buf.order())) && Double
                    .isNaN(value))) {
                assertEquals(bytes2double(bytes, buf.order()), value, 0.00);
            }
        }

        // test LITTLE_ENDIAN double buffer, read
        buf.clear();
        buf.order(ByteOrder.LITTLE_ENDIAN);
        doubleBuffer = buf.asDoubleBuffer();
        assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.order());
        while (doubleBuffer.remaining() > 0) {
            buf.get(bytes);
            value = doubleBuffer.get();
            if (!(Double.isNaN(bytes2double(bytes, buf.order())) && Double
                    .isNaN(value))) {
                assertEquals(bytes2double(bytes, buf.order()), value, 0.00);
            }
        }

        if (!buf.isReadOnly()) {
            // test BIG_ENDIAN double buffer, write
            buf.clear();
            buf.order(ByteOrder.BIG_ENDIAN);
            doubleBuffer = buf.asDoubleBuffer();
            assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.order());
            while (doubleBuffer.remaining() > 0) {
                value = (double) doubleBuffer.remaining();
                doubleBuffer.put(value);
                buf.get(bytes);
                assertTrue(Arrays.equals(bytes, double2bytes(value, buf.order())));
            }

            // test LITTLE_ENDIAN double buffer, write
            buf.clear();
            buf.order(ByteOrder.LITTLE_ENDIAN);
            doubleBuffer = buf.asDoubleBuffer();
            assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.order());
            while (doubleBuffer.remaining() > 0) {
                value = (double) doubleBuffer.remaining();
                doubleBuffer.put(value);
                buf.get(bytes);
                assertTrue(Arrays.equals(bytes, double2bytes(value, buf.order())));
            }
        }
View Full Code Here


            DoubleBuffer.wrap((double[])null, -1, 0);
            fail("Should throw NPE"); //$NON-NLS-1$
        } catch (NullPointerException e) {
        }

        DoubleBuffer buf = DoubleBuffer.wrap(array, 2, 16);
        assertEquals(buf.position(), 2);
        assertEquals(buf.limit(), 18);
        assertEquals(buf.capacity(), 20);
    }
View Full Code Here

        } catch (ReadOnlyBufferException e) {
        }
    }

    public void testHashCode() {
        DoubleBuffer duplicate = buf.duplicate();
        assertEquals(buf.hashCode(), duplicate.hashCode());
    }
View Full Code Here

            // expected
        }
    }

    public void testPutDoubleBuffer() {
        DoubleBuffer other = DoubleBuffer.allocate(1);
        try {
            buf.put(other);
            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
        } catch (ReadOnlyBufferException e) {
            // expected
View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
          arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 8);
          DoubleBuffer doublebuf = buf.asDoubleBuffer();
          double[] doubleArray = new double[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
            doubleArray[i - arrayStart] = Double.longBitsToDouble(this.longHeap.heap[i]);
          }
          doublebuf.put(doubleArray);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        }

      } else if (null != aSofa.getSofaURI()) {
View Full Code Here

        int numpoints = buffer.getInt();
        int dimensions = shapeType == shapeType.MULTIPOINTZ && !flatGeometry ? 3 : 2;
        CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(numpoints, dimensions);

        DoubleBuffer dbuffer = buffer.asDoubleBuffer();
        double[] ordinates = new double[numpoints * 2];
        dbuffer.get(ordinates);
        for (int t = 0; t < numpoints; t++) {
            cs.setOrdinate(t, 0, ordinates[t * 2]);
            cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
        }

        if (dimensions > 2) {
            dbuffer.position(dbuffer.position() + 2);

            dbuffer.get(ordinates, 0, numpoints);
            for (int t = 0; t < numpoints; t++) {
                cs.setOrdinate(t, 2, ordinates[t]); // z
            }
        }

View Full Code Here

        // sequences
        CoordinateSequence[] lines = new CoordinateSequence[numParts];
        int finish, start = 0;
        int length = 0;
        boolean clonePoint = false;
        final DoubleBuffer doubleBuffer = buffer.asDoubleBuffer();
        for (int part = 0; part < numParts; part++) {
            start = partOffsets[part];

            if (part == (numParts - 1)) {
                finish = numPoints;
            } else {
                finish = partOffsets[part + 1];
            }

            length = finish - start;
            int xyLength = length;
            if (length == 1) {
                length = 2;
                clonePoint = true;
            } else {
                clonePoint = false;
            }

            CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(length, dimensions);
            double[] xy = new double[xyLength * 2];
            doubleBuffer.get(xy);
            for (int i = 0; i < xyLength; i++) {
                cs.setOrdinate(i, 0, xy[i * 2]);
                cs.setOrdinate(i, 1, xy[i * 2 + 1]);
            }

            if (clonePoint) {
                cs.setOrdinate(1, 0, cs.getOrdinate(0, 0));
                cs.setOrdinate(1, 1, cs.getOrdinate(0, 1));
            }

            lines[part] = cs;
        }

        // if we have another coordinate, read and add to the coordinate
        // sequences
        if (dimensions == 3) {
            // z min, max
            // buffer.position(buffer.position() + 2 * 8);
            doubleBuffer.position(doubleBuffer.position() + 2);
            for (int part = 0; part < numParts; part++) {
                start = partOffsets[part];

                if (part == (numParts - 1)) {
                    finish = numPoints;
                } else {
                    finish = partOffsets[part + 1];
                }

                length = finish - start;
                if (length == 1) {
                    length = 2;
                    clonePoint = true;
                } else {
                    clonePoint = false;
                }

                double[] z = new double[length];
                doubleBuffer.get(z);
                for (int i = 0; i < length; i++) {
                    lines[part].setOrdinate(i, 2, z[i]);
                }

            }
View Full Code Here

     */
    private CoordinateSequence readCoordinates(final ByteBuffer buffer,
            final int numPoints, final int dimensions) {
        CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(numPoints, dimensions);

        DoubleBuffer dbuffer = buffer.asDoubleBuffer();
        double[] ordinates = new double[numPoints * 2];
        dbuffer.get(ordinates);
        for (int t = 0; t < numPoints; t++) {
            cs.setOrdinate(t, 0, ordinates[t * 2]);
            cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
        }
       
        if (dimensions > 2) {
            // z
            dbuffer.position(dbuffer.position() + 2);
            dbuffer.get(ordinates, 0, numPoints);

            for (int t = 0; t < numPoints; t++) {
                cs.setOrdinate(t, 2, ordinates[t]);
            }
        }
View Full Code Here

   
    LongBuffer lBuffer = buffer.asLongBuffer();
    lBuffer.position(1);
    System.out.println(Memory.getPosition(lBuffer));
   
    DoubleBuffer dBuffer = buffer.asDoubleBuffer();
    dBuffer.position(1);
    System.out.println(Memory.getPosition(dBuffer));
  }
View Full Code Here

   * @param src the source array.
   * @param srcOffset the offset into the source array.
   * @param dst the destination Buffer, its position is used as an offset.
   * @param numElements the number of elements to copy. */
  public static void copy (double[] src, int srcOffset, Buffer dst, int numElements) {
    DoubleBuffer buffer = null;
    if (dst instanceof ByteBuffer)
      buffer = ((ByteBuffer)dst).asDoubleBuffer();
    else if (dst instanceof DoubleBuffer) buffer = (DoubleBuffer)dst;
    if (buffer == null) throw new GdxRuntimeException("dst must be a ByteBuffer or DoubleBuffer");

    int oldPosition = buffer.position();
    buffer.put(src, srcOffset, numElements);
    buffer.position(oldPosition);
    buffer.limit(oldPosition + numElements);
  }
View Full Code Here

TOP

Related Classes of java.nio.DoubleBuffer

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.