Example usage for java.io DataInputStream readDouble

List of usage examples for java.io DataInputStream readDouble

Introduction

In this page you can find the example usage for java.io DataInputStream readDouble.

Prototype

public final double readDouble() throws IOException 

Source Link

Document

See the general contract of the readDouble method of DataInput.

Usage

From source file:org.hyperic.hq.measurement.agent.server.SenderThread.java

private static Record decodeRecord(String val) throws IOException {
    ByteArrayInputStream bIs;/*ww w . j a v a2  s.  c  o  m*/
    DataInputStream dIs;
    MetricValue measVal;
    boolean isAvail;
    int derivedID, dsnID;
    long retTime;

    bIs = new ByteArrayInputStream(Base64.decode(val));
    dIs = new DataInputStream(bIs);

    derivedID = dIs.readInt();
    retTime = dIs.readLong();
    dsnID = dIs.readInt();

    measVal = new MetricValue(dIs.readDouble(), retTime);
    return new Record(dsnID, measVal, derivedID);
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }//from w  w w .j  av a2s.com
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

From source file:com.anhth12.word2vec.VocabWord.java

public VocabWord read(DataInputStream dis) throws IOException {
    this.wordFrequency.set(dis.readDouble());
    return this;
}

From source file:org.deeplearning4j.models.word2vec.VocabWord.java

public VocabWord read(DataInputStream dos) throws IOException {
    this.wordFrequency.set(dos.readDouble());
    return this;
}

From source file:org.apache.hama.monitor.ZKCollector.java

@Override
public MetricsRecord harvest() throws Exception {
    final String path = this.reference.get().path;
    final ZooKeeper zk = this.reference.get().zk;
    LOG.debug("Searching " + path + " in zookeeper.");
    Stat stat = zk.exists(path, false);//from  w  w  w  .  jav  a2s .co  m
    if (null == stat)
        return null; // no need to collect data.
    List<String> children = zk.getChildren(path, false);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Leaves size is " + children.size() + " total znodes in list: " + children);
    }

    // TODO: metrics record contains multiple metrics (1 to many)
    // data is stored under zk e.g. /path/to/metrics/jvm/...
    // within jvm folder metrics is stored in a form of name, value pair
    final MetricsRecord record = reference.get().record;
    if (null != children) {
        for (String child : children) {
            LOG.info("metrics -> " + child);
            // <metricsName_d> indicates data type is double
            String dataType = suffix(child);
            byte[] dataInBytes = zk.getData(path + "/" + child, false, stat);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Data length (in byte): " + dataInBytes.length);
            }
            DataInputStream input = null;
            try {
                String name = removeSuffix(child);
                input = new DataInputStream(new ByteArrayInputStream(dataInBytes));
                if ("d".equals(dataType)) {
                    double dv = input.readDouble();
                    LOG.info("metrics " + name + " value:" + dv);
                    record.add(new Metric<Double>(name, dv));
                } else if ("f".equals(dataType)) {
                    float fv = input.readFloat();
                    LOG.info("metrics " + name + " value:" + fv);
                    record.add(new Metric<Float>(name, fv));
                } else if ("i".equals(dataType)) {
                    int iv = input.readInt();
                    LOG.info("metrics " + name + " value:" + iv);
                    record.add(new Metric<Integer>(name, iv));
                } else if ("l".equals(dataType)) {
                    long lv = input.readLong();
                    LOG.info("metrics " + name + " value:" + lv);
                    record.add(new Metric<Long>(name, lv));
                } else if ("b".equals(dataType)) {
                    LOG.info("metrics" + name + " value:" + Arrays.toString(dataInBytes));
                    record.add(new Metric<byte[]>(name, dataInBytes));
                } else {
                    LOG.warn("Unkown data type for metrics name: " + child);
                }
            } finally {
                input.close();
            }
        }
    }
    return record;
}

From source file:RealFunctionValidation.java

