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.apache.cassandra.db.SuperColumn.java

public void serialize(IColumn column, DataOutputStream dos) throws IOException {
    SuperColumn superColumn = (SuperColumn) column;
    dos.writeUTF(superColumn.name());
    dos.writeInt(superColumn.getLocalDeletionTime());
    dos.writeLong(superColumn.getMarkedForDeleteAt());

    Collection<IColumn> columns = column.getSubColumns();
    int size = columns.size();
    dos.writeInt(size);/*  w  ww  . j a  va  2s.  c om*/

    dos.writeInt(superColumn.getSizeOfAllColumns());
    for (IColumn subColumn : columns) {
        Column.serializer().serialize(subColumn, dos);
    }
}

From source file:org.wso2.carbon.connector.ISO8583.ISO8583MessageHandler.java

/**
 * handle the iso8583 message request and responses
 *
 * @param isoMessage  packed ISOMessage//from ww w  .jav a  2 s .  com
 * @param connection  Socket connection with backend Test server
 * @param messageContext the message context
 */
public void clientHandler(MessageContext messageContext, Socket connection, String isoMessage) {
    DataOutputStream outStream = null;
    BufferedReader inFromServer = null;
    String message;
    try {
        outStream = new DataOutputStream(connection.getOutputStream());
        inFromServer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        if (connection.isConnected()) {
            outStream.writeUTF(isoMessage);
            outStream.flush();

            /* Sender will receive the Acknowledgement here */
            if ((message = inFromServer.readLine()) != null) {
                unpackResponse(messageContext, message);
            }
        }
    } catch (IOException e) {
        handleException("An exception occurred in sending the ISO8583 message", e);
    } finally {
        try {
            if (outStream != null) {
                outStream.close();
            }
            if (inFromServer != null) {
                inFromServer.close();
            }
            connection.close();
        } catch (IOException e) {
            log.error("Couldn't close the I/O Streams", e);
        }
    }
}

From source file:com.googlecode.onevre.utils.ServerClassLoader.java

private void appendIndex(URL url, File jar) throws IOException {
    FileOutputStream output = new FileOutputStream(new File(localCacheDirectory, INDEX), true);
    DataOutputStream cacheFile = new DataOutputStream(output);
    cacheFile.writeUTF(url.toString());
    cacheFile.writeUTF(jar.getName());/*from  w w w . j ava2s .  c o m*/
    output.close();
}

From source file:de.hybris.platform.cuppytrail.impl.DefaultSecureTokenService.java

@Override
public String encryptData(final SecureToken data) {
    if (data == null || StringUtils.isBlank(data.getData())) {
        throw new IllegalArgumentException("missing token");
    }// w w  w. j  a  va 2 s.c  o  m
    try {
        final SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
        final int[] paddingSizes = computePaddingLengths(random);

        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
        dataOutputStream.write(generatePadding(paddingSizes[0], random));
        dataOutputStream.writeUTF(data.getData());
        dataOutputStream.writeUTF(createChecksum(data.getData()));
        dataOutputStream.writeLong(data.getTimeStamp());
        dataOutputStream.write(generatePadding(paddingSizes[1], random));

        dataOutputStream.flush();
        final byte[] unsignedDataBytes = byteArrayOutputStream.toByteArray();

        final byte[] md5SigBytes = generateSignature(unsignedDataBytes, 0, unsignedDataBytes.length,
                signatureKeyBytes);
        byteArrayOutputStream.write(md5SigBytes);
        byteArrayOutputStream.flush();

        final byte[] signedDataBytes = byteArrayOutputStream.toByteArray();

        return encrypt(signedDataBytes, encryptionKeyBytes, random);
    } catch (final IOException e) {
        LOG.error("Could not encrypt", e);
        throw new SystemException(e.toString(), e);
    } catch (final GeneralSecurityException e) {
        LOG.error("Could not encrypt", e);
        throw new SystemException(e.toString(), e);
    }
}

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

public void serialize(IColumn column, DataOutputStream dos) throws IOException {
    SuperColumn superColumn = (SuperColumn) column;
    dos.writeUTF(superColumn.name());
    dos.writeLong(superColumn.getMarkedForDeleteAt());

    Collection<IColumn> columns = column.getSubColumns();
    int size = columns.size();
    dos.writeInt(size);/*from w ww  .  j ava2s. c o  m*/

    /*
     * Add the total size of the columns. This is useful
     * to skip over all the columns in this super column
     * if we are not interested in this super column.
    */
    dos.writeInt(superColumn.getSizeOfAllColumns());
    // dos.writeInt(superColumn.size());

    for (IColumn subColumn : columns) {
        Column.serializer().serialize(subColumn, dos);
    }
}

From source file:com.bigdata.dastor.db.RowMutation.java

