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:com.alphabetbloc.accessmrs.services.SyncManager.java

private void insertObservations(DataInputStream zdis) throws Exception {
    long start = System.currentTimeMillis();

    SimpleDateFormat output = new SimpleDateFormat("MMM dd, yyyy");
    SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd");

    SQLiteDatabase db = DbProvider.getDb();
    InsertHelper ih = new InsertHelper(db, DataModel.OBSERVATIONS_TABLE);
    int ptIdIndex = ih.getColumnIndex(DataModel.KEY_PATIENT_ID);
    int obsTextIndex = ih.getColumnIndex(DataModel.KEY_VALUE_TEXT);
    int obsNumIndex = ih.getColumnIndex(DataModel.KEY_VALUE_NUMERIC);
    int obsDateIndex = ih.getColumnIndex(DataModel.KEY_VALUE_DATE);
    int obsIntIndex = ih.getColumnIndex(DataModel.KEY_VALUE_INT);
    int obsFieldIndex = ih.getColumnIndex(DataModel.KEY_FIELD_NAME);
    int obsTypeIndex = ih.getColumnIndex(DataModel.KEY_DATA_TYPE);
    int obsEncDateIndex = ih.getColumnIndex(DataModel.KEY_ENCOUNTER_DATE);

    db.beginTransaction();/* w  ww .  j a  v  a  2  s . c o  m*/
    sLoopProgress.set(0);
    int count = 0;
    try {
        sLoopCount.set(zdis.readInt());
        if (App.DEBUG)
            Log.v(TAG, "insertObservations icount: " + sLoopCount);
        for (int i = 1; i < sLoopCount.get() + 1; i++) {

            ih.prepareForInsert();
            ih.bind(ptIdIndex, zdis.readInt());
            ih.bind(obsFieldIndex, zdis.readUTF());
            byte dataType = zdis.readByte();
            if (dataType == DataModel.TYPE_STRING) {
                ih.bind(obsTextIndex, zdis.readUTF());
            } else if (dataType == DataModel.TYPE_INT) {
                ih.bind(obsIntIndex, zdis.readInt());
            } else if (dataType == DataModel.TYPE_DOUBLE) {
                ih.bind(obsNumIndex, zdis.readDouble());
            } else if (dataType == DataModel.TYPE_DATE) {
                ih.bind(obsDateIndex, parseDate(input, output, zdis.readUTF()));
            }

            ih.bind(obsTypeIndex, dataType);
            ih.bind(obsEncDateIndex, parseDate(input, output, zdis.readUTF()));
            ih.execute();

            count++;
            sLoopProgress.set(count * 2);
        }

        db.setTransactionSuccessful();
    } finally {
        ih.close();

        db.endTransaction();
    }

    long end = System.currentTimeMillis();
    if (App.DEBUG)
        Log.v("SYNC BENCHMARK",
                String.format("Total Observations: \n%d\nTotal Time: \n%d\nRecords per second: \n%.2f",
                        sLoopCount.get(), (int) (end - start),
                        1000 * (double) sLoopCount.get() / (double) (end - start)));

}

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

