Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static byte[] readFileContents(InputStream input) throws IOException {
        byte contents[] = new byte[10000], buf[] = new byte[1024];
        InputStream in = new BufferedInputStream(input);
        int bytes_read = 0;

        for (;;) {
            int tmp = in.read(buf, 0, buf.length);
            if (tmp == -1)
                break;
            System.arraycopy(buf, 0, contents, bytes_read, tmp);
            bytes_read += tmp;
        }

        byte[] retval = new byte[bytes_read];
        System.arraycopy(contents, 0, retval, 0, bytes_read);
        return retval;
    }
}