DataOutputStream writeHeaderAndWrapStream ( OutputStream os ) throws IOException { DataOutputStream dos = new DataOutputStream ( os ) ; dos . writeBoolean ( imageCodec != null ) ; if ( imageCodec != null ) { String codecClassName = imageCodec . getClass ( ) . getCanonicalName ( ) ; Text . writeString ( dos , codecClassName ) ; return new DataOutputStream ( imageCodec . createOutputStream ( os ) ) ; } else { // use a buffered output stream return new DataOutputStream ( new BufferedOutputStream ( os ) ) ; } }
Write out a header to the given stream that indicates the chosen compression codec and return the same stream wrapped with that codec . If no codec is specified simply adds buffering to the stream so that the returned stream is always buffered .