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

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

Description

Write a string.

License

Open Source License

Parameter

Parameter Description
theString the value

Return

itself

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.DataOutputStream;

import java.io.IOException;

public class Main {
    /**//  w  w w  . ja  v a  2 s.c om
     * Write a string. The maximum string length is Integer.MAX_VALUE.
     *
     * @param theString the value
     * @return itself
     */
    public static void writeString(DataOutputStream out, String theString) throws IOException {
        if (theString == null) {
            out.writeInt(-1);
        } else {
            int len = theString.length();
            out.writeInt(len);
            writeCharsOfString(out, theString);
        }
    }

    public static void writeCharsOfString(DataOutputStream out, String theString) throws IOException {

        int len = theString.length();
        for (int i = 0; i < len; i++) {
            out.writeChar(theString.charAt(i));
        }
    }
}

Related

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