Java OutputStream Write String writeString(String s, OutputStream out)

Here you can find the source of writeString(String s, OutputStream out)

Description

write String

License

Open Source License

Declaration

public static void writeString(String s, OutputStream out)
            throws IOException 

Method Source Code

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

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    public static void writeString(String s, OutputStream out)
            throws IOException {
        if (s == null) {
            writeInt(0, out);//from  w w  w .  ja  v a  2  s. c o m
            return;
        }
        int len = s.length();
        writeInt(len, out);
        for (int i = 0; i < len; i++)
            writChar(s.charAt(i), out);
    }

    public static void writeInt(int val, OutputStream out)
            throws IOException {
        out.write((val >>> 24) & 0xff);
        out.write((val >>> 16) & 0xff);
        out.write((val >>> 8) & 0xff);
        out.write(val & 0xff);
    }

    public static void writChar(char val, OutputStream out)
            throws IOException {
        out.write((val >>> 8) & 0xff);
        out.write(val & 0xff);
    }
}

Related

  1. writeString(OutputStream out, String str)
  2. writeString(OutputStream out, String str)
  3. WriteString(OutputStream output, String string)
  4. writeString(OutputStream output, String string)
  5. writeString(String data, int length, OutputStream out)
  6. writeString(String str, ObjectOutputStream dos)
  7. writeString(String value, OutputStream os)
  8. writeStringAsAsciiBytes(String in, OutputStream out)
  9. writeStringCompressed(ByteArrayOutputStream baos, String s)