Example usage for java.io DataOutputStream writeBoolean

List of usage examples for java.io DataOutputStream writeBoolean

Introduction

In this page you can find the example usage for java.io DataOutputStream writeBoolean.

Prototype

public final void writeBoolean(boolean v) throws IOException 

Source Link

Document

Writes a boolean to the underlying output stream as a 1-byte value.

Usage

From source file:Main.java

public static void writeSettings(String file, Object... objs) throws IOException {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 1024));
    try {//  w  w  w . j  av a  2  s  .com
        out.writeInt(objs.length);
        for (Object obj : objs) {
            char cl;
            if (obj instanceof Byte) {
                cl = 'Y';
            } else {
                cl = obj.getClass().getSimpleName().charAt(0);
            }

            out.writeChar(cl);
            if (obj instanceof String) {
                out.writeUTF((String) obj);
            } else if (obj instanceof Float) {
                out.writeFloat((Float) obj);
            } else if (obj instanceof Double) {
                out.writeDouble((Double) obj);
            } else if (obj instanceof Integer) {
                out.writeInt((Integer) obj);
            } else if (obj instanceof Long) {
                out.writeLong((Long) obj);
            } else if (obj instanceof Boolean) {
                out.writeBoolean((Boolean) obj);
            } else {
                throw new IllegalStateException("Unsupported type");
            }
        }
    } finally {
        out.close();
    }
}

From source file:com.bigdata.dastor.db.ReadResponse.java

public void serialize(ReadResponse rm, DataOutputStream dos) throws IOException {
    dos.writeInt(rm.digest().length);//w  w  w  .  j a v a  2  s  .c  om
    dos.write(rm.digest());
    dos.writeBoolean(rm.isDigestQuery());

    if (!rm.isDigestQuery() && rm.row() != null) {
        Row.serializer().serialize(rm.row(), dos);
    }
}

From source file:org.apache.cassandra.db.SliceByNamesReadCommand.java

@Override
public void serialize(ReadCommand rm, DataOutputStream dos) throws IOException {
    SliceByNamesReadCommand realRM = (SliceByNamesReadCommand) rm;
    dos.writeBoolean(realRM.isDigestQuery());
    dos.writeUTF(realRM.table);/*from   w  ww  .  j av  a  2s. c o m*/
    dos.writeUTF(realRM.key);
    realRM.columnParent.serialize(dos);
    dos.writeInt(realRM.columnNames.size());
    if (realRM.columnNames.size() > 0) {
        for (byte[] cName : realRM.columnNames) {
            ColumnSerializer.writeName(cName, dos);
        }
    }
}

From source file:org.getspout.spout.packet.PacketBlockData.java

public void writeData(DataOutputStream output) throws IOException {
    output.writeInt(data == null ? 0 : data.length);
    output.writeBoolean(compressed);
    if (data != null) {
        output.write(data);//from   w  ww. j  a  va 2 s.  com
    }
}

From source file:J2MEWriteReadMixedDataTypesExample.java

