private void writeRecord ( OutputStream out , HttpHeaders headers , byte [ ] contents ) throws IOException { if ( contents == null ) { headers . add ( CONTENT_LENGTH , "0" ) ; } else { headers . add ( CONTENT_LENGTH , String . valueOf ( contents . length ) ) ; } out . write ( WARC_ID . getBytes ( DEFAULT_ENCODING ) ) ; out . write ( CR ) ; out . write ( LF ) ; // NOTE: HttpHeaders.write() method includes the trailing CRLF. // So we don't need to write it out here. headers . write ( out ) ; if ( contents != null ) { out . write ( contents ) ; } // Emit the 2 trailing CRLF sequences. out . write ( CR ) ; out . write ( LF ) ; out . write ( CR ) ; out . write ( LF ) ; }
Write the headers and contents as a WARC record to the given output stream .