private void handle(final byte command, final DataInputStream inputStream, final DataOutputStream outputStream)
        throws Exception {
    final TradeConfiguration tradeConf = new TradeConfiguration();
    tradeConf.command = command;/*from  w ww .ja v  a2 s  . c  o  m*/
    switch (command) {
    case CHANGE_COMMAND:
        // Change the topic's settings if it exists. Report whether the
        // topic was found on this server.
        decodeProducerOptions(tradeConf, inputStream);
        if (topicsToTradeUnits.containsKey(tradeConf.topic)) {
            topicsToTradeUnits.get(tradeConf.topic).change(tradeConf);
            outputStream.write(FOUND_TOPIC);
        } else {
            outputStream.write(NO_SUCH_TOPIC);
        }
        break;
    case STOP_COMMAND:
        // Stop the topic if it exists. Report whether the topic was found,
        // and whether it was already stopped.
        tradeConf.topic = inputStream.readUTF();
        if (topicsToTradeUnits.containsKey(tradeConf.topic)) {
            final boolean wasStopped = topicsToTradeUnits.get(tradeConf.topic).stop.getAndSet(true);
            outputStream.write(wasStopped ? REDUNDANT_COMMAND : FOUND_TOPIC);
        } else {
            outputStream.write(NO_SUCH_TOPIC);
        }
        break;
    case TRADE_COMMAND:
        // Create the topic. It is assumed that the topic does not already
        // exist.
        decodeProducerOptions(tradeConf, inputStream);
        final TradeUnit tradeUnit = new TradeUnit(tradeConf, client, producerConf, consumerConf, payloadCache);
        topicsToTradeUnits.put(tradeConf.topic, tradeUnit);
        executor.submit(() -> {
            try {
                tradeUnit.start();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        // Tell controller topic creation is finished.
        outputStream.write(NO_SUCH_TOPIC);
        break;
    case CHANGE_GROUP_COMMAND:
        // Change the settings of all topics belonging to a group. Report
        // the number of topics changed.
        decodeGroupOptions(tradeConf, inputStream);
        tradeConf.size = inputStream.readInt();
        tradeConf.rate = inputStream.readDouble();
        // See if a topic belongs to this tenant and group using this regex.
        final String groupRegex = ".*://.*/" + tradeConf.tenant + "/" + tradeConf.group + "-.*/.*";
        int numFound = 0;
        for (Map.Entry<String, TradeUnit> entry : topicsToTradeUnits.entrySet()) {
            final String destination = entry.getKey();
            final TradeUnit unit = entry.getValue();
            if (destination.matches(groupRegex)) {
                ++numFound;
                unit.change(tradeConf);
            }
        }
        outputStream.writeInt(numFound);
        break;
    case STOP_GROUP_COMMAND:
        // Stop all topics belonging to a group. Report the number of topics
        // stopped.
        decodeGroupOptions(tradeConf, inputStream);
        // See if a topic belongs to this tenant and group using this regex.
        final String regex = ".*://.*/" + tradeConf.tenant + "/" + tradeConf.group + "-.*/.*";
        int numStopped = 0;
        for (Map.Entry<String, TradeUnit> entry : topicsToTradeUnits.entrySet()) {
            final String destination = entry.getKey();
            final TradeUnit unit = entry.getValue();
            if (destination.matches(regex) && !unit.stop.getAndSet(true)) {
                ++numStopped;
            }
        }
        outputStream.writeInt(numStopped);
        break;
    default:
        throw new IllegalArgumentException("Unrecognized command code received: " + command);
    }
    outputStream.flush();
}

From source file:org.openmrs.module.odkconnector.serialization.web.PatientWebConnectorTest.java

@Test
public void serialize_shouldDisplayAllPatientInformation() throws Exception {

    // compose url
    URL u = new URL(SERVER_URL + "/module/odkconnector/download/patients.form");

    // setup http url connection
    HttpURLConnection connection = (HttpURLConnection) u.openConnection();
    connection.setDoOutput(true);/*  w w w .j  a  v a2  s .  c om*/
    connection.setRequestMethod("POST");
    connection.setConnectTimeout(10000);
    connection.setReadTimeout(10000);
    connection.addRequestProperty("Content-type", "application/octet-stream");

    // write auth details to connection
    DataOutputStream outputStream = new DataOutputStream(new GZIPOutputStream(connection.getOutputStream()));
    outputStream.writeUTF("admin");
    outputStream.writeUTF("test");
    outputStream.writeBoolean(true);
    outputStream.writeInt(2);
    outputStream.writeInt(1);
    outputStream.close();

    DataInputStream inputStream = new DataInputStream(new GZIPInputStream(connection.getInputStream()));
    Integer responseStatus = inputStream.readInt();

    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();

    int count = 0;
    byte[] buffer = new byte[1024];
    while ((count = inputStream.read(buffer)) > 0) {
        arrayOutputStream.write(buffer, 0, count);
    }
    arrayOutputStream.close();
    inputStream.close();

    File file = new File("/home/nribeka/connector.data");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(arrayOutputStream.toByteArray());
    fos.close();

    inputStream = new DataInputStream(new FileInputStream(file));

    if (responseStatus == HttpURLConnection.HTTP_OK) {

        // total number of patients
        Integer patientCounter = inputStream.readInt();
        System.out.println("Patient Counter: " + patientCounter);
        for (int j = 0; j < patientCounter; j++) {
            System.out.println("=================Patient=====================");
            System.out.println("Patient Id: " + inputStream.readInt());
            System.out.println("Family Name: " + inputStream.readUTF());
            System.out.println("Middle Name: " + inputStream.readUTF());
            System.out.println("Last Name: " + inputStream.readUTF());
            System.out.println("Gender: " + inputStream.readUTF());
            System.out.println("Birth Date: " + inputStream.readUTF());
            System.out.println("Identifier: " + inputStream.readUTF());
            System.out.println("Patients: " + j + " out of " + patientCounter);
        }

        Integer obsCounter = inputStream.readInt();
        System.out.println("Observation Counter: " + obsCounter);
        for (int j = 0; j < obsCounter; j++) {
            System.out.println("==================Observation=================");
            System.out.println("Patient Id: " + inputStream.readInt());
            System.out.println("Concept Name: " + inputStream.readUTF());

            byte type = inputStream.readByte();
            if (type == ObsSerializer.TYPE_STRING)
                System.out.println("Value: " + inputStream.readUTF());
            else if (type == ObsSerializer.TYPE_INT)
                System.out.println("Value: " + inputStream.readInt());
            else if (type == ObsSerializer.TYPE_DOUBLE)
                System.out.println("Value: " + inputStream.readDouble());
            else if (type == ObsSerializer.TYPE_DATE)
                System.out.println("Value: " + inputStream.readUTF());
            System.out.println("Time: " + inputStream.readUTF());
            System.out.println("Obs: " + j + " out of: " + obsCounter);
        }
        Integer formCounter = inputStream.readInt();
        System.out.println("Form Counter: " + formCounter);
        for (int j = 0; j < formCounter; j++) {
            System.out.println("==================Observation=================");
            System.out.println("Patient Id: " + inputStream.readInt());
            System.out.println("Concept Name: " + inputStream.readUTF());

            byte type = inputStream.readByte();
            if (type == ObsSerializer.TYPE_STRING)
                System.out.println("Value: " + inputStream.readUTF());
            else if (type == ObsSerializer.TYPE_INT)
                System.out.println("Value: " + inputStream.readInt());
            else if (type == ObsSerializer.TYPE_DOUBLE)
                System.out.println("Value: " + inputStream.readDouble());
            else if (type == ObsSerializer.TYPE_DATE)
                System.out.println("Value: " + inputStream.readUTF());
            System.out.println("Time: " + inputStream.readUTF());
            System.out.println("Form: " + j + " out of: " + formCounter);
        }
    }
    inputStream.close();
}

From source file:ClassFile.java

public boolean read(DataInputStream dis) throws IOException {
    int len;/*  w w w . j ava  2s .  c o m*/
    char c;

    type = dis.readByte();
    switch (type) {
    case CLASS:
        name = "Class";
        index1 = dis.readShort();
        index2 = -1;
        break;
    case FIELDREF:
        name = "Field Reference";
        index1 = dis.readShort();
        index2 = dis.readShort();
        break;
    case METHODREF:
        name = "Method Reference";
        index1 = dis.readShort();
        index2 = dis.readShort();
        break;
    case INTERFACE:
        name = "Interface Method Reference";
        index1 = dis.readShort();
        index2 = dis.readShort();
        break;
    case NAMEANDTYPE:
        name = "Name and Type";
        index1 = dis.readShort();
        index2 = dis.readShort();
        break;
    case STRING:
        name = "String";
        index1 = dis.readShort();
        index2 = -1;
        break;
    case INTEGER:
        name = "Integer";
        intValue = dis.readInt();
        break;
    case FLOAT:
        name = "Float";
        floatValue = dis.readFloat();
        break;
    case LONG:
        name = "Long";
        longValue = dis.readLong();
        break;
    case DOUBLE:
        name = "Double";
        doubleValue = dis.readDouble();
        break;
    case ASCIZ:
    case UNICODE:
        if (type == ASCIZ)
            name = "ASCIZ";
        else
            name = "UNICODE";

        StringBuffer xxBuf = new StringBuffer();

        len = dis.readShort();
        while (len > 0) {
            c = (char) (dis.readByte());
            xxBuf.append(c);
            len--;
        }
        strValue = xxBuf.toString();
        break;
    default:
        System.out.println("Warning bad type.");
    }
    return (true);
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Deserializes a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream//from   w w  w .  j  a va 2s  . c o m
 * @param id the property id for the new property entry
 * @return the property entry
 * @throws IOException if an I/O error occurs.
 */
public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException {
    NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id);
    // type and modcount
    int type = in.readInt();
    entry.setModCount((short) ((type >> 16) & 0x0ffff));
    type &= 0x0ffff;
    entry.setType(type);

    // multiValued
    entry.setMultiValued(in.readBoolean());
    // definitionId
    in.readUTF();
    // values
    int count = in.readInt(); // count
    InternalValue[] values = new InternalValue[count];
    String[] blobIds = new String[count];
    for (int i = 0; i < count; i++) {
        InternalValue val;
        switch (type) {
        case PropertyType.BINARY:
            int size = in.readInt();
            if (size == BINARY_IN_DATA_STORE) {
                val = InternalValue.create(dataStore, in.readUTF());
            } else if (size == BINARY_IN_BLOB_STORE) {
                blobIds[i] = in.readUTF();
                try {
                    if (blobStore instanceof ResourceBasedBLOBStore) {
                        val = InternalValue
                                .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i]));
                    } else {
                        val = InternalValue.create(blobStore.get(blobIds[i]));
                    }
                } catch (IOException e) {
                    if (errorHandling.ignoreMissingBlobs()) {
                        log.warn("Ignoring error while reading blob-resource: " + e);
                        val = InternalValue.create(new byte[0]);
                    } else {
                        throw e;
                    }
                } catch (Exception e) {
                    throw new IOException("Unable to create property value: " + e.toString());
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                in.readFully(data);
                val = InternalValue.create(data);
            }
            break;
        case PropertyType.DOUBLE:
            val = InternalValue.create(in.readDouble());
            break;
        case PropertyType.LONG:
            val = InternalValue.create(in.readLong());
            break;
        case PropertyType.BOOLEAN:
            val = InternalValue.create(in.readBoolean());
            break;
        case PropertyType.NAME:
            val = InternalValue.create(readQName(in));
            break;
        case PropertyType.REFERENCE:
            val = InternalValue.create(readUUID(in));
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len = in.readInt();
            byte[] bytes = new byte[len];
            in.readFully(bytes);
            val = InternalValue.valueOf(new String(bytes, "UTF-8"), type);
        }
        values[i] = val;
    }
    entry.setValues(values);
    entry.setBlobIds(blobIds);

    return entry;
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Deserializes a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream/*from  ww w.j  a va 2  s .  c  o  m*/
 * @param id the property id for the new property entry
 * @return the property entry
 * @throws IOException if an I/O error occurs.
 */
public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException {
    NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id);
    // type and modcount
    int type = in.readInt();
    entry.setModCount((short) ((type >> 16) & 0x0ffff));
    type &= 0x0ffff;
    entry.setType(type);

    // multiValued
    entry.setMultiValued(in.readBoolean());
    // definitionId
    entry.setPropDefId(PropDefId.valueOf(in.readUTF()));
    // values
    int count = in.readInt(); // count
    InternalValue[] values = new InternalValue[count];
    String[] blobIds = new String[count];
    for (int i = 0; i < count; i++) {
        InternalValue val;
        switch (type) {
        case PropertyType.BINARY:
            int size = in.readInt();
            if (size == BINARY_IN_DATA_STORE) {
                val = InternalValue.create(dataStore, in.readUTF());
            } else if (size == BINARY_IN_BLOB_STORE) {
                blobIds[i] = in.readUTF();
                try {
                    if (blobStore instanceof ResourceBasedBLOBStore) {
                        val = InternalValue
                                .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i]));
                    } else {
                        val = InternalValue.create(blobStore.get(blobIds[i]));
                    }
                } catch (IOException e) {
                    if (errorHandling.ignoreMissingBlobs()) {
                        log.warn("Ignoring error while reading blob-resource: " + e);
                        val = InternalValue.create(new byte[0]);
                    } else {
                        throw e;
                    }
                } catch (Exception e) {
                    throw new IOException("Unable to create property value: " + e.toString());
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                in.readFully(data);
                val = InternalValue.create(data);
            }
            break;
        case PropertyType.DOUBLE:
            val = InternalValue.create(in.readDouble());
            break;
        case PropertyType.DECIMAL:
            val = InternalValue.create(readDecimal(in));
            break;
        case PropertyType.LONG:
            val = InternalValue.create(in.readLong());
            break;
        case PropertyType.BOOLEAN:
            val = InternalValue.create(in.readBoolean());
            break;
        case PropertyType.NAME:
            val = InternalValue.create(readQName(in));
            break;
        case PropertyType.WEAKREFERENCE:
        case PropertyType.REFERENCE:
            val = InternalValue.create(readID(in));
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len = in.readInt();
            byte[] bytes = new byte[len];
            in.readFully(bytes);
            val = InternalValue.valueOf(new String(bytes, "UTF-8"), type);
        }
        values[i] = val;
    }
    entry.setValues(values);
    entry.setBlobIds(blobIds);

    return entry;
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Deserializes a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream//from w  ww.j a  va2  s.  c o  m
 * @param id the property id for the new property entry
 * @return the property entry
 * @throws IOException if an I/O error occurs.
 */
