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

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

Description

Writes a string to the buffer.

License

Open Source License

Parameter

Parameter Description
out The buffer.
str The string.

Exception

Parameter Description
IOException Loading the file failed.

Declaration

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

Method Source Code


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

import java.io.*;

public class Main {
    private static final int MAXLEN = 65535;

    /**/*from   ww w  .ja  v  a2  s . c om*/
     * Writes a string to the buffer.
     *
     * @param out The buffer.
     * @param str The string.
     * @throws IOException Loading the file failed.
     */
    public static void writeString(final DataOutputStream out, final String str) throws IOException {
        int len = str.length();
        if (len > MAXLEN) {
            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 out, String text)
  2. writeString(DataOutputStream out, String theString)
  3. writeString(DataOutputStream out, String val)
  4. writeString(DataOutputStream output, String s)
  5. writeString(DataOutputStream outputStream, String string)
  6. writeString(final DataOutputStream out, final String value)
  7. writeString(String arg, DataOutputStream data)
  8. writeString(String s, DataOutputStream out)
  9. writeString(String s, DataOutputStream out)