Java InputStream Read Long readLong(InputStream stream)

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

Description

read Long

License

Open Source License

Declaration

public static long readLong(InputStream stream) 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 {
    private final static int BITS_IN_BYTE = 8;
    private final static int BITS_IN_LONG = 64;

    public static long readLong(InputStream stream) throws IOException {
        long result = 0;
        for (int i = 0; i < BITS_IN_LONG; i += BITS_IN_BYTE)
            result |= ((long) readByte(stream)) << i;
        return result;
    }/*from  www. j a va 2 s  .com*/

    private static int readByte(InputStream stream) throws IOException {
        int result = stream.read();
        if (result == -1)
            throw new IOException("Try to read from empty stream!");
        return result;
    }
}

Related

  1. readLong(InputStream is)
  2. readLong(InputStream is)
  3. readLong(InputStream is)
  4. readLong(InputStream is)
  5. readLong(InputStream is)
  6. readLong(InputStream stream)
  7. readLong(InputStream stream)
  8. readLong(InputStream stream)
  9. readLongFrom(InputStream is)