Java InputStream Read Long readLong(InputStream is)

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

Description

read Long

License

Open Source License

Declaration

public static long readLong(InputStream is) throws IOException 

Method Source Code


//package com.java2s;
/*/*from  w  ww  . java  2s. com*/
 * Copyright (c) 1998-2015 Caucho Technology -- all rights reserved
 *
 * This file is part of Baratine(TM)(TM)
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * Baratine 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 2 of the License, or
 * (at your option) any later version.
 *
 * Baratine 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, or any warranty
 * of NON-INFRINGEMENT.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Baratine; if not, write to the
 *
 *   Free Software Foundation, Inc.
 *   59 Temple Place, Suite 330
 *   Boston, MA 02111-1307  USA
 *
 * @author Scott Ferguson
 */

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

public class Main {
    public static long readLong(byte[] buffer, int offset) {
        return (((buffer[0 + offset] & 0xffL) << 56) + ((buffer[1 + offset] & 0xffL) << 48)
                + ((buffer[2 + offset] & 0xffL) << 40) + ((buffer[3 + offset] & 0xffL) << 32)
                + ((buffer[4 + offset] & 0xffL) << 24) + ((buffer[5 + offset] & 0xffL) << 16)
                + ((buffer[6 + offset] & 0xffL) << 8) + ((buffer[7 + offset] & 0xffL) << 0));
    }

    public static long readLong(InputStream is) throws IOException {
        long d0 = is.read();
        long d1 = is.read();
        long d2 = is.read();
        long d3 = is.read();

        long d4 = is.read();
        long d5 = is.read();
        long d6 = is.read();
        long d7 = is.read();

        if (d7 < 0) {
            return d7;
        }

        return ((d0 << 56) + (d1 << 48) + (d2 << 40) + (d3 << 32) + (d4 << 24) + (d5 << 16) + (d6 << 8)
                + (d7 << 0));
    }
}

Related

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