Java InputStream Create getInputStream(FileInputStream fileInput)

Here you can find the source of getInputStream(FileInputStream fileInput)

Description

get Input Stream

License

Open Source License

Declaration

public static InputStream getInputStream(FileInputStream fileInput) 

Method Source Code


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

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

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static InputStream getInputStream(FileInputStream fileInput) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024 * 4];
        int n = -1;
        InputStream inputStream = null;
        try {//from ww w  .j a v a2s . co  m
            while ((n = fileInput.read(buffer)) != -1) {
                baos.write(buffer, 0, n);
            }
            byte[] byteArray = baos.toByteArray();
            inputStream = new ByteArrayInputStream(byteArray);
            return inputStream;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. getInputStream(File f)
  2. getInputStream(File jarFile, String fileName)
  3. getInputStream(File tarFile)
  4. getInputStream(File tarFile)
  5. getInputStream(File TheFile)
  6. getInputStream(final File file)
  7. getInputStream(final File file)
  8. getInputStream(final File file, final boolean createFile)
  9. getInputStream(final Serializable obj)