Java DataOutputStream Write String writeString(DataOutputStream out, String text)

Here you can find the source of writeString(DataOutputStream out, String text)

Description

Writes a string to the given output stream and emits an additional short to transfer if text is null.

License

Apache License

Parameter

Parameter Description
out the output stream
text the text to be emitted

Exception

Parameter Description
IOException in case of any I/O error or problem

Declaration

public static void writeString(DataOutputStream out, String text) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.DataOutputStream;
import java.io.IOException;

public class Main {
    /**/*from   w  w w. jav a2  s  .c om*/
     * Writes a string to the given output stream and emits an additional short
     * to transfer if <code>text</code> is <b>null</b>.
     * 
     * @param out the output stream
     * @param text the text to be emitted
     * @throws IOException in case of any I/O error or problem
     * 
     * @since 1.00
     */
    public static void writeString(DataOutputStream out, String text) throws IOException {
        if (null == text) {
            out.writeShort(0);
        } else {
            out.writeShort(1);
            out.writeUTF(text);
        }
    }
}

Related

  1. writeString(DataOutputStream os, String str)
  2. writeString(DataOutputStream out, String s)
  3. writeString(DataOutputStream out, String str)
  4. writeString(DataOutputStream out, String str)
  5. writeString(DataOutputStream out, String str)
  6. writeString(DataOutputStream out, String theString)
  7. writeString(DataOutputStream out, String val)
  8. writeString(DataOutputStream output, String s)
  9. writeString(DataOutputStream outputStream, String string)