Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;
import java.io.InputStream;

import android.os.SystemClock;

public class Main {
    /**
     * @param s
     * @param b
     * @param startIdx
     * @param numBytes
     * @param timeout
     * @return
     * @throws IOException
     */
    public static int inputStreamTimedRead(InputStream s, byte[] b, int startIdx, int numBytes, int timeout)
            throws IOException {
        int retval = -1;

        int i = 0;
        for (i = 0; i < timeout; i++) {
            if (s.available() > 0) {
                retval = s.read(b, startIdx, numBytes);
                break;
            }
            SystemClock.sleep(1000);
        }
        return retval;
    }
}