Example usage for java.io DataOutputStream writeByte

List of usage examples for java.io DataOutputStream writeByte

Introduction

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

Prototype

public final void writeByte(int v) throws IOException 

Source Link

Document

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

Usage

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

private void putJSON(DataOutputStream data, JSONObject value) throws IOException {

    // JSON ID is 2
    data.writeByte(JSONKafkaSerializer.JSONObjectID);
    data.write(toBytes(value));// w ww.ja  va  2s.  c om

}

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

private static void writeObject(final DataOutputStream outputStream, final byte type, final Object value)
        throws IOException {

    switch (type) {

    case 0://from   w  ww.ja v a 2s .co m
    case 1:
        outputStream.writeByte((byte) value);
        break;

    case 2:
    case 3:
        outputStream.writeShort((short) value);
        break;

    case 4:
    case 5:
        outputStream.writeInt((int) value);
        break;

    case 6:
    case 7:
        outputStream.writeLong((long) value);
        break;

    case 8:
    case 9:
        outputStream.writeFloat((float) value);
        break;

    case 10:
    case 11:
        outputStream.writeDouble((double) value);
        break;

    case 12:
    case 13:
        outputStream.writeChar((char) value);
        break;

    case 14:
    case 15:
        serializeData(outputStream, ((String) value).getBytes("UTF-8"));

        // this doesn't work with very long strings
        //outputStream.writeUTF((String)value);
        break;

    case 16:
    case 17:
        outputStream.writeBoolean((boolean) value);
        break;
    }
}

From source file:gobblin.metrics.reporter.util.SchemaRegistryVersionWriter.java

@Override
public void writeSchemaVersioningInformation(Schema schema, DataOutputStream outputStream) throws IOException {

    String schemaId = this.schemaId.isPresent() ? this.schemaId.get() : this.getIdForSchema(schema);

    outputStream.writeByte(KafkaAvroSchemaRegistry.MAGIC_BYTE);
    try {/*from   w  ww  . jav a 2  s  .co m*/
        outputStream.write(Hex.decodeHex(schemaId.toCharArray()));
    } catch (DecoderException exception) {
        throw new IOException(exception);
    }
}

From source file:bankingclient.TaoTaiKhoanFrame.java

public TaoTaiKhoanFrame(NewOrOldAccFrame acc) {

    initComponents();//  w  w w  . j ava  2  s. c om
    this.jText_ten_tk.setText("");
    this.jText_sd.setText("");

    this.noAcc = acc;
    this.mainCustomerName = null;
    this.setVisible(false);

    jBt_ht.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (NumberUtils.isNumber(jText_sd.getText()) && (Long.parseLong(jText_sd.getText()) > 0)) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(3);
                    dout.writeUTF(jText_ten_tk.getText() + "\n" + mainCustomerName + "\n" + jText_sd.getText());
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        JOptionPane.showMessageDialog(rootPane, "da tao tai khoan thanh cong");
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "tao tai khoan khong thanh cong");
                    }
                    client.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                noAcc.setVisible(true);
                TaoTaiKhoanFrame.this.setVisible(false);
            } else {
                JOptionPane.showMessageDialog(rootPane, "Can nhap lai so tien gui");
            }

        }
    });
    jBt_ql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            noAcc.setVisible(true);
            TaoTaiKhoanFrame.this.setVisible(false);

        }
    });
}

From source file:org.apache.hadoop.dfs.TestBlockReplacement.java

private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy,
        DatanodeInfo destination) throws IOException {
    Socket sock = new Socket();
    sock.connect(NetUtils.createSocketAddr(sourceProxy.getName()), FSConstants.READ_TIMEOUT);
    sock.setKeepAlive(true);//from ww  w.  j  a  v  a  2  s. c  o m
    // sendRequest
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    out.writeShort(FSConstants.DATA_TRANSFER_VERSION);
    out.writeByte(FSConstants.OP_COPY_BLOCK);
    out.writeLong(block.getBlockId());
    out.writeLong(block.getGenerationStamp());
    Text.writeString(out, source.getStorageID());
    destination.write(out);
    out.flush();
    // receiveResponse
    DataInputStream reply = new DataInputStream(sock.getInputStream());

    short status = reply.readShort();
    if (status == FSConstants.OP_STATUS_SUCCESS) {
        return true;
    }
    return false;
}

From source file:info.fetter.logstashforwarder.protocol.LumberjackClient.java