public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException {
    NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id);
    // type and modcount
    int type = in.readInt();
    entry.setModCount((short) ((type >> 16) & 0x0ffff));
    type &= 0x0ffff;
    entry.setType(type);

    // multiValued
    entry.setMultiValued(in.readBoolean());
    // definitionId
    entry.setPropDefId(PropDefId.valueOf(in.readUTF()));
    // values
    int count = in.readInt(); // count
    InternalValue[] values = new InternalValue[count];
    String[] blobIds = new String[count];
    for (int i = 0; i < count; i++) {
        InternalValue val;
        switch (type) {
        case PropertyType.BINARY:
            int size = in.readInt();
            if (size == BINARY_IN_DATA_STORE) {
                val = InternalValue.create(dataStore, in.readUTF());
            } else if (size == BINARY_IN_BLOB_STORE) {
                blobIds[i] = in.readUTF();
                try {
                    if (blobStore instanceof ResourceBasedBLOBStore) {
                        val = InternalValue
                                .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i]));
                    } else {
                        val = InternalValue.create(blobStore.get(blobIds[i]));
                    }
                } catch (IOException e) {
                    if (errorHandling.ignoreMissingBlobs()) {
                        log.warn("Ignoring error while reading blob-resource: " + e);
                        val = InternalValue.create(new byte[0]);
                    } else {
                        throw e;
                    }
                } catch (Exception e) {
                    throw new IOException("Unable to create property value: " + e.toString());
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                in.readFully(data);
                val = InternalValue.create(data);
            }
            break;
        case PropertyType.DOUBLE:
            val = InternalValue.create(in.readDouble());
            break;
        case PropertyType.DECIMAL:
            val = InternalValue.create(readDecimal(in));
            break;
        case PropertyType.LONG:
            val = InternalValue.create(in.readLong());
            break;
        case PropertyType.BOOLEAN:
            val = InternalValue.create(in.readBoolean());
            break;
        case PropertyType.NAME:
            val = InternalValue.create(readQName(in));
            break;
        case PropertyType.WEAKREFERENCE:
        case PropertyType.REFERENCE:
            val = InternalValue.create(readUUID(in));
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len = in.readInt();
            byte[] bytes = new byte[len];
            in.readFully(bytes);
            val = InternalValue.valueOf(new String(bytes, "UTF-8"), type);
        }
        values[i] = val;
    }
    entry.setValues(values);
    entry.setBlobIds(blobIds);

    return entry;
}

