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

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

Description

write String

License

Open Source License

Declaration

static void writeString(OutputStream os, String s) throws IOException 

Method Source Code


//package com.java2s;
/*/*from  w w w  . j  a v a2 s. co  m*/
 * @(#)NodeUtil.java 1.2 05/06/27
 *
 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
 *
 * See the file "LICENSE.txt" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

import java.io.*;

public class Main {
    static void writeString(OutputStream os, String s) throws IOException {

        int n = s.length();

        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);

            if (c < 0x80) {
                os.write(c);
            } else if (c < 0x800) {
                os.write(0xc0 + (c >> 6));
                os.write(0x80 + (c & 0x3f));
            } else {
                os.write(0xe0 + (c >> 12));
                os.write(0x80 + ((c >> 6) & 0x3f));
                os.write(0x80 + (c & 0x3f));
            }
        }
    }
}

Related

  1. writeString(ByteArrayOutputStream baos, String s)
  2. writeString(final OutputStream output, final String s)
  3. writeString(ObjectOutputStream stream, String string)
  4. writeString(OutputStream os, String request, String charsetName)
  5. writeString(OutputStream os, String s)
  6. writeString(OutputStream os, String s)
  7. writeString(OutputStream os, String str)
  8. writeString(OutputStream os, String text)
  9. writeString(OutputStream out, String s)