private int sendDataFrame(DataOutputStream output, Map<String, byte[]> keyValues) throws IOException {
    output.writeByte(PROTOCOL_VERSION);
    output.writeByte(FRAME_DATA);//  w  w  w  .j  a  v  a2  s . c  om
    output.writeInt(sequence++);
    output.writeInt(keyValues.size());
    int bytesSent = 10;
    for (String key : keyValues.keySet()) {
        int keyLength = key.length();
        output.writeInt(keyLength);
        bytesSent += 4;
        output.write(key.getBytes());
        bytesSent += keyLength;
        byte[] value = keyValues.get(key);
        output.writeInt(value.length);
        bytesSent += 4;
        output.write(value);
        bytesSent += value.length;
    }
    output.flush();
    return bytesSent;
}

From source file:bankingclient.DKFrame.java

public DKFrame(MainFrame vmain) {
    initComponents();/*from  w ww.j a  va2s .  c  o m*/
    this.main = vmain;
    this.jTextField1.setText("");
    this.jTextField2.setText("");
    this.jTextField3.setText("");
    this.jTextField4.setText("");
    this.jTextField5.setText("");
    this.setVisible(false);
    jButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jTextField2.getText().equals(jTextField3.getText())
                    && NumberUtils.isNumber(jTextField4.getText())
                    && NumberUtils.isNumber(jTextField5.getText())) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    String cusName = jTextField1.getText();
                    String pass = jTextField2.getText();
                    String sdt = jTextField4.getText();
                    String cmt = jTextField5.getText();
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(1);
                    dout.writeUTF(cusName + "\n" + pass + "\n" + sdt + "\n" + cmt);
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        JOptionPane.showMessageDialog(rootPane, "da dang ki tai khoan thanh cong");
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "dang ki tai khoan khong thanh cong");

                    }
                    client.close();
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
                main.setVisible(true);
                DKFrame.this.setVisible(false);

            } else {
                JOptionPane.showMessageDialog(rootPane, "Nhap thong tin sai, moi nhap lai");
            }
        }
    });
    jButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            main.setVisible(true);
            DKFrame.this.setVisible(false);
        }
    });
}

From source file:com.mirth.connect.connectors.mllp.protocols.LlpProtocol.java

public void write(OutputStream os, byte[] data) throws IOException {
    // Write the data with LLP wrappers
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeByte(START_MESSAGE);

    // MIRTH-1448: Changed from writing the entire byte[] to writing
    // each byte in the byte[] to avoid sending the START_MESSAGE as
    // its own packet.
    for (int i = 0; i < data.length; i++) {
        dos.writeByte(data[i]);/*  w w  w.  j  a  va 2  s. com*/
    }

    dos.writeByte(END_MESSAGE);
    if (END_OF_RECORD != 0) {
        dos.writeByte(END_OF_RECORD);
    }
    try {
        dos.flush();
    } catch (SocketException se) {
        logger.debug("Socket closed while trying to flush");
    }
}

From source file:org.apache.hadoop.hdfs.server.datanode.TestBlockReplacement.java

private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy,
        DatanodeInfo destination) throws IOException {
    Socket sock = new Socket();
    sock.connect(NetUtils.createSocketAddr(destination.getName()), HdfsConstants.READ_TIMEOUT);
    sock.setKeepAlive(true);/*  w  ww .  j  a v  a2 s.co m*/
    // sendRequest
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    out.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION);
    out.writeByte(DataTransferProtocol.OP_REPLACE_BLOCK);
    out.writeLong(block.getBlockId());
    out.writeLong(block.getGenerationStamp());
    Text.writeString(out, source.getStorageID());
    sourceProxy.write(out);
    BlockTokenSecretManager.DUMMY_TOKEN.write(out);
    out.flush();
    // receiveResponse
    DataInputStream reply = new DataInputStream(sock.getInputStream());

    short status = reply.readShort();
    if (status == DataTransferProtocol.OP_STATUS_SUCCESS) {
        return true;
    }
    return false;
}

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

public static void serialize(DataOutputStream outputStream, Object obj) throws IOException {

    if (obj != null) {

        Class clazz = obj.getClass();
        Byte type = typeMap.get(clazz);

        if (type != null) {

            if (clazz.isArray()) {

                Object[] array = (Object[]) obj;

                outputStream.writeByte(type);
                outputStream.writeInt(array.length);

                // serialize array
                for (Object o : (Object[]) obj) {
                    serialize(outputStream, o);
                }/* w  ww . j ava2s  . c om*/

            } else {

                outputStream.writeByte(type);
                writeObject(outputStream, type, obj);

                //outputStream.writeUTF(obj.toString());
            }

        } else {

            logger.log(Level.WARNING, "Unable to serialize object of type {0}, type not supported",
                    obj.getClass());
        }

    } else {

        // null value
        outputStream.writeByte((byte) 127);
    }

    outputStream.flush();
}