Java Text File Write by Charset writer(OutputStream out, String charset)

Here you can find the source of writer(OutputStream out, String charset)

Description

writer

License

Apache License

Declaration

static public OutputStreamWriter writer(OutputStream out, String charset) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2012 Urbancode, Inc/*  www . jav a2s.  com*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

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

import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

public class Main {
    static public OutputStreamWriter writer(OutputStream out, String charset) {
        OutputStreamWriter result;
        if (charset == null) {
            result = writer(out);
        } else {
            result = writer(out, Charset.forName(charset));
        }
        return result;
    }

    static public OutputStreamWriter writer(OutputStream out, CharsetEncoder encoder) {
        OutputStreamWriter result;
        if (encoder == null) {
            result = writer(out);
        } else {
            result = new OutputStreamWriter(out, encoder);
        }
        return result;
    }

    static public OutputStreamWriter writer(OutputStream out, Charset charset) {
        OutputStreamWriter result;
        if (charset == null) {
            result = writer(out);
        } else {
            CharsetEncoder encoder;
            encoder = charset.newEncoder();
            result = writer(out, encoder);
        }
        return result;
    }

    static public OutputStreamWriter writer(OutputStream out) {
        OutputStreamWriter result;

        result = new OutputStreamWriter(out);

        return result;
    }
}

Related

  1. writeFile(File file, String content, Charset charset)
  2. writeFile(String content, File file, Charset encoding)
  3. writeFile(String path, String content, Charset charset)
  4. writeFile(String path, String content, Charset encoding)
  5. writeFile(String path, String output, Charset encoding)
  6. writer(String path, String content, String charset)
  7. writerBuffered(final File file, final Charset charset)
  8. writeStreamToString(InputStream is, String charsetName)
  9. writeString(OutputStream os, String string, CharsetEncoder encoder)