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:gobblin.metrics.kafka.KafkaAvroReporter.java

/**
 * Implementation of {@link gobblin.metrics.SerializedMetricReportReporter#writeSchemaVersioningInformation} supporting
 * a {@link gobblin.metrics.kafka.KafkaAvroSchemaRegistry}.
 *
 * <p>/* w w  w  .  j  a  va2  s .  c o m*/
 * If a {@link gobblin.metrics.kafka.KafkaAvroSchemaRegistry} is provided to the reporter, this method writes
 * the {@link gobblin.metrics.kafka.KafkaAvroSchemaRegistry} id for the {@link gobblin.metrics.MetricReport} schema
 * instead of the static {@link gobblin.metrics.MetricReportUtils#SCHEMA_VERSION}. This allows processors like
 * Camus to retrieve the correct {@link org.apache.avro.Schema} from a REST schema registry. This method will also
 * automatically register the {@link org.apache.avro.Schema} to the REST registry. It is assumed that calling
 * {@link gobblin.metrics.kafka.KafkaAvroSchemaRegistry#register} more than once for the same
 * {@link org.apache.avro.Schema} is not a problem, as it will be called at least once per JVM.
 *
 * If no {@link gobblin.metrics.kafka.KafkaAvroSchemaRegistry} is provided, this method simply calls the super method.
 * </p>
 *
 * @param outputStream Empty {@link java.io.DataOutputStream} that will hold the serialized
 *                     {@link gobblin.metrics.MetricReport}. Any data written by this method
 *                     will appear at the beginning of the emitted message.
 * @throws IOException
 */
@Override
protected void writeSchemaVersioningInformation(DataOutputStream outputStream) throws IOException {

    if (this.registry.isPresent()) {
        if (!this.registrySchemaId.isPresent()) {
            this.registrySchemaId = Optional.of(this.registry.get().register(MetricReport.SCHEMA$));
        }
        outputStream.writeByte(KafkaAvroSchemaRegistry.MAGIC_BYTE);
        try {
            outputStream.write(Hex.decodeHex(this.registrySchemaId.get().toCharArray()));
        } catch (DecoderException exception) {
            throw new IOException(exception);
        }
    } else {
        super.writeSchemaVersioningInformation(outputStream);
    }

}

From source file:bankingclient.DNFrame.java

public DNFrame(MainFrame vmain) {

    initComponents();// w  w w.  j a  va2s .c  o m

    this.jTextField1.setText("");
    this.jTextField2.setText("");
    this.jTextField_cmt.setText("");
    this.jTextField_sdt.setText("");

    this.main = vmain;
    noAcc = new NewOrOldAccFrame(this);
    this.setVisible(false);
    jL_sdt.setVisible(false);
    jL_cmtnd.setVisible(false);
    jTextField_cmt.setVisible(false);
    jTextField_sdt.setVisible(false);

    jBt_dn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!jCheck_qmk.isSelected()) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(2);
                    dout.writeUTF(jTextField1.getText() + "\n" + jTextField2.getText());
                    dout.flush();
                    while (true) {
                        break;
                    }
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        noAcc.setVisible(true);
                        DNFrame.this.setVisible(false);
                        noAcc.setMainCustomer(jTextField1.getText());

                    } else {
                        JOptionPane.showMessageDialog(new JFrame(),
                                "Tn ?ang Nhp Khng Tn Ti, hoac mat khau sai");
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Mng....");
                }
            } else if ((!jTextField_cmt.getText().equals("")) && (!jTextField_sdt.getText().equals(""))
                    && (NumberUtils.isNumber(jTextField_cmt.getText()))
                    && (NumberUtils.isNumber(jTextField_sdt.getText()))) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(9);
                    dout.writeUTF(jTextField1.getText() + "\n" + jTextField_sdt.getText() + "\n"
                            + jTextField_cmt.getText());
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        noAcc.setVisible(true);
                        DNFrame.this.setVisible(false);
                        noAcc.setMainCustomer(jTextField1.getText());
                    } else {
                        JOptionPane.showMessageDialog(new JFrame(), "Khong dang nhap duoc, thong tin sai");
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(new JFrame(), "Can dien day du thong tin va dung mau");
            }
        }
    });
    jBt_ql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            main.setVisible(true);
            DNFrame.this.setVisible(false);
        }
    });
    jCheck_qmk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (jCheck_qmk.isSelected()) {
                jL_sdt.setVisible(true);
                jL_cmtnd.setVisible(true);
                jTextField_cmt.setVisible(true);
                jTextField_sdt.setVisible(true);
            } else {
                jL_sdt.setVisible(false);
                jL_cmtnd.setVisible(false);
                jTextField_cmt.setVisible(false);
                jTextField_sdt.setVisible(false);
            }
        }
    });
}

