protected final void write ( @ NotNull final GeneratedArtifact artifact ) throws GenerateException { Contract . requireArgNotNull ( "artifact" , artifact ) ; final GeneratedFile genFile = getTargetFile ( artifact . getName ( ) , artifact . getPathAndName ( ) , null ) ; if ( genFile . isSkip ( ) ) { LOG . debug ( "Omitted already existing file: {} [{}]" , genFile , artifact ) ; } else { LOG . debug ( "Writing file: {} [{}]" , genFile , artifact ) ; try { final OutputStream out = new BufferedOutputStream ( new FileOutputStream ( genFile . getTmpFile ( ) ) ) ; try { out . write ( artifact . getData ( ) ) ; } finally { out . close ( ) ; } genFile . persist ( ) ; } catch ( final IOException ex ) { throw new GenerateException ( "Error writing artifact '" + artifact + "' to '" + artifact . getPathAndName ( ) + "'!" , ex ) ; } } }
Writes a generated artifact to a file .