Example usage for java.io DataOutputStream writeUTF

List of usage examples for java.io DataOutputStream writeUTF

Introduction

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

Prototype

public final void writeUTF(String str) throws IOException 

Source Link

Document

Writes a string to the underlying output stream using modified UTF-8 encoding in a machine-independent manner.

Usage

From source file:org.floggy.synchronization.jme.server.SynchronizationServletTest.java

/**
* DOCUMENT ME!//from   w  w  w  . j ava 2  s.c om
*
* @param synchronizableClass DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
public byte[] getContent(Class synchronizableClass) throws Exception {
    SynchronizableMetadataManager.init();

    SynchronizableMetadata metadata = SynchronizableMetadataManager
            .getSynchronizableMetadata(synchronizableClass.getName());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    DataOutputStream dos = new DataOutputStream(baos);

    dos.flush();
    dos.writeUTF(metadata.toJSON());

    return baos.toByteArray();
}

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

@Override
public void writeData(DataOutputStream data) throws IOException {
    data.writeInt(value.length);//from  w  w  w .  ja v a  2  s .  c  o  m
    for (String v : value) {
        data.writeUTF(v);
    }
}

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

/**
 * Write the data to the output stream.//ww  w.j  a  v  a2s. c  om
 *
 * @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 {
        SerializedForm serializedForm = (SerializedForm) data;

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        DataOutputStream outputStream = new DataOutputStream(stream);

        outputStream.writeInt(serializedForm.getPatientId());
        outputStream.writeUTF(ExtendedDefinition.DEFINITION_PROPERTY_FORM);
        outputStream.writeByte(TYPE_INT);
        outputStream.writeInt(serializedForm.getFormId());
        outputStream.writeUTF(dateFormat.format(new Date()));
    } catch (IOException e) {
        log.info("Writing form information failed!", e);
    }
}

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);/*from ww w.  j av a  2s .  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:MainClass.java

public void run() {
    try {//from  ww w . j  av  a 2 s .  c o m
        Socket socket = new Socket("127.0.0.1", 2000);

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

        while (true) {
            System.out.print("Enter response: ");
            String response = console.readLine();
            out.writeUTF(response);

            String message = in.readUTF();
            System.out.println(message);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java

/**
 * Returns the encoded form of PBEncryptionParameters.
 *//*from  ww w.j a  v  a2  s . c o  m*/
public byte[] getEncoded() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    DataOutputStream out = new DataOutputStream(bos);

    out.writeLong(serialVersionUID);

    out.writeUTF(algorithm);
    out.writeInt(salt.length);
    out.write(salt);

    out.writeInt(iterationCount);

    return bos.toByteArray();
}

From source file:J2MEWriteReadMixedDataTypesExample.java

public void commandAction(Command command, Displayable displayable) {
    if (command == exit) {
        destroyApp(true);//from  w w w  .j  a va  2  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.apache.cassandra.db.ReadCommand.java

public void serialize(ReadCommand rm, DataOutputStream dos) throws IOException {
    dos.writeUTF(rm.table);
    dos.writeUTF(rm.key);//from  w  ww. ja va 2  s .  c om
    dos.writeUTF(rm.columnFamilyColumn);
    dos.writeInt(rm.start);
    dos.writeInt(rm.count);
    dos.writeLong(rm.sinceTimestamp);
    dos.writeBoolean(rm.isDigestQuery());
    dos.writeInt(rm.columnNames.size());
    if (rm.columnNames.size() > 0) {
        for (String cName : rm.columnNames) {
            dos.writeInt(cName.getBytes().length);
            dos.write(cName.getBytes());
        }
    }
}

From source file:com.yattatech.io.ShalomFileWriter.java

public boolean write(Seminary seminary) {
    final String path = seminary.getFilePath();
    final String json = new Gson().toJson(seminary);
    boolean sucess = true;
    DataOutputStream out = null;
    try {//from   www  . j  a  v a 2  s  .c  o m
        out = new DataOutputStream(new FileOutputStream(path));
        out.writeLong(ChecksumCalculator.calculateChecksum(json));
        out.writeUTF("\n");
        out.writeUTF(json);
    } catch (IOException ioe) {
        LOGGER.log(Level.SEVERE, ioe.getMessage());
        sucess = false;
    } finally {
        IOUtils.closeQuietly(out);
        return sucess;
    }
}

From source file:org.openxdata.server.serializer.JavaRosaXformSerializer.java

@Override
public void serializeFailure(OutputStream os, Exception ex) {
    DataOutputStream dos = new DataOutputStream(os);
    try {//from  w  w  w.j a v a2 s.c  om
        dos.writeUTF(ex.toString());
        dos.flush();
        dos.close();
    } catch (IOException e) {
        throw new UnexpectedException(e);
    }
}