Java InputStream Read Long readLong(InputStream in)

Here you can find the source of readLong(InputStream in)

Description

Read an long.

License

Open Source License

Parameter

Parameter Description
in The InputStream to read the int from

Exception

Parameter Description
IOException an exception

Return

The long read

Declaration

public static long readLong(InputStream in) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from  w  w w .j  a v  a2 s . c  om
     * Read an long.
     *
     * @param in The InputStream to read the int from
     * @return The long read
     * @throws IOException
     */
    public static long readLong(InputStream in) throws IOException {
        return ((long) in.read() << 56) | ((long) in.read() << 48) | ((long) in.read() << 40)
                | ((long) in.read() << 32) | ((long) in.read() << 24) | ((long) in.read() << 16)
                | ((long) in.read() << 8) | (long) in.read();
    }

    /**
     * Read a number of bytes.
     *
     * @param in     The InputStream to read from
     * @param length Number of bytes to read
     * @return An array containing the bytes read
     * @throws IOException
     */
    public static byte[] read(InputStream in, int length) throws IOException {
        byte[] data = new byte[length];
        int read = 0;
        while (read != length) {
            read += in.read(data, read, length - read);
        }
        return data;
    }
}

Related

  1. readLong(InputStream in)
  2. readLong(InputStream in)
  3. readLong(InputStream in)
  4. readLong(InputStream in)
  5. readLong(InputStream in)
  6. readLong(InputStream in)
  7. readLong(InputStream in)
  8. readLong(InputStream in)
  9. readLong(InputStream input)