Java InputStream Create toInputStream(OutputStream out)

Here you can find the source of toInputStream(OutputStream out)

Description

OutputStream -> InputStream

License

Open Source License

Parameter

Parameter Description
out a parameter

Declaration

public static InputStream toInputStream(OutputStream out) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

public class Main {
    /**/* w w w . j  a v  a2  s.  co m*/
     * 
     * OutputStream -> InputStream
     * 
     * @param out
     * @return
     */
    public static InputStream toInputStream(OutputStream out) {
        ByteArrayInputStream result = null;
        if (out instanceof ByteArrayOutputStream) {
            try {
                result = new ByteArrayInputStream(
                        ((ByteArrayOutputStream) out).toByteArray());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }
}

Related

  1. toInputStream(CharSequence input, String encoding)
  2. toInputStream(File file)
  3. toInputStream(File file)
  4. toInputStream(final String content)
  5. toInputStream(final String input, final String encoding)
  6. toInputStream(String input)
  7. toInputStream(String input)
  8. toInputStream(String input, String encoding)
  9. toInputStream(String result, String encoding)