public static void write( String content,
                              OutputStream stream ) throws IOException {
        CheckArg.isNotNull(stream, "destination stream");
        boolean error = false;
        try {
            if (content != null) {
                byte[] bytes = content.getBytes();
                stream.write(bytes, 0, bytes.length);
            }
        } catch (IOException e) {
            error = true; // this error should be thrown, even if there is an error flushing/closing stream
            throw e;
        } catch (RuntimeException e) {
            error = true; // this error should be thrown, even if there is an error flushing/closing stream
            throw e;
        } finally {
            try {
                stream.flush();
            } catch (IOException e) {
                if (!error) throw e;
            } finally {
                try {
                    stream.close();
                } catch (IOException e) {
                    if (!error) throw e;
                }
            }
        }
    }
public static void write ( String content , OutputStream stream ) throws IOException { CheckArg . isNotNull ( stream , "destination stream" ) ; boolean error = false ; try { if ( content != null ) { byte [ ] bytes = content . getBytes ( ) ; stream . write ( bytes , 0 , bytes . length ) ; } } catch ( IOException e ) { error = true ; throw e ; } catch ( RuntimeException e ) { error = true ; throw e ; } finally { try { stream . flush ( ) ; } catch ( IOException e ) { if ( ! error ) throw e ; } finally { try { stream . close ( ) ; } catch ( IOException e ) { if ( ! error ) throw e ; } } } }
Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when
finished.

@param content the content to write to the stream; may be null
@param stream the stream to which the content is to be written
@throws IOException
@throws IllegalArgumentException if the stream is null