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

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

Description

Writes a string to the buffer.

License

Open Source License

Parameter

Parameter Description
buf The buffer.
str The string.

Exception

Parameter Description
IllegalArgumentException if the string is too long<em>after</em> it is encoded.

Declaration

public static void writeString(DataOutputStream out, String str) 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 {
    /**/*from  w  w  w.j  a v  a 2  s . c  o  m*/
     * Writes a string to the buffer.
     * @param buf The buffer.
     * @param str The string.
     * @throws IllegalArgumentException if the string is too long
     * <em>after</em> it is encoded.
     */
    public static void writeString(DataOutputStream out, String str) throws IOException {
        int len = str.length();
        if (len >= 65536) {
            throw new IllegalArgumentException("String too long.");
        }

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

Related

  1. writeString(DataOutputStream buf, String value)
  2. writeString(DataOutputStream os, String s)
  3. writeString(DataOutputStream os, String str)
  4. writeString(DataOutputStream out, String s)
  5. writeString(DataOutputStream out, String str)
  6. writeString(DataOutputStream out, String str)
  7. writeString(DataOutputStream out, String text)
  8. writeString(DataOutputStream out, String theString)