Example usage for org.apache.commons.io.input XmlStreamReader close

List of usage examples for org.apache.commons.io.input XmlStreamReader close

Introduction

In this page you can find the example usage for org.apache.commons.io.input XmlStreamReader close.

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Closes the XmlStreamReader stream.

Usage

From source file:com.github.spyhunter99.pdf.plugin.PdfMojo.java

/**
 * @return the DecorationModel instance from <code>site.xml</code>
 * @throws MojoExecutionException if any
 *//*from w  ww.j a va2 s  .com*/
private DecorationModel getDefaultDecorationModel() throws MojoExecutionException {
    if (this.defaultDecorationModel == null) {
        final Locale locale = getDefaultLocale();

        final File descriptorFile = siteTool.getSiteDescriptor(siteDirectory, locale);
        DecorationModel decoration = null;

        if (descriptorFile.exists()) {
            XmlStreamReader reader = null;
            try {
                reader = new XmlStreamReader(descriptorFile);

                String siteDescriptorContent = IOUtil.toString(reader);

                reader.close();
                reader = null;

                siteDescriptorContent = siteTool.getInterpolatedSiteDescriptorContent(
                        new HashMap<String, String>(2), project, siteDescriptorContent);

                decoration = new DecorationXpp3Reader().read(new StringReader(siteDescriptorContent));
            } catch (XmlPullParserException e) {
                throw new MojoExecutionException("Error parsing site descriptor", e);
            } catch (IOException e) {
                throw new MojoExecutionException("Error reading site descriptor", e);
            } catch (SiteToolException e) {
                throw new MojoExecutionException("Error when interpoling site descriptor", e);
            } finally {
                IOUtil.close(reader);
            }
        }

        this.defaultDecorationModel = decoration;
    }

    return this.defaultDecorationModel;
}

From source file:org.apache.maven.plugins.pdf.stubs.ModelBuilderMavenProjectStub.java

/**
 * Stub to test the DocumentModelBuilder.
 *///from   w w w. j  av  a2s.  c om
public ModelBuilderMavenProjectStub() {
    XmlStreamReader reader = null;
    try {
        reader = new XmlStreamReader(getFile());

        final Model model = new MavenXpp3Reader().read(reader);
        setModel(model);

        reader.close();
        reader = null;

        setGroupId(model.getGroupId());
        setArtifactId(model.getArtifactId());
        setVersion(model.getVersion());
        setName(model.getName());
        setDescription(model.getDescription());
        setDevelopers(model.getDevelopers());
        setOrganization(model.getOrganization());
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        IOUtil.close(reader);
    }
}