Example usage for java.nio ByteBuffer putDouble

List of usage examples for java.nio ByteBuffer putDouble

Introduction

In this page you can find the example usage for java.nio ByteBuffer putDouble.

Prototype

public abstract ByteBuffer putDouble(double value);

Source Link

Document

Writes the given double to the current position and increases the position by 8.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(100);

    // Put values of different types
    buf.putDouble(12.3D);

    // Reset position for reading
    buf.flip();//from w  w w. ja  va2s.c om

    // Retrieve the values
    double d = buf.getDouble();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);
    bbuf.putDouble(123);

    System.out.println(Arrays.toString(bbuf.array()));
}

From source file:Main.java

public static byte[] createDigest(String passcode, long t1, double q1)
        throws IOException, NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(passcode.getBytes());/*from  www  .  jav a 2  s. co m*/
    ByteBuffer bb = ByteBuffer.allocate(16); //8 bytes for long and double each
    bb.putLong(t1);
    bb.putDouble(q1);
    md.update(bb);
    return md.digest();
}

From source file:org.apache.camel.converter.NIOConverter.java

@Converter
public static ByteBuffer toByteBuffer(Double value) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    buf.putDouble(value);
    return buf;/*  w ww  . j  a v  a 2  s  .  c  o m*/
}

From source file:ConversionUtil.java

public static byte[] convertToByteArray(double value) {
    byte[] bytes = new byte[8];
    ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
    buffer.putDouble(value);
    return buffer.array();
    // buffer.get(bytes);
    // return bytes;
    //return convertToByteArray(Double.doubleToLongBits(value));
}

From source file:org.opensha.commons.util.XMLUtils.java

public static void doubleArrayToXML(Element parent, double[] array, String elName) {
    byte[] bytes = new byte[array.length * 8];
    ByteBuffer buf = ByteBuffer.wrap(bytes);
    for (double val : array)
        buf.putDouble(val);
    byteArrayToXML(parent, buf.array(), elName);
}

From source file:org.mcisb.util.math.MathUtils.java

/**
 * /*from   w ww.j a va  2s  . c om*/
 * @param values
 * @param bigEndian
 * @return String
 */
public static byte[] getBytes(final double[] values, final boolean bigEndian) {
    final byte[] byteArray = new byte[values.length * DOUBLE_LENGTH];
    ByteBuffer buffer = ByteBuffer.wrap(byteArray);
    buffer = buffer.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);

    for (int i = 0; i < values.length; i++) {
        buffer.putDouble(values[i]);
    }

    return buffer.array();
}

From source file:org.pentaho.di.trans.steps.teradatabulkloader.TeraDataBulkLoaderRoutines.java

/**
 * Convert float.//from w ww.  j av  a  2  s.  c om
 *
 * @param d the d
 * @return the byte[]
 */
static byte[] convertFloat(Double d) {
    ByteBuffer b = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
    b.putDouble(d != null ? d : 0);
    return b.array();
}

From source file:hivemall.GeneralLearnerBaseUDTF.java

private static void writeFeatureValue(@Nonnull final ByteBuffer buf, @Nonnull final FeatureValue f) {
    NIOUtils.putString(f.getFeatureAsString(), buf);
    buf.putDouble(f.getValue());
}

From source file:edu.umn.cs.spatialHadoop.indexing.BTRPartitioner.java

@Override
public void write(DataOutput out) throws IOException {
    mbr.write(out);/*from   w w w  .java2s.  c o  m*/
    out.writeInt(columns);
    out.writeInt(rows);
    ByteBuffer bbuffer = ByteBuffer.allocate((xSplits.length + ySplits.length) * 8);
    for (double xSplit : xSplits)
        bbuffer.putDouble(xSplit);
    for (double ySplit : ySplits)
        bbuffer.putDouble(ySplit);
    if (bbuffer.hasRemaining())
        throw new RuntimeException("Did not calculate buffer size correctly");
    out.write(bbuffer.array(), bbuffer.arrayOffset(), bbuffer.position());
}