Example usage for java.io DataInputStream readUTF

List of usage examples for java.io DataInputStream readUTF

Introduction

In this page you can find the example usage for java.io DataInputStream readUTF.

Prototype

public final String readUTF() throws IOException 

Source Link

Document

See the general contract of the readUTF method of DataInput.

Usage

From source file:com.csipsimple.backup.SipProfilesHelper.java

/**
 * Read data from the input stream/*from w w  w  . j  a  va 2 s  . c o  m*/
 * 
 * @param data the input stream
 * @return the data
 * @throws IOException I/O error
 */
private String readData(BackupDataInputStream data) throws IOException {
    String dataS;
    byte[] buf = new byte[data.size()];
    data.read(buf, 0, buf.length);
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
    DataInputStream dis = new DataInputStream(bais);
    dataS = dis.readUTF();
    dis.close();
    bais.close();
    return dataS;
}

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

public ReadCommand deserialize(DataInputStream dis) throws IOException {
    String table = dis.readUTF();
    String key = dis.readUTF();/*w  w  w . j av a2  s. c  om*/
    String columnFamily_column = dis.readUTF();
    int start = dis.readInt();
    int count = dis.readInt();
    long sinceTimestamp = dis.readLong();
    boolean isDigest = dis.readBoolean();

    int size = dis.readInt();
    List<String> columns = new ArrayList<String>();
    for (int i = 0; i < size; ++i) {
        byte[] bytes = new byte[dis.readInt()];
        dis.readFully(bytes);
        columns.add(new String(bytes));
    }
    ReadCommand rm = null;
    if (columns.size() > 0) {
        rm = new ReadCommand(table, key, columnFamily_column, columns);
    } else if (sinceTimestamp > 0) {
        rm = new ReadCommand(table, key, columnFamily_column, sinceTimestamp);
    } else {
        rm = new ReadCommand(table, key, columnFamily_column, start, count);
    }
    rm.setDigestQuery(isDigest);
    return rm;
}

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

public Row deserialize(DataInputStream dis) throws IOException {
    String key = dis.readUTF();
    Row row = new Row(key);
    int size = dis.readInt();

    if (size > 0) {
        for (int i = 0; i < size; ++i) {
            ColumnFamily cf = ColumnFamily.serializer().deserialize(dis);
            row.addColumnFamily(cf);/*  w w  w . jav a  2 s  .co m*/
        }
    }
    return row;
}

From source file:org.orbisgis.sqlconsole.api.SQLElement.java

@Override
public void readStream(DataInputStream in) throws IOException {
    String path = in.readUTF();
    if (!path.isEmpty()) {
        setDocumentPath(new File(path));
    }/*from   ww  w  . j  a va  2  s. com*/
}

From source file:LCModels.MessageTransmitter.java