public void commandAction(Command command, Displayable displayable) {
    if (command == exit) {
        destroyApp(true);/*from   w  ww.  j  av a2  s  .co m*/
        notifyDestroyed();
    } else if (command == start) {
        try {
            recordstore = RecordStore.openRecordStore("myRecordStore", true);
            byte[] outputRecord;
            String outputString = "First Record";
            int outputInteger = 15;
            boolean outputBoolean = true;
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            DataOutputStream outputDataStream = new DataOutputStream(outputStream);
            outputDataStream.writeUTF(outputString);
            outputDataStream.writeBoolean(outputBoolean);
            outputDataStream.writeInt(outputInteger);
            outputDataStream.flush();
            outputRecord = outputStream.toByteArray();
            recordstore.addRecord(outputRecord, 0, outputRecord.length);
            outputStream.reset();
            outputStream.close();
            outputDataStream.close();
            String inputString = null;
            int inputInteger = 0;
            boolean inputBoolean = false;
            byte[] byteInputData = new byte[100];
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
            DataInputStream inputDataStream = new DataInputStream(inputStream);
            for (int x = 1; x <= recordstore.getNumRecords(); x++) {
                recordstore.getRecord(x, byteInputData, 0);
                inputString = inputDataStream.readUTF();
                inputBoolean = inputDataStream.readBoolean();
                inputInteger = inputDataStream.readInt();
                inputStream.reset();
            }
            inputStream.close();
            inputDataStream.close();
            alert = new Alert("Reading", inputString + " " + inputInteger + " " + inputBoolean, null,
                    AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
            recordstore.closeRecordStore();
            if (RecordStore.listRecordStores() != null) {
                RecordStore.deleteRecordStore("myRecordStore");
            }
        } catch (Exception error) {
            alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
    }
}

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

@Test
public void serialize_shouldDisplayAllCohortInformation() throws Exception {

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

    // setup http url connection
    HttpURLConnection connection = (HttpURLConnection) u.openConnection();
    connection.setDoOutput(true);/*w w  w. ja  v  a  2 s .co  m*/
    connection.setRequestMethod("POST");
    connection.setConnectTimeout(8000);
    connection.setReadTimeout(8000);
    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(false);
    outputStream.close();

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

    if (responseStatus == HttpURLConnection.HTTP_OK) {

        Integer cohortCounts = inputStream.readInt();
        System.out.println("Number of cohorts: " + cohortCounts);

        for (int i = 0; i < cohortCounts; i++) {
            System.out.println("Cohort ID: " + inputStream.readInt());
            System.out.println("Cohort Name: " + inputStream.readUTF());
        }
    }
    inputStream.close();
}

From source file:com.facebook.infrastructure.db.ReadResponse.java

public void serialize(ReadResponse rm, DataOutputStream dos) throws IOException {
    dos.writeUTF(rm.table());//from  w  w w  . j a  v a 2  s  .c  o  m
    dos.writeInt(rm.digest().length);
    dos.write(rm.digest());
    dos.writeBoolean(rm.isDigestQuery());

    if (!rm.isDigestQuery() && rm.row() != null) {
        Row.serializer().serialize(rm.row(), dos);
    }
}

From source file:org.getspout.spout.packet.PacketCacheFile.java

public void writeData(DataOutputStream output) throws IOException {
    PacketUtil.writeString(output, fileName);
    PacketUtil.writeString(output, plugin);
    output.writeBoolean(compressed);
    output.writeInt(fileData.length);//from   w w  w . j a  v a 2  s . co  m
    output.write(fileData);
}

From source file:com.facebook.infrastructure.db.Column.java

public void serialize(IColumn column, DataOutputStream dos) throws IOException {
    dos.writeUTF(column.name());/*from  www . j  a v  a  2 s  .  co m*/
    dos.writeBoolean(column.isMarkedForDelete());
    dos.writeLong(column.timestamp());
    dos.writeInt(column.value().length);
    dos.write(column.value());
}

From source file:WriteReadMixedDataTypesExample.java

public void commandAction(Command command, Displayable displayable) {
    if (command == exit) {
        destroyApp(true);/* w  w  w.j  a  v a2s. c om*/
        notifyDestroyed();
    } else if (command == start) {
        try {
            recordstore = RecordStore.openRecordStore("myRecordStore", true);
        } catch (Exception error) {
            alert = new Alert("Error Creating", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
        try {
            byte[] outputRecord;
            String outputString = "First Record";
            int outputInteger = 15;
            boolean outputBoolean = true;
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            DataOutputStream outputDataStream = new DataOutputStream(outputStream);
            outputDataStream.writeUTF(outputString);
            outputDataStream.writeBoolean(outputBoolean);
            outputDataStream.writeInt(outputInteger);
            outputDataStream.flush();
            outputRecord = outputStream.toByteArray();
            recordstore.addRecord(outputRecord, 0, outputRecord.length);
            outputStream.reset();
            outputStream.close();
            outputDataStream.close();
        } catch (Exception error) {
            alert = new Alert("Error Writing", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
        try {
            String inputString = null;
            int inputInteger = 0;
            boolean inputBoolean = false;
            byte[] byteInputData = new byte[100];
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
            DataInputStream inputDataStream = new DataInputStream(inputStream);
            for (int x = 1; x <= recordstore.getNumRecords(); x++) {
                recordstore.getRecord(x, byteInputData, 0);
                inputString = inputDataStream.readUTF();
                inputBoolean = inputDataStream.readBoolean();
                inputInteger = inputDataStream.readInt();
                inputStream.reset();
            }
            inputStream.close();
            inputDataStream.close();
            alert = new Alert("Reading", inputString + " " + inputInteger + " " + inputBoolean, null,
                    AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        } catch (Exception error) {
            alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
        try {
            recordstore.closeRecordStore();
        } catch (Exception error) {
            alert = new Alert("Error Closing", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
        if (RecordStore.listRecordStores() != null) {
            try {
                RecordStore.deleteRecordStore("myRecordStore");
            } catch (Exception error) {
                alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
                alert.setTimeout(Alert.FOREVER);
                display.setCurrent(alert);
            }
        }
    }
}