From source file:com.mirth.connect.model.transmission.framemode.FrameStreamHandler.java

protected void write(byte[]... dataArrays) throws IOException {
    if (dataArrays == null || outputStream == null) {
        return;/*from   ww w  . j  a v  a2 s  .co  m*/
    }

    DataOutputStream dos = new DataOutputStream(outputStream);

    for (byte[] data : dataArrays) {
        if (data != null) {
            for (byte b : data) {
                dos.writeByte(b);
            }
        }
    }

    try {
        dos.flush();
    } catch (SocketException e) {
        logger.debug("Socket closed while trying to flush.");
    }
}

From source file:com.tc.simple.apn.factories.PushByteFactory.java

@Override
public byte[] buildPushBytes(int id, Payload payload) {
    byte[] byteMe = null;
    ByteArrayOutputStream baos = null;
    DataOutputStream dos = null;

    try {/*www  .j  a v  a  2  s .c om*/
        baos = new ByteArrayOutputStream();

        dos = new DataOutputStream(baos);

        int expiry = 0; // (int) ((System.currentTimeMillis () / 1000L) + 7200);

        char[] cars = payload.getToken().trim().toCharArray();

        byte[] tokenBytes = Hex.decodeHex(cars);

        //command
        dos.writeByte(1);

        //id
        dos.writeInt(id);

        //expiry
        dos.writeInt(expiry);

        //token length.
        dos.writeShort(tokenBytes.length);

        //token
        dos.write(tokenBytes);

        //payload length
        dos.writeShort(payload.getJson().length());

        logger.log(Level.FINE, payload.getJson());

        //payload.
        dos.write(payload.getJson().getBytes());

        byteMe = baos.toByteArray();

    } catch (Exception e) {
        logger.log(Level.SEVERE, null, e);

    } finally {
        CloseUtils.close(dos);
        CloseUtils.close(baos);
    }

    return byteMe;

}

From source file:com.ning.arecibo.util.timeline.times.TimelineCoderImpl.java

private void writeRepeatedDelta(final int delta, final int repeatCount, final DataOutputStream dataStream)
        throws IOException {
    if (repeatCount > 1) {
        if (repeatCount > MAX_BYTE_REPEAT_COUNT) {
            dataStream.writeByte(TimelineOpcode.REPEATED_DELTA_TIME_SHORT.getOpcodeIndex());
            dataStream.writeShort(repeatCount);
        } else if (repeatCount == 2) {
            dataStream.writeByte(delta);
        } else {/*w  w  w .j a  v a2s  .  co m*/
            dataStream.writeByte(TimelineOpcode.REPEATED_DELTA_TIME_BYTE.getOpcodeIndex());
            dataStream.writeByte(repeatCount);
        }
    }
    dataStream.writeByte(delta);
}

From source file:org.ejbca.core.protocol.cmp.CmpTestCase.java

private static byte[] createTcpMessage(byte[] msg) throws IOException {
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bao);
    // 0 is pkiReq
    int msgType = 0;
    int len = msg.length;
    // return msg length = msg.length + 3; 1 byte version, 1 byte flags and
    // 1 byte message type
    dos.writeInt(len + 3);//  w ww.j a  v a 2  s. c o  m
    dos.writeByte(10);
    dos.writeByte(0); // 1 if we should close, 0 otherwise
    dos.writeByte(msgType);
    dos.write(msg);
    dos.flush();
    return bao.toByteArray();
}

From source file:org.openmrs.module.odkconnector.serialization.serializer.openmrs.ObsSerializer.java

/**
 * Write the data to the output stream./*from  w w w  .  j a  v a  2  s  .  c o m*/
 *
 * @param stream the output stream
 * @param data   the data that need to be written to the output stream
 * @throws java.io.IOException thrown when the writing process encounter is failing
 */
