Java InputStream Read Long readLong(InputStream input)

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

Description

Read long, little endian.

License

Open Source License

Parameter

Parameter Description
input a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static final long readLong(InputStream input) throws IOException 

Method Source Code

//package com.java2s;
/**/*from   ww w . ja v  a2 s  .  co  m*/
 * File: $HeadURL: https://hdt-java.googlecode.com/svn/trunk/hdt-java/src/org/rdfhdt/hdt/util/io/IOUtil.java $
 * Revision: $Rev: 194 $
 * Last modified: $Date: 2013-03-04 21:30:01 +0000 (lun, 04 mar 2013) $
 * Last modified by: $Author: mario.arias $
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contacting the authors:
 *   Mario Arias:               mario.arias@deri.org
 *   Javier D. Fernandez:       jfergar@infor.uva.es
 *   Miguel A. Martinez-Prieto: migumar2@infor.uva.es
 *   Alejandro Andres:          fuzzy.alej@gmail.com
 */

import java.io.EOFException;

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

public class Main {
    /**
     * Read long, little endian.
     * @param input
     * @return
     * @throws IOException
     */
    public static final long readLong(InputStream input) throws IOException {
        int n = 0;
        byte[] readBuffer = new byte[8];
        while (n < 8) {
            int count = input.read(readBuffer, n, 8 - n);
            if (count < 0)
                throw new EOFException();
            n += count;
        }

        return ((long) readBuffer[7] << 56) + ((long) (readBuffer[6] & 255) << 48)
                + ((long) (readBuffer[5] & 255) << 40) + ((long) (readBuffer[4] & 255) << 32)
                + ((long) (readBuffer[3] & 255) << 24) + ((readBuffer[2] & 255) << 16)
                + ((readBuffer[1] & 255) << 8) + ((readBuffer[0] & 255));
    }
}

Related

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