示例#1
0
 /**
  * Parse a header from a byte buffer. The buffer's position will be advanced to the end of the
  * header.
  *
  * @param buf The byte buffer.
  * @return The header.
  */
 public static BinaryHeader fromHeader(ByteBuffer buf) {
   Preconditions.checkArgument(buf.remaining() >= HEADER_SIZE, "buffer not large enough");
   byte[] magic = new byte[2];
   buf.get(magic);
   if (!Arrays.equals(magic, BinaryFormat.HEADER_MAGIC)) {
     throw new IllegalArgumentException("invalid magic");
   }
   short word = buf.getShort();
   BinaryFormat format = BinaryFormat.fromFlags(word);
   int nratings = buf.getInt();
   int nusers = buf.getInt();
   int nitems = buf.getInt();
   return new BinaryHeader(format, nratings, nusers, nitems);
 }