private void freezeTheMaps(Map<String, ColumnFamily> map, DataOutputStream dos) throws IOException {
    int size = map.size();
    dos.writeInt(size);/*from   w w  w  . j  a va  2 s .  com*/
    if (size > 0) {
        Set<String> keys = map.keySet();
        for (String key : keys) {
            dos.writeUTF(key);
            ColumnFamily cf = map.get(key);
            if (cf != null) {
                ColumnFamily.serializer().serialize(cf, dos);
            }
        }
    }
}

From source file:org.hyperic.hq.agent.client.AgentConnection.java

private AgentStreamPair sendCommandHeadersWithRetries(String cmdName, int cmdVersion, AgentRemoteValue arg,
        int maxRetries) throws IOException {
    IOException ex = null;//w ww.j a  va 2  s  .c  o  m
    AgentStreamPair streamPair = null;
    Socket s = null;
    int tries = 0;
    while (tries++ < maxRetries) {
        try {
            s = getSocket();
            streamPair = new SocketStreamPair(s, s.getInputStream(), s.getOutputStream());
            DataOutputStream outputStream = new DataOutputStream(streamPair.getOutputStream());
            outputStream.writeInt(_agentAPI.getVersion());
            outputStream.writeInt(cmdVersion);
            outputStream.writeUTF(cmdName);
            arg.toStream(outputStream);
            outputStream.flush();
            return streamPair;
        } catch (IOException e) {
            ex = e;
            close(s);
        }
        if (tries >= maxRetries) {
            break;
        }
        try {
            Thread.sleep(SLEEP_TIME);
        } catch (InterruptedException e) {
            log.debug(e, e);
        }
    }
    if (ex != null) {
        IOException toThrow = new IOException(ex.getMessage() + ", retried " + MAX_RETRIES + " times");
        // call initCause instead of constructor to be java 1.5 compat
        toThrow.initCause(ex);
        throw toThrow;
    }
    return streamPair;
}

From source file:org.sakaiproject.search.journal.impl.SegmentListWriter.java

public void write(List<File> segments) throws IOException {

    if (!out.exists() && !out.getParentFile().exists()) {
        if (!out.getParentFile().mkdirs()) {
            throw new IOException("Can't create folder " + out.getParentFile().getPath());
        }/*w  w  w  .  j  a v a  2 s  .  c  o  m*/
    }
    FileOutputStream fout = new FileOutputStream(out);
    DataOutputStream dout = new DataOutputStream(fout);
    dout.write(SegmentListStore.SEGMENT_LIST_SIGNATURE);
    dout.writeInt(SegmentListStore.VERSION_SIGNATURE);
    dout.writeInt(segments.size());
    StringBuilder sb = new StringBuilder();
    sb.append(segments.size()).append(" Segments \n");
    for (File segs : segments) {
        String s = segs.getAbsolutePath();
        sb.append("\t").append(s).append("\n");
        dout.writeUTF(s);
    }
    dout.close();
    fout.close();
    if (log.isDebugEnabled())
        log.debug("Saved: " + sb.toString());
}

From source file:com.igormaznitsa.jhexed.hexmap.HexFieldLayer.java

public void write(final OutputStream out) throws IOException {
    final DataOutputStream dout = out instanceof DataOutputStream ? (DataOutputStream) out
            : new DataOutputStream(out);
    dout.writeUTF(this.name);
    dout.writeUTF(this.comments);

    dout.writeShort(this.values.size());
    for (int i = 0; i < this.values.size(); i++) {
        this.values.get(i).write(dout);
    }/*from  w  w  w .j av a  2  s. co  m*/

    dout.writeInt(this.columns);
    dout.writeInt(this.rows);
    dout.writeBoolean(this.visible);

    final byte[] packed = Utils.packByteArray(this.array);
    dout.writeInt(packed.length);
    dout.write(packed);
    dout.flush();
}

From source file:org.darwinathome.server.controller.HubController.java

@RequestMapping(Hub.SET_TARGET_SERVICE)
public void setTarget(@PathVariable("session") String session, @RequestParam(Hub.PARAM_LOCATION_X) double x,
        @RequestParam(Hub.PARAM_LOCATION_Y) double y, @RequestParam(Hub.PARAM_LOCATION_Z) double z,
        @RequestParam(Hub.PARAM_PREY_NAME) String preyName, OutputStream outputStream) throws IOException {
    log.info(Hub.SET_TARGET_SERVICE);//from   w w w  .  j a va 2  s  .  c o m
    DataOutputStream dos = new DataOutputStream(outputStream);
    try {
        Arrow location = new Arrow(x, y, z);
        Target target = new Target(location, preyName);
        WorldHistory.Frozen frozen = worldHistory.setTarget(getEmail(session), target);
        dos.writeUTF(Hub.SUCCESS);
        dos.write(frozen.getWorld());
    } catch (NoSessionException e) {
        dos.writeUTF(Hub.FAILURE);
        dos.writeUTF(Failure.SESSION.toString());
    }
}