Java OutputStream Write writeStreamText(OutputStream out, String text)

Here you can find the source of writeStreamText(OutputStream out, String text)

Description

Writes the text data to the specified output stream.

License

BSD License

Parameter

Parameter Description
out output stream
text text data

Exception

Parameter Description
IOException an exception

Declaration

public static void writeStreamText(OutputStream out, String text) throws IOException 

Method Source Code

//package com.java2s;
// New BSD License

import java.io.BufferedWriter;
import java.io.Closeable;

import java.io.IOException;

import java.io.OutputStream;
import java.io.OutputStreamWriter;

public class Main {
    private static final String DEFAULT_ENCODING = "UTF8";

    /**/*from  w  w w  . j  ava2s . c o  m*/
    * Writes the text data to the specified output stream.
    *
    * @param out output stream
    * @param text text data
    * @throws IOException
    */
    public static void writeStreamText(OutputStream out, String text) throws IOException {
        writeLinesCommon(out, text);
    }

    private static void writeLinesCommon(OutputStream out, String text) throws IOException {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new OutputStreamWriter(out, DEFAULT_ENCODING));
            writer.write(text);
        } finally {
            close(writer);
        }
    }

    private static void close(Closeable c) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException ex) {
            }
        }
    }
}

Related

  1. writeStreamCharwise(final Reader in, final Writer out)
  2. writeStreamCharwiseLimited(final Reader in, final Writer out, final int len)
  3. writeStreamFromString(String contents, OutputStream outputStream)
  4. writeStreamFromString(String serializePath)
  5. writeStreamInFile(File f, InputStream in)
  6. writeStreamToArray(InputStream stream)
  7. writeStreamToStream(InputStream in, OutputStream out)
  8. writeStreamToStream(InputStream input, OutputStream output)
  9. writeStreamToStream(InputStream inputStream, OutputStream outputStream)