Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static byte[] readFromInputStream(InputStream inputStream) throws IOException {

        if (inputStream == null)
            return null;

        BufferedInputStream bin = new BufferedInputStream(inputStream);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        byte[] buffer = new byte[1024 * 8];
        int len = 0;

        while ((len = bin.read(buffer)) != -1) {
            bos.write(buffer, 0, len);
        }

        bin.close();

        return bos.toByteArray();
    }
}