code: public JournalEntry readEntry() throws IOException {
      int firstByte = mStream.read();
      if (firstByte == -1) {
        return null;
      }
      // All journal entries start with their size in bytes written as a varint.
      int size;
      try {
        size = ProtoUtils.readRawVarint32(firstByte, mStream);
      } catch (IOException e) {
        LOG.warn("Journal entry was truncated in the size portion.");
        throw e;
      }
      if (mBuffer.length < size) {
        mBuffer = new byte[size];
      }
      // Total bytes read so far for journal entry.
      int totalBytesRead = 0;
      while (totalBytesRead < size) {
        // Bytes read in last read request.
        int latestBytesRead = mStream.read(mBuffer, totalBytesRead, size - totalBytesRead);
        if (latestBytesRead < 0) {
          break;
        }
        totalBytesRead += latestBytesRead;
      }
      if (totalBytesRead < size) {
        // This could happen if the master crashed partway through writing the final journal entry. In
        // this case, we can ignore the last entry because it was not acked to the client.
        LOG.warn("Journal entry was truncated. Expected to read {} bytes but only got {}", size,
            totalBytesRead);
        return null;
      }
  
      JournalEntry entry = JournalEntry.parseFrom(new ByteArrayInputStream(mBuffer, 0, size));
      return entry;
    }
docs: Reads a journal entry from the input stream.
  
  @return the journal entry, null if no journal entry is found