@Override
public void run() {
    try {/*from www.ja v  a  2 s .c  om*/
        // Socket connects to the ServerSocket, ServerSocket receives a Socket, what? haha//
        //send data as points
        //            Socket s = new Socket(hostname,targetPort);
        //            Socket z = new Socket(hostname, 48500, InetAddress.getByName("127.0.0.1"), targetPort);
        Socket client = new Socket(hostname, targetPort);
        /* Get server's OutputStream */
        OutputStream outToServer = client.getOutputStream();
        /* Get server's DataOutputStream to write/send message */
        DataOutputStream out = new DataOutputStream(outToServer);
        /* Write message to DataOutputStream */
        out.writeUTF(transmitJSON.toString());
        /* Get InputStream to get message from server */
        InputStream inFromServer = client.getInputStream();
        /* Get DataInputStream to read message of server */
        DataInputStream in = new DataInputStream(inFromServer);
        /* Print message received from server */
        System.out.println("Server says..." + in.readUTF());
        client.close();
    } catch (IOException ex) {
        Logger.getLogger(MessageTransmitter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:srvserver.thKeepAliveSocket.java

@Override
public void run() {

    if (gDatos.getServiceStatus().isIsActivePrimaryMonHost()) {
        try {//from  w  w w .j a  va 2 s .  com
            Socket skCliente = new Socket(gDatos.getServiceInfo().getSrvMonHost(),
                    gDatos.getServiceInfo().getMonPort());

            OutputStream aux = skCliente.getOutputStream();
            DataOutputStream flujo = new DataOutputStream(aux);
            String dataSend = gSub.sendDataKeep("keep");

            logger.info("Generando (tx) hacia Server Monitor Primario: " + dataSend);

            flujo.writeUTF(dataSend);

            InputStream inpStr = skCliente.getInputStream();
            DataInputStream dataInput = new DataInputStream(inpStr);
            String response = dataInput.readUTF();

            logger.info("Recibiendo (rx)...: " + response);
            JSONObject jHeader = new JSONObject(response);

            try {
                if (jHeader.getString("result").equals("OK")) {
                    JSONObject jData = jHeader.getJSONObject("data");
                    //Como es una repsuesta no se espera retorno de error del SP
                    //el mismo lo resporta internamente si hay alguno.
                    gSub.updateAssignedProcess(jData);
                } else {
                    if (jHeader.getString("result").equals("error")) {
                        JSONObject jData = jHeader.getJSONObject("data");
                        System.out.println(
                                "Error result: " + jData.getInt("errCode") + " " + jData.getString("errMesg"));
                    }
                }
            } catch (Exception e) {
                logger.error("Error en formato de respuesta");
            }
        } catch (NumberFormatException | IOException e) {
            gDatos.getServiceStatus().setIsActivePrimaryMonHost(false);
            gDatos.getServiceStatus().setIsConnectMonHost(false);
            logger.error(" Error conexion a server de monitoreo primary...." + e.getMessage());
        }

    } else {
        //
        //Valida conexion a server secundario Backup
        //
        try {
            Socket skCliente = new Socket(gDatos.getServiceInfo().getSrvMonHostBack(),
                    gDatos.getServiceInfo().getMonPortBack());

            OutputStream aux = skCliente.getOutputStream();
            DataOutputStream flujo = new DataOutputStream(aux);
            String dataSend = gSub.sendDataKeep("keep");

            logger.info("Generando (tx) hacia Server Monitor Secundario: " + dataSend);

            flujo.writeUTF(dataSend);

            InputStream inpStr = skCliente.getInputStream();
            DataInputStream dataInput = new DataInputStream(inpStr);
            String response = dataInput.readUTF();

            logger.info("Recibiendo (rx)...: " + response);
            JSONObject jHeader = new JSONObject(response);

            try {
                if (jHeader.getString("result").equals("OK")) {
                    JSONObject jData = jHeader.getJSONObject("data");
                    //Como es una repsuesta no se espera retorno de error del SP
                    //el mismo lo resporta internamente si hay alguno.
                    gSub.updateAssignedProcess(jData);
                } else {
                    if (jHeader.getString("result").equals("error")) {
                        JSONObject jData = jHeader.getJSONObject("data");
                        logger.error(
                                "Error result: " + jData.getInt("errCode") + " " + jData.getString("errMesg"));
                    }
                }
            } catch (Exception e) {
                logger.error("Error en formato de respuesta");
            }
        } catch (NumberFormatException | IOException e) {
            gDatos.getServiceStatus().setIsActivePrimaryMonHost(true);
            gDatos.getServiceStatus().setIsConnectMonHost(false);
            logger.error(" Error conexion a server de monitoreo backup...." + e.getMessage());
        }
    }
}

From source file:additionalpipes.inventory.components.PropertyStrArray.java

@Override
public void readData(DataInputStream data) throws IOException {
    int size = data.readInt();
    if (size > 0) {
        value = new String[size];
        for (int i = 0; i < value.length; i++) {
            value[i] = data.readUTF();
        }/*from   w ww.j ava  2s  . c  om*/
    } else {
        value = ArrayUtils.EMPTY_STRING_ARRAY;
    }
}

From source file:MainClass.java

public void run() {
    try {//from w ww  .j  av  a2  s  . co  m
        Socket client = serverSocket.accept();

        DataInputStream in = new DataInputStream(client.getInputStream());
        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
        DataOutputStream out = new DataOutputStream(client.getOutputStream());

        while (true) {
            String message = in.readUTF();
            System.out.println(message);
            System.out.print("Enter response: ");
            String response = console.readLine();

            out.writeUTF(response);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:RetrieveAllMIDlet.java

public void changeFromByteArray(byte[] data) {
    try {//  ww w .  j  a  va  2  s  .c  o m
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);

        name = dis.readUTF();
        chineseScore = dis.readInt();
        englishScore = dis.readInt();
        mathScore = dis.readInt();

        bais.close();
        dis.close();
    } catch (Exception e) {
    }
}

From source file:org.darwinathome.client.HttpHub.java

public void authenticate(final String email, final String password, final Exchange exchange) {
    CargoCatcher sessionCatcher = new CargoCatcher() {
        public void catchCargo(DataInputStream dis) throws IOException {
            session = dis.readUTF();
        }//from  w  ww . ja  v  a  2  s.com
    };
    submit(new ExchangeRunner(Hub.AUTHENTICATE_SERVICE, exchange, sessionCatcher) {
        @Override
        HttpRequestBase getRequest(String serviceUrl) {
            return createPost(serviceUrl, Hub.PARAM_BODY_NAME, email, Hub.PARAM_PASSWORD, password);
        }
    });
}