Here you can find the source of toInputStream(String input)
Parameter | Description |
---|---|
input | the string to convert |
public static InputStream toInputStream(String input)
//package com.java2s; /**//from w w w .j a v a 2 s .c om * Copyright (C) 2016 LibRec * <p> * This file is part of LibRec. * LibRec is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * <p> * LibRec 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 General Public License for more details. * <p> * You should have received a copy of the GNU General Public License * along with LibRec. If not, see <http://www.gnu.org/licenses/>. */ import java.io.*; public class Main { /** * Convert the specified string to an input stream, encoded as bytes * using the default character encoding of the platform. * * @param input the string to convert * @return an input stream * @since Commons IO 1.1 */ public static InputStream toInputStream(String input) { byte[] bytes = input.getBytes(); return new ByteArrayInputStream(bytes); } /** * Convert the specified string to an input stream, encoded as bytes * using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * * @param input the string to convert * @param encoding the encoding to use, null means platform default * @return an input stream * @throws IOException if the encoding is invalid * @since Commons IO 1.1 */ public static InputStream toInputStream(String input, String encoding) throws IOException { byte[] bytes = encoding != null ? input.getBytes(encoding) : input.getBytes(); return new ByteArrayInputStream(bytes); } }