Java examples for File Path IO:Byte Array
Reads an 16 bit array length followed by the actual array data.
import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.Iterator; import org.apache.log4j.Logger; public class Main{ /**/*from w w w . ja v a 2 s. c om*/ * Reads an 16 bit array length followed by the actual array data. * * @param buf * @return the array read */ final static public byte[] readArray16(ByteBuffer buf) { int length = getUnsignedShort(buf); byte[] array = new byte[length]; buf.get(array); return array; } /** * Returns 16 unsigned bits as an integer. Big endian. * * @param buf * @return */ final public static int getUnsignedShort(ByteBuffer buf) { return buf.getShort() & 0xffff; } }