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 main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/WriteBoolean.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    boolean b = false;
    dos.writeBoolean(b);
    dos.close();//from   w  w  w  .  j ava 2  s. co  m
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*from   w w w  . j a v  a 2 s  . c  o m*/

        FileOutputStream fos = new FileOutputStream(args[0]);

        DataOutputStream dos = new DataOutputStream(fos);

        dos.writeBoolean(false);
        dos.writeByte(Byte.MAX_VALUE);
        dos.writeChar('A');
        dos.writeDouble(Double.MAX_VALUE);
        dos.writeFloat(Float.MAX_VALUE);
        dos.writeInt(Integer.MAX_VALUE);
        dos.writeLong(Long.MAX_VALUE);
        dos.writeShort(Short.MAX_VALUE);

        fos.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    boolean[] bools = { true, false, false, true, true, true };

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);

    for (boolean bool : bools) {
        dos.writeBoolean(bool);
    }/*w ww  .  ja v  a 2s.  com*/

    dos.flush();

    for (byte b : baos.toByteArray()) {
        System.out.print(b);
    }
}

From source file:DataIODemo.java

public static void main(String args[]) throws IOException {

    FileOutputStream fout = new FileOutputStream("Test.dat");
    DataOutputStream out = new DataOutputStream(fout);

    out.writeDouble(98.6);/*from ww  w  .  j  a  v a 2 s  .  com*/
    out.writeInt(1000);
    out.writeBoolean(true);

    out.close();

    FileInputStream fin = new FileInputStream("Test.dat");
    DataInputStream in = new DataInputStream(fin);

    double d = in.readDouble();
    int i = in.readInt();
    boolean b = in.readBoolean();

    System.out.println("Here are the values:  " + d + " " + i + " " + b);

    in.close();
}

From source file:Main.java

public static void writeBoolean(DataOutputStream os, boolean b) throws IOException {
    os.writeBoolean(b);
}

From source file:Main.java

public static void writeBool(DataOutputStream out, boolean val) throws IOException {
    out.writeBoolean(val);
}

From source file:com.opensoc.json.serialization.JSONEncoderHelper.java

public static void putBoolean(DataOutputStream data, Boolean value) throws IOException {
    // TODO Auto-generated method stub
    data.writeByte(JSONKafkaSerializer.BooleanID);
    data.writeBoolean(value);

}

From source file:com.fullhousedev.globalchat.bukkit.PluginMessageManager.java

public static void userToggleMessage(String username, boolean on, Plugin pl) {
    try {/*from ww w.j  av  a 2  s .c o m*/
        ByteArrayOutputStream customData = new ByteArrayOutputStream();
        DataOutputStream outCustom = new DataOutputStream(customData);
        outCustom.writeUTF(username);
        outCustom.writeBoolean(on);

        sendRawMessage("togglemsg", "ALL", customData.toByteArray(), pl);
    } catch (IOException ex) {
        Logger.getLogger(GlobalChat.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.fullhousedev.globalchat.bukkit.PluginMessageManager.java

public static void userToggleSocialspy(String username, boolean on, Plugin pl) {
    try {/* w ww. j  a v  a  2 s  .com*/
        ByteArrayOutputStream customData = new ByteArrayOutputStream();
        DataOutputStream outCustom = new DataOutputStream(customData);
        outCustom.writeUTF(username);
        outCustom.writeBoolean(on);

        sendRawMessage("toggless", "ALL", customData.toByteArray(), pl);
    } catch (IOException ex) {
        Logger.getLogger(GlobalChat.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.hive.hcatalog.streaming.mutate.client.AcidTableSerializer.java

/** Returns a base 64 encoded representation of the supplied {@link AcidTable}. */
public static String encode(AcidTable table) throws IOException {
    DataOutputStream data = null;
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    try {//from   w ww .  ja v a2 s.com
        data = new DataOutputStream(bytes);
        data.writeUTF(table.getDatabaseName());
        data.writeUTF(table.getTableName());
        data.writeBoolean(table.createPartitions());
        if (table.getTransactionId() <= 0) {
            LOG.warn("Transaction ID <= 0. The recipient is probably expecting a transaction ID.");
        }
        data.writeLong(table.getTransactionId());
        data.writeByte(table.getTableType().getId());

        Table metaTable = table.getTable();
        if (metaTable != null) {
            byte[] thrift = new TSerializer(new TCompactProtocol.Factory()).serialize(metaTable);
            data.writeInt(thrift.length);
            data.write(thrift);
        } else {
            LOG.warn("Meta store table is null. The recipient is probably expecting an instance.");
            data.writeInt(0);
        }
    } catch (TException e) {
        throw new IOException("Error serializing meta store table.", e);
    } finally {
        data.close();
    }

    return PROLOG_V1 + new String(Base64.encodeBase64(bytes.toByteArray()), Charset.forName("UTF-8"));
}