Here you can find the source of readIntLittleEndian(InputStream in)
public static int readIntLittleEndian(InputStream in) throws IOException
//package com.java2s; /* // ww w . jav a 2 s . c o m * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { /** * reads an int in little endian at the given position * @param in * @param offset * @return * @throws IOException */ public static int readIntLittleEndian(ByteBuffer in, int offset) throws IOException { int ch4 = in.get(offset) & 0xff; int ch3 = in.get(offset + 1) & 0xff; int ch2 = in.get(offset + 2) & 0xff; int ch1 = in.get(offset + 3) & 0xff; return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)); } /** * reads an int in little endian at the given position * @param in * @param offset * @return * @throws IOException */ public static int readIntLittleEndian(byte[] in, int offset) throws IOException { int ch4 = in[offset] & 0xff; int ch3 = in[offset + 1] & 0xff; int ch2 = in[offset + 2] & 0xff; int ch1 = in[offset + 3] & 0xff; return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)); } public static int readIntLittleEndian(InputStream in) throws IOException { // TODO: this is duplicated code in LittleEndianDataInputStream int ch1 = in.read(); int ch2 = in.read(); int ch3 = in.read(); int ch4 = in.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) { throw new EOFException(); } return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0)); } }