Java InputStream Read Bytes readBytes(InputStream in, int bytesToRead, byte[] buffer, int bufferOffset)

Here you can find the source of readBytes(InputStream in, int bytesToRead, byte[] buffer, int bufferOffset)

Description

Reads bytesToRead bytes from the stream.

License

Open Source License

Parameter

Parameter Description
in a parameter
bytesToRead a parameter
buffer a parameter
bufferOffset a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static final void readBytes(InputStream in, int bytesToRead, byte[] buffer, int bufferOffset)
        throws IOException 

Method Source Code


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

public class Main {
    /**/*from  www.  j  a v a2  s.  co  m*/
     * Reads bytesToRead bytes from the stream.
     * 
     * @param in
     * @param bytesToRead
     * @param buffer
     * @param bufferOffset
     * 
     * @throws IOException
     */
    public static final void readBytes(InputStream in, int bytesToRead, byte[] buffer, int bufferOffset)
            throws IOException {
        int bytesRead = 0;
        int read;
        do {
            read = in.read(buffer, bufferOffset + bytesRead, bytesToRead);
            bytesRead += read;
            bytesToRead -= read;
        } while ((bytesToRead > 0) && (read > 0));
    }

    /**
     * Reads bytesToRead bytes from the stream.
     * 
     * @param in
     * @param bytesToRead
     * @param buffer
     * @param bufferOffset
     * 
     * @throws IOException
     */
    public static final void readBytes(BufferedInputStream in, int bytesToRead, byte[] buffer, int bufferOffset)
            throws IOException {
        int bytesRead = 0;
        int read;
        do {
            read = in.read(buffer, bufferOffset + bytesRead, bytesToRead);
            bytesRead += read;
            bytesToRead -= read;
        } while ((bytesToRead > 0) && (read > 0));
    }
}

Related

  1. readBytes(InputStream in, byte[] buf, int length)
  2. readBytes(InputStream in, byte[] buffer)
  3. readBytes(InputStream in, byte[] buffer, int maxBytesAtOnce)
  4. readBytes(InputStream in, byte[] data, int offset, int length)
  5. readBytes(InputStream in, int bufferSize, boolean forceClose)
  6. readBytes(InputStream in, int expectedBytes, long timeoutMs)
  7. readBytes(InputStream in, int len, boolean isLE)
  8. readBytes(InputStream in, int length)
  9. readBytes(InputStream in, int maxLeng)