Java OutputStream Write String writeString(String str, ObjectOutputStream dos)

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

Description

DOC zhao Comment method "writeString".

License

Open Source License

Parameter

Parameter Description
line a parameter
dos a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void writeString(String str, ObjectOutputStream 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";

    /**/*from  www .  ja v a2s . co 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(OutputStream out, String str)
  2. WriteString(OutputStream output, String string)
  3. writeString(OutputStream output, String string)
  4. writeString(String data, int length, OutputStream out)
  5. writeString(String s, OutputStream out)
  6. writeString(String value, OutputStream os)
  7. writeStringAsAsciiBytes(String in, OutputStream out)
  8. writeStringCompressed(ByteArrayOutputStream baos, String s)
  9. writeStringKey(final Object key, final ObjectOutputStream oos)