From source file:se.llbit.chunky.renderer.scene.Scene.java

/**
 * Merge a render dump into this scene/*from ww  w  . j ava 2 s  .c  om*/
 * @param dumpFile
 * @param renderListener
 */
public void mergeDump(File dumpFile, RenderStatusListener renderListener) {
    int dumpSpp;
    long dumpTime;
    DataInputStream in = null;
    try {
        in = new DataInputStream(new GZIPInputStream(new FileInputStream(dumpFile)));

        String task = "Merging render dump";
        renderListener.setProgress(task, 1, 0, 2);
        Log.info("Loading render dump " + dumpFile.getAbsolutePath());
        int dumpWidth = in.readInt();
        int dumpHeight = in.readInt();
        if (dumpWidth != width || dumpHeight != height) {
            Log.warn("Render dump discarded: incorrect widht or height!");
            in.close();
            return;
        }
        dumpSpp = in.readInt();
        dumpTime = in.readLong();

        double sa = spp / (double) (spp + dumpSpp);
        double sb = 1 - sa;

        for (int x = 0; x < width; ++x) {
            renderListener.setProgress(task, x + 1, 0, width);
            for (int y = 0; y < height; ++y) {
                samples[(y * width + x) * 3 + 0] = samples[(y * width + x) * 3 + 0] * sa + in.readDouble() * sb;
                samples[(y * width + x) * 3 + 1] = samples[(y * width + x) * 3 + 1] * sa + in.readDouble() * sb;
                samples[(y * width + x) * 3 + 2] = samples[(y * width + x) * 3 + 2] * sa + in.readDouble() * sb;
                finalizePixel(x, y);
            }
        }
        Log.info("Render dump loaded");

        // Update render status
        spp += dumpSpp;
        renderTime += dumpTime;
        renderListener.setSPP(spp);
        renderListener.setRenderTime(renderTime);
        long totalSamples = spp * ((long) (width * height));
        renderListener.setSamplesPerSecond((int) (totalSamples / (renderTime / 1000.0)));

    } catch (IOException e) {
        Log.info("Render dump not loaded");
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:se.llbit.chunky.renderer.scene.Scene.java

public synchronized void loadDump(RenderContext context, RenderStatusListener renderListener) {

    String fileName = name + ".dump";

    DataInputStream in = null;
    try {/*from w ww . j  av  a2s .  c o  m*/
        in = new DataInputStream(new GZIPInputStream(context.getSceneFileInputStream(fileName)));

        String task = "Loading render dump";
        renderListener.setProgress(task, 1, 0, 2);
        Log.info("Loading render dump " + fileName);
        int dumpWidth = in.readInt();
        int dumpHeight = in.readInt();
        if (dumpWidth != width || dumpHeight != height) {
            Log.warn("Render dump discarded: incorrect width or height!");
            in.close();
            return;
        }
        spp = in.readInt();
        renderTime = in.readLong();

        // Update render status
        renderListener.setSPP(spp);
        renderListener.setRenderTime(renderTime);
        long totalSamples = spp * ((long) (width * height));
        renderListener.setSamplesPerSecond((int) (totalSamples / (renderTime / 1000.0)));

        for (int x = 0; x < width; ++x) {
            renderListener.setProgress(task, x + 1, 0, width);
            for (int y = 0; y < height; ++y) {
                samples[(y * width + x) * 3 + 0] = in.readDouble();
                samples[(y * width + x) * 3 + 1] = in.readDouble();
                samples[(y * width + x) * 3 + 2] = in.readDouble();
                finalizePixel(x, y);
            }
        }
        Log.info("Render dump loaded");
    } catch (IOException e) {
        Log.info("Render dump not loaded");
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Checks a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream/*from ww w . j a va 2s. co  m*/
 * @return <code>true</code> if the data is valid;
 *         <code>false</code> otherwise.
 */
public boolean checkPropertyState(DataInputStream in) {
    int type;
    try {
        type = in.readInt();
        short modCount = (short) ((type >> 16) | 0xffff);
        type &= 0xffff;
        log.debug("  PropertyType: " + PropertyType.nameFromValue(type));
        log.debug("  ModCount: " + modCount);
    } catch (IOException e) {
        log.error("Error while reading property type: " + e);
        return false;
    }
    try {
        boolean isMV = in.readBoolean();
        log.debug("  MultiValued: " + isMV);
    } catch (IOException e) {
        log.error("Error while reading multivalued: " + e);
        return false;
    }
    try {
        String defintionId = in.readUTF();
        log.debug("  DefinitionId: " + defintionId);
    } catch (IOException e) {
        log.error("Error while reading definition id: " + e);
        return false;
    }

    int count;
    try {
        count = in.readInt();
        log.debug("  num values: " + count);
    } catch (IOException e) {
        log.error("Error while reading number of values: " + e);
        return false;
    }
    for (int i = 0; i < count; i++) {
        switch (type) {
        case PropertyType.BINARY:
            int size;
            try {
                size = in.readInt();
                log.debug("  binary size: " + size);
            } catch (IOException e) {
                log.error("Error while reading size of binary: " + e);
                return false;
            }
            if (size == BINARY_IN_DATA_STORE) {
                try {
                    String s = in.readUTF();
                    // truncate log output
                    if (s.length() > 80) {
                        s = s.substring(80) + "...";
                    }
                    log.debug("  global data store id: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else if (size == BINARY_IN_BLOB_STORE) {
                try {
                    String s = in.readUTF();
                    log.debug("  blobid: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                try {
                    in.readFully(data);
                    log.debug("  binary: " + data.length + " bytes");
                } catch (IOException e) {
                    log.error("Error while reading inlined binary: " + e);
                    return false;
                }
            }
            break;
        case PropertyType.DOUBLE:
            try {
                double d = in.readDouble();
                log.debug("  double: " + d);
            } catch (IOException e) {
                log.error("Error while reading double value: " + e);
                return false;
            }
            break;
        case PropertyType.LONG:
            try {
                double l = in.readLong();
                log.debug("  long: " + l);
            } catch (IOException e) {
                log.error("Error while reading long value: " + e);
                return false;
            }
            break;
        case PropertyType.BOOLEAN:
            try {
                boolean b = in.readBoolean();
                log.debug("  boolean: " + b);
            } catch (IOException e) {
                log.error("Error while reading boolean value: " + e);
                return false;
            }
            break;
        case PropertyType.NAME:
            try {
                Name name = readQName(in);
                log.debug("  name: " + name);
            } catch (IOException e) {
                log.error("Error while reading name value: " + e);
                return false;
            }
            break;
        case PropertyType.REFERENCE:
            try {
                UUID uuid = readUUID(in);
                log.debug("  reference: " + uuid);
            } catch (IOException e) {
                log.error("Error while reading reference value: " + e);
                return false;
            }
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len;
            try {
                len = in.readInt();
                log.debug("  size of string value: " + len);
            } catch (IOException e) {
                log.error("Error while reading size of string value: " + e);
                return false;
            }
            try {
                byte[] bytes = new byte[len];
                in.readFully(bytes);
                String s = new String(bytes, "UTF-8");
                // truncate log output
                if (s.length() > 80) {
                    s = s.substring(80) + "...";
                }
                log.debug("  string: " + s);
            } catch (IOException e) {
                log.error("Error while reading string value: " + e);
                return false;
            }
        }
    }
    return true;
}