@Override
public void write(final OutputStream stream, final Object data) throws IOException {
    try {
        Obs obs = (Obs) data;

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        DataOutputStream outputStream = new DataOutputStream(stream);
        // write the person id of the observation
        outputStream.writeInt(obs.getPersonId());
        // write the concept name of the observation
        outputStream.writeUTF(obs.getConcept().getDisplayString());
        // write the data type and the value of the observation
        if (obs.getValueDatetime() != null) {
            outputStream.writeByte(TYPE_DATE);
            outputStream.writeUTF(dateFormat.format(obs.getValueDatetime()));
        } else if (obs.getValueCoded() != null) {
            outputStream.writeByte(TYPE_STRING);
            outputStream.writeUTF(obs.getValueCoded().getDisplayString());
        } else if (obs.getValueNumeric() != null) {
            outputStream.writeByte(TYPE_DOUBLE);
            outputStream.writeDouble(obs.getValueNumeric());
        } else {
            outputStream.writeByte(TYPE_STRING);
            outputStream.writeUTF(obs.getValueAsString(Context.getLocale()));
        }
        // write the datetime of the observation
        outputStream.writeUTF(dateFormat.format(obs.getObsDatetime()));
    } catch (IOException e) {
        log.info("Writing obs information failed!", e);
    }
}

From source file:hd3gtv.embddb.network.DataBlock.java

byte[] getBytes(Protocol protocol) throws IOException {
    checkIfNotEmpty();//from w  ww.j a va2 s .  c o  m

    ByteArrayOutputStream byte_array_out_stream = new ByteArrayOutputStream(Protocol.BUFFER_SIZE);

    DataOutputStream dos = new DataOutputStream(byte_array_out_stream);
    dos.write(Protocol.APP_SOCKET_HEADER_TAG);
    dos.writeInt(Protocol.VERSION);

    /**
     * Start header name
     */
    dos.writeByte(0);
    byte[] request_name_data = request_name.getBytes(Protocol.UTF8);
    dos.writeInt(request_name_data.length);
    dos.write(request_name_data);

    /**
     * Start datas payload
     */
    dos.writeByte(1);

    /**
     * Get datas from zip
     */
    ZipOutputStream zos = new ZipOutputStream(dos);
    zos.setLevel(3);
    entries.forEach(entry -> {
        try {
            entry.toZip(zos);
        } catch (IOException e) {
            log.error("Can't add to zip", e);
        }
    });
    zos.flush();
    zos.finish();
    zos.close();

    dos.flush();
    dos.close();

    byte[] result = byte_array_out_stream.toByteArray();

    if (log.isTraceEnabled()) {
        log.trace("Make raw datas for " + request_name + Hexview.LINESEPARATOR + Hexview.tracelog(result));
    }

    return result;
}

From source file:com.ning.arecibo.util.timeline.times.TimelineCoderImpl.java

private void writeTime(final int lastTime, final int newTime, final DataOutputStream dataStream)
        throws IOException {
    if (newTime > lastTime) {
        final int delta = (newTime - lastTime);
        if (delta <= TimelineOpcode.MAX_DELTA_TIME) {
            dataStream.writeByte(delta);
        } else {//from  www.  j av  a2 s . c  o  m
            dataStream.writeByte(TimelineOpcode.FULL_TIME.getOpcodeIndex());
            dataStream.writeInt(newTime);
        }
    } else if (newTime == lastTime) {
        dataStream.writeByte(0);
    }
}

From source file:com.codefollower.lealone.omid.tso.TSOHandler.java

/**
 * Handle the FullAbortReport message/*from  w  ww. ja  va 2  s . c  om*/
 */
private void handle(FullAbortRequest msg, ChannelHandlerContext ctx) {
    synchronized (sharedState) {
        DataOutputStream toWAL = sharedState.toWAL;
        try {
            toWAL.writeByte(LoggerProtocol.FULL_ABORT);
            toWAL.writeLong(msg.startTimestamp);
        } catch (IOException e) {
            LOG.error("failed to write fullabort wal", e);
        }
        sharedState.processFullAbort(msg.startTimestamp);
    }
    synchronized (sharedMsgBufLock) {
        queueFullAbort(msg.startTimestamp);
    }
}