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

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

Description

write String

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    public static void writeString(OutputStream out, String s) throws IOException {
        if (s == null) {
            writeInt(out, 0);//from w ww. j a  va 2s  .  c  o  m
        } else {
            byte[] bytes = s.getBytes("UTF-8");
            writeInt(out, bytes.length);
            out.write(bytes);
        }
    }

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

Related

  1. writeString(OutputStream os, String text)
  2. writeString(OutputStream out, String s)
  3. writeString(OutputStream out, String s)
  4. writeString(OutputStream out, String s)
  5. writeString(OutputStream out, String s)
  6. writeString(OutputStream out, String s)
  7. writeString(OutputStream out, String str)
  8. writeString(OutputStream out, String str)
  9. WriteString(OutputStream output, String string)