Java File Read via ByteBuffer readInt(InputStream inputStream)

Here you can find the source of readInt(InputStream inputStream)

Description

read Int

License

Apache License

Declaration

public static int readInt(InputStream inputStream) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    public static int readInt(InputStream inputStream) throws IOException {
        byte[] bytesToRead = new byte[4];
        int readBytes = inputStream.read(bytesToRead);
        if (readBytes == -1) {
            return -1;
        }//from w ww  . jav  a  2s .c  o m

        ByteBuffer buffer = ByteBuffer.wrap(bytesToRead);
        buffer.order(ByteOrder.LITTLE_ENDIAN);

        return buffer.getInt();
    }
}

Related

  1. readInt(byte[] bytes, int offset, java.nio.ByteOrder byteorder)
  2. readInt(byte[] in)
  3. readInt(ByteArrayInputStream bin)
  4. readInt(InputStream in, ByteOrder order)
  5. readInt(InputStream input)
  6. readInt(ReadableByteChannel channel)
  7. readInt(ReadableByteChannel channel)
  8. readInt16(DataInput di)
  9. readIntArray(DataInput input)