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

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

Description

write String

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

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

import java.io.ObjectOutputStream;

public class Main {
    private static final String UTF8 = "UTF-8";

    /**//w  ww.  j av  a2 s. c o m
     * DOC zhao Comment method "writeString".
     * 
     * @param line
     * @param dos
     * @throws IOException
     */
    public static void writeString(String str, ObjectOutputStream dos) throws IOException {
        if (str == null) {
            dos.writeInt(-1);
        } else {
            byte[] byteArray = str.getBytes(UTF8);
            dos.writeInt(byteArray.length);
            dos.write(byteArray);
        }
    }

    public static void writeString(String str, DataOutputStream dos) throws IOException {
        if (str == null) {
            dos.writeInt(-1);
        } else {
            byte[] byteArray = str.getBytes(UTF8);
            dos.writeInt(byteArray.length);
            dos.write(byteArray);
        }
    }
}

Related

  1. writeString(final DataOutputStream out, final String value)
  2. writeString(String arg, DataOutputStream data)
  3. writeString(String s, DataOutputStream out)
  4. writeString(String s, DataOutputStream out)
  5. writeString(String s, DataOutputStream writer)
  6. writeString(String str, DataOutputStream os)
  7. writeString(String stringToWrite, DataOutputStream data)
  8. writeStringAsBytes(DataOutputStream out, byte[] byteArray)
  9. writeStringAsBytes(DataOutputStream out, byte[] byteArray)