public void printHead ( final Writer writer ) throws IOException { final String eol = "\r\n" ; int pos = 0 ; try { for ( final String line : this . head ( ) ) { if ( pos == 0 && ! RsPrint . FIRST . matcher ( line ) . matches ( ) ) { throw new IllegalArgumentException ( String . format ( // @checkstyle LineLength (1 line) "first line of HTTP response \"%s\" doesn't match \"%s\" regular expression, but it should, according to RFC 7230" , line , RsPrint . FIRST ) ) ; } if ( pos > 0 && ! RsPrint . OTHERS . matcher ( line ) . matches ( ) ) { throw new IllegalArgumentException ( String . format ( // @checkstyle LineLength (1 line) "header line #%d of HTTP response \"%s\" doesn't match \"%s\" regular expression, but it should, according to RFC 7230" , pos + 1 , line , RsPrint . OTHERS ) ) ; } writer . append ( line ) ; writer . append ( eol ) ; ++ pos ; } writer . append ( eol ) ; } finally { writer . flush ( ) ; } }
Print it into a writer .