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 {
    public static long readLong(InputStream stream) throws IOException {
        long a = readUInt(stream);
        long b = readUInt(stream);

        return a + (b << 32);
    }//from  w ww  . j  a  v a  2  s . c om

    @SuppressWarnings("PointlessBitwiseExpression")
    public static long readLong(byte[] src, int offset) {
        long a = readUInt(src, offset);
        long b = readUInt(src, offset + 4);

        return (a & 0xFFFFFFFF) + ((b & 0xFFFFFFFF) << 32);
    }

    public static long readUInt(InputStream stream) throws IOException {
        long a = stream.read();
        if (a < 0) {
            throw new IOException();
        }
        long b = stream.read();
        if (b < 0) {
            throw new IOException();
        }
        long c = stream.read();
        if (c < 0) {
            throw new IOException();
        }
        long d = stream.read();
        if (d < 0) {
            throw new IOException();
        }

        return a + (b << 8) + (c << 16) + (d << 24);
    }

    public static long readUInt(byte[] src) {
        return readUInt(src, 0);
    }

    public static long readUInt(byte[] src, int offset) {
        long a = src[offset] & 0xFF;
        long b = src[offset + 1] & 0xFF;
        long c = src[offset + 2] & 0xFF;
        long d = src[offset + 3] & 0xFF;

        return a + (b << 8) + (c << 16) + (d << 24);
    }
}

Related

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