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.IOException;
import java.io.InputStream;

public class Main {
    private static byte[] readSmallerStream(final InputStream in, final int streamlength) throws IOException {
        byte[] bytes = new byte[streamlength];
        int readed = in.read(bytes);
        int patchsize = 1;
        while (patchsize > 0 && readed != streamlength) {
            patchsize = in.read(bytes, readed, streamlength - readed);
            if (patchsize > 0) {
                readed += patchsize;
            }
        }
        if (readed != streamlength) {
            throw new IOException("InputStream(" + in + ", streamlength=" + streamlength + ", readedlength="
                    + readed + ") read fail");
        }
        return bytes;
    }
}