@SuppressWarnings("ResultOfMethodCallIgnored") public static void pipeInputToOutputStream(InputStream in,File fileOut,boolean ignoreErrors) throws IOException {
  if (fileOut == null) {
    logger.error("The output filename doesn't exist or is invalid");
    if (!ignoreErrors) {
      throw new IOException("The output filename doesn't exist or is invalid");
    }
  }
 else {
    File parent=fileOut.getParentFile();
    if (parent != null && !parent.exists()) {
      parent.mkdirs();
    }
    OutputStream fileStream=null;
    try {
      fileStream=new FileOutputStream(fileOut);
      pipeInputToOutputStream(in,fileStream,true,ignoreErrors);
    }
 catch (    IOException e) {
      if (fileStream != null) {
        try {
          fileStream.close();
        }
 catch (        IOException ex) {
          logger.error("Cannot close stream - {}",ex.getMessage());
        }
      }
      if (!ignoreErrors) {
        throw e;
      }
    }
  }
}

@ SuppressWarnings ( "ResultOfMethodCallIgnored" ) public static void pipeInputToOutputStream ( InputStream in , File fileOut , boolean ignoreErrors ) throws IOException { if ( fileOut == null ) { logger . error ( "The output filename doesn't exist or is invalid" ) ; if ( ! ignoreErrors ) { throw new IOException ( "The output filename doesn't exist or is invalid" ) ; } } else { File parent = fileOut . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } OutputStream fileStream = null ; try { fileStream = new FileOutputStream ( fileOut ) ; pipeInputToOutputStream ( in , fileStream , true , ignoreErrors ) ; } catch ( IOException e ) { if ( fileStream != null ) { try { fileStream . close ( ) ; } catch ( IOException ex ) { logger . error ( "Cannot close stream - {}" , ex . getMessage ( ) ) ; } } if ( ! ignoreErrors ) { throw e ; } } } }
convenient way of sending data from an input stream to an output file in the most efficient way possible
