Here you can find the source of readLong(InputStream inputStream)
Parameter | Description |
---|---|
inputStream | The InputStream used to read the long |
Parameter | Description |
---|---|
IOException | Thrown if there is a problem reading from the InputStream |
public static long readLong(InputStream inputStream) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; public class Main { /**// ww w .j av a2 s. c o m * Read in a long from an InputStream * * @param inputStream * The InputStream used to read the long * @return A long, which is the next 8 bytes converted from the InputStream * @throws IOException * Thrown if there is a problem reading from the InputStream */ public static long readLong(InputStream inputStream) throws IOException { byte[] byteArray = new byte[8]; // Read in the next 8 bytes inputStream.read(byteArray); long number = convertLongFromBytes(byteArray); return number; } public static long convertLongFromBytes(byte[] bytes) { return convertLongFromBytes(bytes, 0); } public static long convertLongFromBytes(byte[] bytes, int offset) { // Convert it to an long return ((((long) bytes[offset + 7]) & 0xFF) + ((((long) bytes[offset + 6]) & 0xFF) << 8) + ((((long) bytes[offset + 5]) & 0xFF) << 16) + ((((long) bytes[offset + 4]) & 0xFF) << 24) + ((((long) bytes[offset + 3]) & 0xFF) << 32) + ((((long) bytes[offset + 2]) & 0xFF) << 40) + ((((long) bytes[offset + 1]) & 0xFF) << 48) + ((((long) bytes[offset + 0]) & 0xFF) << 56)); } }