Java InputStream Read Long readLong(InputStream in)

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

Description

read Long

License

Apache License

Declaration

public static final 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 {
    public static final long readLong(InputStream in) throws IOException {
        byte[] b = new byte[8];
        read(in, b, 0, b.length);//from   w w  w  .  ja  va2 s .c  o m
        long l = (long) (b[0] & 0xff);
        l |= (long) (b[1] & 0xff) << 8;
        l |= (long) (b[2] & 0xff) << 16;
        l |= (long) (b[3] & 0xff) << 24;
        l |= (long) (b[4] & 0xff) << 32;
        l |= (long) (b[5] & 0xff) << 40;
        l |= (long) (b[6] & 0xff) << 48;
        l |= (long) (b[7] & 0xff) << 56;
        return l;
    }

    public static final void read(InputStream in, byte[] b, int offset, int length) throws IOException {
        for (int got = 0; length > 0;) {
            got = in.read(b, offset, length);
            if (got < 0) {
                throw new EOFException();
            }
            offset += got;
            length -= got;
        }
    }

    public static final byte read(InputStream in) throws IOException {
        int got = in.read();
        if (got < 0) {
            throw new EOFException();
        }
        return (byte) (got & 0xff);
    }
}

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 input)
  9. readLong(InputStream inputStream)