public static WarcRecord readNextWarcRecord(DataInputStream in) throws IOException {
    // LOG.info("Starting read of WARC record");
    StringBuffer recordHeader=new StringBuffer();
    byte[] recordContent=readNextRecord(in, recordHeader);
    if (recordContent==null) { 
      // LOG.info("WARC content is null - file is complete");
      return null; 
    }
    
    // extract out our header information
    String thisHeaderString=recordHeader.toString();


    String[] headerLines=thisHeaderString.split(LINE_ENDING);

    WarcRecord retRecord=new WarcRecord();
    for (int i=0; i < headerLines.length; i++) {
      String[] pieces=headerLines[i].split(":", 2);
      if (pieces.length!=2) { 
        retRecord.addHeaderMetadata(pieces[0], "");
        continue; 
      }
      String thisKey=pieces[0].trim();
      String thisValue=pieces[1].trim();

      // check for known keys
      if (thisKey.equals("WARC-Type")) { 
        // LOG.info("Setting WARC record type: " + thisValue);
        retRecord.setWarcRecordType(thisValue);
      } else if (thisKey.equals("WARC-Date")) {
        retRecord.setWarcDate(thisValue);
      } else if (thisKey.equals("WARC-Record-ID")) {
        // LOG.info("Setting WARC record ID: " + thisValue);
        retRecord.setWarcUUID(thisValue);
      } else if (thisKey.equals("Content-Type")) {
        retRecord.setWarcContentType(thisValue);
      } else {
        retRecord.addHeaderMetadata(thisKey, thisValue);
      }
    }

    // set the content
    retRecord.setContent(recordContent);
    
    return retRecord;
  }