Java Utililty Methods InputStream Create

List of utility methods to do InputStream Create

Description

The list of methods to do InputStream Create are organized into topic(s).

Method

InputStreamtoInputStream(byte[] data)
converts the byte array to an input stream
ByteArrayInputStream bais = new ByteArrayInputStream(data);
InputStream isContent = new BufferedInputStream(bais);
return isContent;
InputStreamtoInputStream(CharSequence input)
Convert the specified CharSequence to an input stream, encoded as bytes using the default character encoding of the platform.
return toInputStream(input.toString());
InputStreamtoInputStream(CharSequence input, String encoding)
Convert the specified CharSequence to an input stream, encoded as bytes using the specified character encoding.
return toInputStream(input.toString(), encoding);
InputStreamtoInputStream(CharSequence input, String encoding)
Convert the specified CharSequence to an input stream, encoded as bytes using the specified character encoding.
return toInputStream(input.toString(), encoding);
InputStreamtoInputStream(File file)
to Input Stream
return new FileInputStream(file);
InputStreamtoInputStream(File file)
to Input Stream
InputStream in = new FileInputStream(file);
if (file.getName().endsWith(".gz")) {
    in = new GZIPInputStream(in);
return in;
InputStreamtoInputStream(final String content)
Convert a string into an input stream.
try {
    return toInputStream(content, DEFAULT_CHARSET);
} catch (final UnsupportedEncodingException e) {
    throw new IllegalStateException(DEFAULT_CHARSET
            + " is an unsupported encoding!  You may have a corrupted installation of java.");
InputStreamtoInputStream(final String input, final String encoding)
Convert the specified string to an input stream, encoded as bytes using the specified character encoding.
final byte[] bytes = encoding != null ? input.getBytes(encoding) : input.getBytes();
return new ByteArrayInputStream(bytes);
InputStreamtoInputStream(OutputStream out)
OutputStream -> InputStream
ByteArrayInputStream result = null;
if (out instanceof ByteArrayOutputStream) {
    try {
        result = new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray());
    } catch (Exception ex) {
        ex.printStackTrace();
return result;
InputStreamtoInputStream(String input)
to Input Stream
byte[] bytes = input.getBytes();
return new ByteArrayInputStream(bytes);