public static ByteBuffer read(DataInput in, int length) throws IOException { if (length == 0) return EMPTY_BYTE_BUFFER; if (in instanceof FileDataInput) return ((FileDataInput) in).readBytes(length); byte[] buff = new byte[length]; in.readFully(buff); return ByteBuffer.wrap(buff); }