Here you can find the source of toInputStream(String input, String encoding)
public static InputStream toInputStream(String input, String encoding) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . j av a 2 s . c o m*/ * Angelo Zerr <angelo.zerr@gmail.com> - Initial API and implementation *******************************************************************************/ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static InputStream toInputStream(String input, String encoding) throws IOException { byte bytes[] = encoding == null ? input.getBytes() : input .getBytes(encoding); return new ByteArrayInputStream(bytes); } }