Here you can find the source of writeStreamFromString(String contents, OutputStream outputStream)
public static void writeStreamFromString(String contents, OutputStream outputStream) throws IOException
//package com.java2s; /**/*www . j a v a 2s.c om*/ * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; public class Main { public static void writeStreamFromString(String contents, OutputStream outputStream) throws IOException { if (contents == null) { return; } char[] buffer = new char[0x10000]; Reader in = new InputStreamReader(new ByteArrayInputStream(contents.getBytes("UTF-8"))); //$NON-NLS-1$ Writer out = new OutputStreamWriter(outputStream, "UTF-8"); //$NON-NLS-1$ int read; do { read = in.read(buffer, 0, buffer.length); if (read > 0) { out.write(buffer, 0, read); } } while (read >= 0); in.close(); out.flush(); out.close(); } }