@Override
 public int read() throws IOException {
   checkIfClosed();
   if (remaining() == 0) {
     close();
     return -1;
   }
   if (!mBufferIsValid || mBuffer.remaining() == 0) {
     updateBuffer();
   }
   mPos++;
   return BufferUtils.byteToInt(mBuffer.get());
 }