Example usage for javax.xml.stream XMLStreamWriter close

List of usage examples for javax.xml.stream XMLStreamWriter close

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter close.

Prototype

public void close() throws XMLStreamException;

Source Link

Document

Close this writer and free any resources associated with the writer.

Usage

From source file:org.apache.axiom.om.impl.llom.OMElementImpl.java

public String toStringWithConsume() throws XMLStreamException {
    StringWriter writer = new StringWriter();
    XMLStreamWriter writer2 = StAXUtils.createXMLStreamWriter(writer);
    try {/*from   w  w w . j a v  a  2 s  .  com*/
        this.serializeAndConsume(writer2);
        writer2.flush();
    } finally {
        writer2.close();
    }
    return writer.toString();
}

From source file:org.apache.axiom.om.impl.llom.OMElementImpl.java

public String toString() {
    StringWriter writer = new StringWriter();
    try {/*from www.  ja v  a  2  s  . c o  m*/
        XMLStreamWriter writer2 = StAXUtils.createXMLStreamWriter(writer);
        try {
            this.serialize(writer2);
            writer2.flush();
        } finally {
            writer2.close();
        }
    } catch (XMLStreamException e) {
        throw new RuntimeException("Can not serialize OM Element " + this.getLocalName(), e);
    }
    return writer.toString();
}

From source file:org.apache.axiom.om.impl.llom.OMNodeImpl.java

public void serialize(OutputStream output) throws XMLStreamException {
    XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
    try {//www  . java2s . c  o m
        serialize(xmlStreamWriter);
    } finally {
        xmlStreamWriter.close();
    }
}

From source file:org.apache.axiom.om.impl.llom.OMNodeImpl.java

public void serialize(Writer writer) throws XMLStreamException {
    XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
    try {//  w ww  . ja v a 2s .c om
        serialize(xmlStreamWriter);
    } finally {
        xmlStreamWriter.close();
    }
}

From source file:org.apache.axiom.om.impl.llom.OMNodeImpl.java

public void serializeAndConsume(OutputStream output) throws XMLStreamException {
    XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
    try {//from  www.j a v a 2 s.  c om
        serializeAndConsume(xmlStreamWriter);
    } finally {
        xmlStreamWriter.close();
    }
}

From source file:org.apache.axiom.om.impl.llom.OMNodeImpl.java

public void serializeAndConsume(Writer writer) throws XMLStreamException {
    XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
    try {/*from  w ww.  j  a v a2s .  c  o  m*/
        serializeAndConsume(xmlStreamWriter);
    } finally {
        xmlStreamWriter.close();
    }
}

From source file:org.apache.axis2.jaxws.message.util.Reader2Writer.java

/**
 * Utility method to write the reader contents to a String
 * @return String//from  w  w w  . j a v a2 s  . c o  m
 */
public String getAsString() throws XMLStreamException {
    StringWriter sw = new StringWriter();
    XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(sw);

    // Write the reader to the writer
    outputTo(writer);

    // Flush the writer and get the String
    writer.flush();
    sw.flush();
    String str = sw.toString();
    writer.close();
    return str;
}

From source file:org.apache.nifi.authorization.FileAccessPolicyProvider.java

@Override
public String getFingerprint() throws AuthorizationAccessException {
    final List<AccessPolicy> policies = new ArrayList<>(getAccessPolicies());
    Collections.sort(policies, Comparator.comparing(AccessPolicy::getIdentifier));

    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {/*from   www . j a v a  2s. com*/
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("accessPolicies");

        for (AccessPolicy policy : policies) {
            writePolicy(writer, policy);
        }

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
                // nothing to do here
            }
        }
    }

    return out.toString();
}

From source file:org.apache.nifi.authorization.FileUserGroupProvider.java

@Override
public String getFingerprint() throws AuthorizationAccessException {
    final UserGroupHolder usersAndGroups = userGroupHolder.get();

    final List<User> users = new ArrayList<>(usersAndGroups.getAllUsers());
    Collections.sort(users, Comparator.comparing(User::getIdentifier));

    final List<Group> groups = new ArrayList<>(usersAndGroups.getAllGroups());
    Collections.sort(groups, Comparator.comparing(Group::getIdentifier));

    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {/*  w w  w  .j  ava2s  . com*/
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("tenants");

        for (User user : users) {
            writeUser(writer, user);
        }
        for (Group group : groups) {
            writeGroup(writer, group);
        }

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
                // nothing to do here
            }
        }
    }

    return out.toString();
}

From source file:org.apache.nifi.authorization.StandardManagedAuthorizer.java

@Override
public String getFingerprint() throws AuthorizationAccessException {
    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {//w ww. j a v a 2 s .  co m
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("managedAuthorizations");

        writer.writeStartElement(ACCESS_POLICY_PROVIDER_ELEMENT);
        if (accessPolicyProvider instanceof ConfigurableAccessPolicyProvider) {
            writer.writeCharacters(((ConfigurableAccessPolicyProvider) accessPolicyProvider).getFingerprint());
        }
        writer.writeEndElement();

        writer.writeStartElement(USER_GROUP_PROVIDER_ELEMENT);
        if (userGroupProvider instanceof ConfigurableUserGroupProvider) {
            writer.writeCharacters(((ConfigurableUserGroupProvider) userGroupProvider).getFingerprint());
        }
        writer.writeEndElement();

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
                // nothing to do here
            }
        }
    }

    return out.toString();
}