/** * Create a new Writer with specified encoding. * * @param file not null file. * @param encoding not null supported encoding. * @return a writer instance for the output file using the given encoding. * @throws UnsupportedEncodingException if any. * @throws FileNotFoundException if any. * @see <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc.html">Supported encodings</a> */ public static Writer newWriter( @Nonnull File file, @Nonnull String encoding ) throws UnsupportedEncodingException, FileNotFoundException { return newWriter( new FileOutputStream( file ), encoding ); } }
/** * Generates a (temporary) POM file from the plugin configuration. It's the responsibility of the caller to delete * the generated file when no longer needed. * * @return The path to the generated POM file, never <code>null</code>. * @throws MojoExecutionException If the POM file could not be generated. */ private File generatePomFile() throws MojoExecutionException { Model model = generateModel(); Writer writer = null; try { File pomFile = File.createTempFile( "mvninstall", ".pom" ); writer = WriterFactory.newXmlWriter( pomFile ); new MavenXpp3Writer().write( writer, model ); return pomFile; } catch ( IOException e ) { throw new MojoExecutionException( "Error writing temporary POM file: " + e.getMessage(), e ); } finally { IOUtil.close( writer ); } }
try fileWriter = WriterFactory.newXmlWriter( new FileOutputStream( f ) ); final Xpp3Dom dom = new Xpp3Dom( "component-set" ); final Xpp3Dom componentDom = new Xpp3Dom( "components" );