public static SummaryStatistics assessAccuracy(final Method method, final DataInputStream in,
        final DataOutputStream out)
        throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    if (method.getReturnType() != Double.TYPE) {
        throw new IllegalArgumentException("method must return a double");
    }/*w  ww.j a v  a 2s  .c  o  m*/

    final Class<?>[] types = method.getParameterTypes();
    for (int i = 0; i < types.length; i++) {
        if (!types[i].isPrimitive()) {
            final StringBuilder builder = new StringBuilder();
            builder.append("argument #").append(i + 1).append(" of method ").append(method.getName())
                    .append("must be of primitive of type");
            throw new IllegalArgumentException(builder.toString());
        }
    }

    final SummaryStatistics stat = new SummaryStatistics();
    final Object[] parameters = new Object[types.length];
    while (true) {
        try {
            for (int i = 0; i < parameters.length; i++) {
                parameters[i] = readAndWritePrimitiveValue(in, out, types[i]);
            }
            final double expected = in.readDouble();
            if (FastMath.abs(expected) > 1E-16) {
                final Object value = method.invoke(null, parameters);
                final double actual = ((Double) value).doubleValue();
                final double err = FastMath.abs(actual - expected);
                final double ulps = err / FastMath.ulp(expected);
                out.writeDouble(expected);
                out.writeDouble(actual);
                out.writeDouble(ulps);
                stat.addValue(ulps);
            }
        } catch (EOFException e) {
            break;
        }
    }
    return stat;
}

From source file:com.yahoo.pulsar.testclient.LoadSimulationClient.java

private void decodeProducerOptions(final TradeConfiguration tradeConf, final DataInputStream inputStream)
        throws Exception {
    tradeConf.topic = inputStream.readUTF();
    tradeConf.size = inputStream.readInt();
    tradeConf.rate = inputStream.readDouble();
}

From source file:org.structr.core.graph.SyncCommand.java

private static Object readObject(final DataInputStream inputStream, final byte type) throws IOException {

    switch (type) {

    case 0://  w w w  .  j a  v a2  s.  c  o m
    case 1:
        return inputStream.readByte();

    case 2:
    case 3:
        return inputStream.readShort();

    case 4:
    case 5:
        return inputStream.readInt();

    case 6:
    case 7:
        return inputStream.readLong();

    case 8:
    case 9:
        return inputStream.readFloat();

    case 10:
    case 11:
        return inputStream.readDouble();

    case 12:
    case 13:
        return inputStream.readChar();

    case 14:
    case 15:
        return new String(deserializeData(inputStream), "UTF-8");

    // this doesn't work with very long strings
    //return inputStream.readUTF();

    case 16:
    case 17:
        return inputStream.readBoolean();
    }

    return null;
}

From source file:org.slc.sli.dal.encrypt.AesCipher.java

private Object decryptBinary(String data, Class<?> expectedType) {
    byte[] decoded = decryptToBytes(data);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(decoded));
    try {//from w w w.j a  v a2  s . c om
        if (Boolean.class.equals(expectedType)) {
            return dis.readBoolean();
        } else if (Integer.class.equals(expectedType)) {
            return dis.readInt();
        } else if (Long.class.equals(expectedType)) {
            return dis.readLong();
        } else if (Double.class.equals(expectedType)) {
            return dis.readDouble();
        } else {
            throw new RuntimeException("Unsupported type: " + expectedType.getCanonicalName());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            dis.close();
        } catch (IOException e) {
            LOG.error("Unable to close DataInputStream!");
        }
    }
}

From source file:edu.fullerton.ldvplugin.ExternalPlotManager.java

public double[][] rdBinXYFile(File in) throws FileNotFoundException, IOException, WebUtilException {
    ArrayList<double[]> data = new ArrayList<>();
    DataInputStream input = new DataInputStream(new FileInputStream(in));

    try {/*ww w  .j  av  a 2  s  . co  m*/
        while (true) {
            double[] it = new double[2];
            it[0] = input.readDouble();
            it[1] = input.readDouble();
            data.add(it);
        }
    } catch (EOFException eof) {
        // we're good
    } catch (IOException ex) {
        String ermsg = "Reading binary xy data from file: " + ex.getClass().getSimpleName();
        ermsg += " - " + ex.getLocalizedMessage();
        throw new WebUtilException(ermsg);
    }
    // return as array
    double[][] ret = new double[1][2];
    ret = data.toArray(ret);
    return ret;
}