Java InputStream Read Long readLongLE(InputStream in)

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

Description

read little-endian long

License

Open Source License

Declaration

public static long readLongLE(InputStream in) throws IOException 

Method Source Code

//package com.java2s;

import java.io.DataInput;

import java.io.EOFException;

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

public class Main {
    /**/*from w  ww  . j a v a2 s.c  o m*/
     * read little-endian long
     */
    public static long readLongLE(InputStream in) throws IOException {
        long b0 = in.read();
        long b1 = in.read();
        long b2 = in.read();
        long b3 = in.read();
        long b4 = in.read();
        long b5 = in.read();
        long b6 = in.read();
        long b7 = in.read();
        if ((b7 < 0) || (b6 < 0) || (b5 < 0) || (b4 < 0) || (b3 < 0) || (b2 < 0) || (b1 < 0) || (b0 < 0)) {
            throw new EOFException();
        }
        return (b0 << 0) + (b1 << 8) + (b2 << 16) + (b3 << 24) | (b4 << 32) + (b5 << 40) + (b6 << 48) + (b7 << 56);
    }

    /**
     * read little-endian long
     */
    public static long readLongLE(DataInput in) throws IOException {
        long b0 = in.readUnsignedByte();
        long b1 = in.readUnsignedByte();
        long b2 = in.readUnsignedByte();
        long b3 = in.readUnsignedByte();
        long b4 = in.readUnsignedByte();
        long b5 = in.readUnsignedByte();
        long b6 = in.readUnsignedByte();
        long b7 = in.readUnsignedByte();
        return (b0 << 0) + (b1 << 8) + (b2 << 16) + (b3 << 24) | (b4 << 32) + (b5 << 40) + (b6 << 48) + (b7 << 56);
    }
}

Related

  1. readLong(InputStream stream)
  2. readLong(InputStream stream)
  3. readLong(InputStream stream)
  4. readLongFrom(InputStream is)
  5. readLongLE(InputStream in)