Java InputStream Read Long readLong(InputStream in)

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

Description

read Long

License

Apache License

Declaration

static public long readLong(InputStream in) throws IOException 

Method Source Code


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

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

public class Main {
    static public long readLong(InputStream in) throws IOException {
        byte[] buffer = new byte[8];
        readFully(in, buffer, 0, 8);//from w  ww. j  a v  a  2 s  .  co m
        return (((long) buffer[0] << 56) + ((long) (buffer[1] & 255) << 48) + ((long) (buffer[2] & 255) << 40)
                + ((long) (buffer[3] & 255) << 32) + ((long) (buffer[4] & 255) << 24) + ((buffer[5] & 255) << 16)
                + ((buffer[6] & 255) << 8) + ((buffer[7] & 255) << 0));
    }

    static public void readFully(InputStream in, byte buff[]) throws IOException {
        readFully(in, buff, 0, buff.length);
    }

    static public void readFully(InputStream in, byte buff[], int offset, int length) throws IOException {
        if (length < 0)
            throw new IndexOutOfBoundsException();
        int n = 0;
        while (n < length) {
            int count = in.read(buff, offset + n, length - n);
            if (count < 0)
                throw new EOFException();
            n += count;
        }
    }

    static public byte[] read(InputStream in, int len) throws IOException {
        byte[] buff = new byte[len];
        readFully(in, buff);
        return buff;
    }
}

Related

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