Java File Read via ByteBuffer readTwoByteInt(byte[] array, int start)

Here you can find the source of readTwoByteInt(byte[] array, int start)

Description

read Two Byte Int

License

Open Source License

Declaration

public static int readTwoByteInt(byte[] array, int start) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static int readTwoByteInt(ByteBuffer buffer, int start) {
        final byte b1 = buffer.get(start);
        final byte b2 = buffer.get(start + 1);
        return ((b1 & 255) << 8) + (b2 & 255);
    }/* w w  w .  j  a v a 2 s  .  co m*/

    public static int readTwoByteInt(byte[] array, int start) {
        return ((array[start] & 255) << 8) + (array[start + 1] & 255);
    }
}

Related

  1. readStringFromFile(String path)
  2. readStringFromSocketChannel(SocketChannel sc)
  3. readStringInUTF8(DataInput in)
  4. readToBuffer(final String filename)
  5. readToByteArray(String fname)
  6. readTxtFromFile(File file)
  7. readUint32(final DataInput di)
  8. readUint32AsInt(DataInput di)
  9. readUintLE(byte[] bytes, int pointer, int size)