Java InputStream Read Long readLong(InputStream in)

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

Description

read Long

License

Open Source License

Declaration

public static long readLong(InputStream in) throws IOException 

Method Source Code


//package com.java2s;
/*//from  w ww. j  a  va 2  s  .  com
   This file is part of ADBCJ.
    
   ADBCJ is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
    
   ADBCJ is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with ADBCJ.  If not, see <http://www.gnu.org/licenses/>.
    
   Copyright 2008  Mike Heath
 */

import java.io.*;

public class Main {
    public static long readLong(InputStream in) throws IOException {
        long b0 = safeRead(in);
        long b1 = safeRead(in);
        long b2 = safeRead(in);
        long b3 = safeRead(in);
        long b4 = safeRead(in);
        long b5 = safeRead(in);
        long b6 = safeRead(in);
        long b7 = safeRead(in);
        return b7 << 56 | b6 << 48 | b5 << 40 | b4 << 32 | b3 << 24 | b2 << 16 | b1 << 8 | b0;
    }

    /**
     * @return an unsigned byte
     * @throws IOException  if there is an error reading from the stream
     * @throws EOFException if the end of the stream is reached
     */
    public static int safeRead(InputStream in) throws IOException {
        int i = in.read();
        if (i < 0) {
            throw new EOFException();
        }
        return i;
    }
}

Related

  1. readLong(InputStream i)
  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 in)