Example usage for javax.xml.stream XMLStreamWriter flush

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

Introduction

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

Prototype

public void flush() throws XMLStreamException;

Source Link

Document

Write any cached data to the underlying output mechanism.

Usage

From source file:org.wso2.carbon.registry.core.jdbc.Repository.java

private void dumpRecursively(String path, XMLStreamWriter xmlWriter, Writer writer)
        throws RegistryException, XMLStreamException {
    // adding resource meta data
    ResourceImpl resource = resourceDAO.getResourceMetaData(path);
    if (resource == null) {
        return;/*  w ww.ja  v  a  2 s  .co m*/
    }

    if (!AuthorizationUtils.authorize(path, ActionConstants.GET)) {
        String msg = getUserNotAuthorizedMsg() + "check out the path " + path + ".";
        log.warn(msg);
        throw new AuthorizationFailedException(msg);
    }

    xmlWriter.writeStartElement(DumpConstants.RESOURCE);

    // adding path as an attribute, updated dump has name instead of path
    xmlWriter.writeAttribute(DumpConstants.RESOURCE_NAME, RegistryUtils.getResourceName(path));

    //adding dump attribute
    xmlWriter.writeAttribute(DumpConstants.RESOURCE_STATUS, DumpConstants.RESOURCE_DUMP);

    // adding isCollection as an attribute
    xmlWriter.writeAttribute(DumpConstants.RESOURCE_IS_COLLECTION,
            (resource instanceof CollectionImpl) ? DumpConstants.RESOURCE_IS_COLLECTION_TRUE
                    : DumpConstants.RESOURCE_IS_COLLECTION_FALSE);
    OMElement child;

    // set media type
    String mediaType = resource.getMediaType();
    OMFactory factory = OMAbstractFactory.getOMFactory();
    child = factory.createOMElement(new QName(DumpConstants.MEDIA_TYPE));
    child.setText(mediaType);
    child.serialize(xmlWriter);

    // set version
    long version = resource.getVersionNumber();
    child = factory.createOMElement(new QName(DumpConstants.VERSION));
    child.setText(version + "");
    child.serialize(xmlWriter);

    // set creator
    String creator = resource.getAuthorUserName();
    child = factory.createOMElement(new QName(DumpConstants.CREATOR));
    child.setText(creator);
    child.serialize(xmlWriter);

    // set createdTime
    Date createdTime = resource.getCreatedTime();
    child = factory.createOMElement(new QName(DumpConstants.CREATED_TIME));
    child.setText(Long.toString(createdTime.getTime()));
    child.serialize(xmlWriter);

    // set updater
    String updater = resource.getLastUpdaterUserName();
    child = factory.createOMElement(new QName(DumpConstants.LAST_UPDATER));
    child.setText(updater);
    child.serialize(xmlWriter);

    // set LastModified
    Date lastModified = resource.getLastModified();
    child = factory.createOMElement(new QName(DumpConstants.LAST_MODIFIED));
    child.setText(Long.toString(lastModified.getTime()));
    child.serialize(xmlWriter);

    // set UUID
    String uuid = resource.getUUID();
    child = factory.createOMElement(new QName(DumpConstants.UUID));
    child.setText(uuid);
    child.serialize(xmlWriter);

    // set Description
    String description = resource.getDescription();
    child = factory.createOMElement(new QName(DumpConstants.DESCRIPTION));
    child.setText(description);
    child.serialize(xmlWriter);

    // fill properties
    resourceDAO.fillResourceProperties(resource);
    Properties properties = resource.getProperties();
    if (properties != null && properties.size() > 0) {
        // properties will be kept inside the <properties> element
        OMElement propertiesOM = factory.createOMElement(new QName(DumpConstants.PROPERTIES));
        for (Object keyObject : properties.keySet()) {
            String key = (String) keyObject;
            List<String> propValues = resource.getPropertyValues(key);
            for (String value : propValues) {
                OMElement propertyOM = factory.createOMElement(new QName(DumpConstants.PROPERTY_ENTRY));

                // adding the key and value as attributes
                OMAttribute keyAttribute = factory.createOMAttribute(DumpConstants.PROPERTY_ENTRY_KEY, null,
                        key);
                propertyOM.addAttribute(keyAttribute);

                if (value != null) {
                    propertyOM.setText(value);
                }

                propertiesOM.addChild(propertyOM);
            }
        }
        propertiesOM.serialize(xmlWriter);
    }
    // getting comment information
    Comment[] comments = commentsDAO.getComments(resource);
    if (comments != null && comments.length > 0) {
        child = factory.createOMElement(new QName(DumpConstants.COMMENTS));
        for (Comment comment : comments) {
            OMElement commentElement = factory.createOMElement(new QName(DumpConstants.COMMENT_ENTRY));
            String user = comment.getAuthorUserName();
            String text = comment.getText();

            OMElement userElement = factory.createOMElement(new QName(DumpConstants.COMMENT_ENTRY_USER));
            userElement.setText(user);
            commentElement.addChild(userElement);

            OMElement textElement = factory.createOMElement(new QName(DumpConstants.COMMENT_ENTRY_TEXT));
            textElement.setText(text);
            commentElement.addChild(textElement);

            child.addChild(commentElement);
        }
        child.serialize(xmlWriter);
    }
    // getting tagging
    TaggingDO[] taggings = tagsDAO.getTagging(resource);
    if (taggings != null && taggings.length > 0) {
        child = factory.createOMElement(new QName(DumpConstants.TAGGINGS));
        for (TaggingDO tagging : taggings) {
            OMElement taggingElement = factory.createOMElement(new QName(DumpConstants.TAGGING_ENTRY));
            String user = tagging.getTaggedUserName();
            Date date = tagging.getTaggedTime();
            String tagName = tagging.getTagName();

            OMElement userElement = factory.createOMElement(new QName(DumpConstants.TAGGING_ENTRY_USER));
            userElement.setText(user);
            taggingElement.addChild(userElement);

            OMElement dateElement = factory.createOMElement(new QName(DumpConstants.TAGGING_ENTRY_DATE));
            String dateString = Long.toString(date.getTime());
            dateElement.setText(dateString);
            taggingElement.addChild(dateElement);

            OMElement textElement = factory.createOMElement(new QName(DumpConstants.TAGGING_ENTRY_TAG_NAME));
            textElement.setText(tagName);
            taggingElement.addChild(textElement);

            child.addChild(taggingElement);
        }
        child.serialize(xmlWriter);
    }
    // getting ratings
    RatingDO[] ratings = ratingsDAO.getResourceRatingDO(resource);
    if (ratings != null && ratings.length > 0) {
        child = factory.createOMElement(new QName(DumpConstants.RATINGS));
        for (RatingDO rating : ratings) {
            OMElement ratingElement = factory.createOMElement(new QName(DumpConstants.RATING_ENTRY));
            String user = rating.getRatedUserName();
            Date date = rating.getRatedTime();
            int rate = rating.getRating();

            OMElement userElement = factory.createOMElement(new QName(DumpConstants.RATING_ENTRY_USER));
            userElement.setText(user);
            ratingElement.addChild(userElement);

            OMElement dateElement = factory.createOMElement(new QName(DumpConstants.RATING_ENTRY_DATE));
            String dateString = Long.toString(date.getTime());
            dateElement.setText(dateString);
            ratingElement.addChild(dateElement);

            OMElement textElement = factory.createOMElement(new QName(DumpConstants.RATING_ENTRY_RATE));
            String rateString = String.valueOf(rate);
            textElement.setText(rateString);
            ratingElement.addChild(textElement);

            child.addChild(ratingElement);
        }
        child.serialize(xmlWriter);
    }

    Association[] associations = associationDAO.getAllAssociations(path);
    if (associations != null && associations.length > 0) {
        child = factory.createOMElement(new QName(DumpConstants.ASSOCIATIONS));
        for (Association association : associations) {
            OMElement associationElement = factory.createOMElement(new QName(DumpConstants.ASSOCIATION_ENTRY));
            String source = association.getSourcePath();
            String destination = association.getDestinationPath();
            String type = association.getAssociationType();

            // getting the relative paths
            source = RegistryUtils.getRelativeAssociationPath(source, path);

            if (destination.startsWith(RegistryConstants.ROOT_PATH)) {
                // we are treating this as a path
                destination = RegistryUtils.getRelativeAssociationPath(destination, path);
            } else {
                // then the destination is an external association
                destination = DumpConstants.EXTERNAL_ASSOCIATION_DESTINATION_PREFIX + destination;
            }

            OMElement sourceElement = factory
                    .createOMElement(new QName(DumpConstants.ASSOCIATION_ENTRY_SOURCE));
            sourceElement.setText(source);
            associationElement.addChild(sourceElement);

            OMElement destinationElement = factory
                    .createOMElement(new QName(DumpConstants.ASSOCIATION_ENTRY_DESTINATION));
            destinationElement.setText(destination);
            associationElement.addChild(destinationElement);

            OMElement typeElement = factory.createOMElement(new QName(DumpConstants.ASSOCIATION_ENTRY_TYPE));
            typeElement.setText(type);
            associationElement.addChild(typeElement);

            child.addChild(associationElement);
        }
        child.serialize(xmlWriter);
    }

    // adding contents..
    if (!(resource instanceof CollectionImpl)) {
        resourceDAO.fillResourceContent(resource);

        byte[] content = (byte[]) resource.getContent();
        if (content != null) {
            child = factory.createOMElement(new QName(DumpConstants.CONTENT));
            child.setText(Base64.encode(content));
            child.serialize(xmlWriter);
        }
    }

    // getting children and applying dump recursively
    if (resource instanceof CollectionImpl) {
        CollectionImpl collection = (CollectionImpl) resource;
        resourceDAO.fillChildren(collection, 0, -1);
        String childPaths[] = collection.getChildren();

        xmlWriter.writeStartElement(DumpConstants.CHILDREN);
        OMText emptyText = factory.createOMText("");
        emptyText.serialize(xmlWriter);
        xmlWriter.flush();
        for (String childPath : childPaths) {
            // we would be writing the start element of the child and its name here.
            try {
                String resourceName = RegistryUtils.getResourceName(childPath);
                writer.write("<resource name=\"" + resourceName + "\"");
                writer.flush();
            } catch (IOException e) {
                String msg = "Error in writing the start element for the path: " + childPath + ".";
                log.error(msg, e);
                throw new RegistryException(msg, e);
            }
            recursionRepository.dumpRecursively(childPath, new DumpWriter(writer));
        }
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();
    xmlWriter.flush();
}

From source file:org.wso2.carbon.registry.core.jdbc.Repository.java

private void dumpRecursivelyLight(String path, XMLStreamWriter xmlWriter, Writer writer)
        throws RegistryException, XMLStreamException {
    // adding resource meta data
    ResourceImpl resource = resourceDAO.getResourceMetaData(path);
    if (resource == null) {
        return;//from   w  w w.  j  a v a  2 s  . co  m
    }

    if (!AuthorizationUtils.authorize(path, ActionConstants.GET)) {
        String msg = getUserNotAuthorizedMsg() + "check out the path " + path + ".";
        log.warn(msg);
        throw new AuthorizationFailedException(msg);
    }

    xmlWriter.writeStartElement(DumpConstants.RESOURCE);

    // adding path as an attribute, updated dump has name instead of path
    xmlWriter.writeAttribute(DumpConstants.RESOURCE_NAME, RegistryUtils.getResourceName(path));

    // adding isCollection as an attribute
    xmlWriter.writeAttribute(DumpConstants.RESOURCE_IS_COLLECTION,
            (resource instanceof CollectionImpl) ? DumpConstants.RESOURCE_IS_COLLECTION_TRUE
                    : DumpConstants.RESOURCE_IS_COLLECTION_FALSE);
    OMElement child;

    // set media type
    String mediaType = resource.getMediaType();
    OMFactory factory = OMAbstractFactory.getOMFactory();
    child = factory.createOMElement(new QName(DumpConstants.MEDIA_TYPE));
    child.setText(mediaType);
    child.serialize(xmlWriter);

    // set version
    long version = resource.getVersionNumber();
    child = factory.createOMElement(new QName(DumpConstants.VERSION));
    child.setText(version + "");
    child.serialize(xmlWriter);

    // set creator
    String creator = resource.getAuthorUserName();
    child = factory.createOMElement(new QName(DumpConstants.CREATOR));
    child.setText(creator);
    child.serialize(xmlWriter);

    // set createdTime
    Date createdTime = resource.getCreatedTime();
    child = factory.createOMElement(new QName(DumpConstants.CREATED_TIME));
    child.setText(Long.toString(createdTime.getTime()));
    child.serialize(xmlWriter);

    // set updater
    String updater = resource.getLastUpdaterUserName();
    child = factory.createOMElement(new QName(DumpConstants.LAST_UPDATER));
    child.setText(updater);
    child.serialize(xmlWriter);

    // set LastModified
    Date lastModified = resource.getLastModified();
    child = factory.createOMElement(new QName(DumpConstants.LAST_MODIFIED));
    child.setText(Long.toString(lastModified.getTime()));
    child.serialize(xmlWriter);

    // set UUID
    String uuid = resource.getUUID();
    child = factory.createOMElement(new QName(DumpConstants.UUID));
    child.setText(uuid);
    child.serialize(xmlWriter);

    // set Description
    String description = resource.getDescription();
    child = factory.createOMElement(new QName(DumpConstants.DESCRIPTION));
    child.setText(description);
    child.serialize(xmlWriter);

    // adding contents..
    if (!(resource instanceof CollectionImpl)) {
        resourceDAO.fillResourceContent(resource);

        byte[] content = (byte[]) resource.getContent();
        if (content != null) {
            child = factory.createOMElement(new QName(DumpConstants.CONTENT));
            child.setText(Base64.encode(content));
            child.serialize(xmlWriter);
        }
    }

    // getting children and applying dump recursively
    if (resource instanceof CollectionImpl) {
        CollectionImpl collection = (CollectionImpl) resource;
        resourceDAO.fillChildren(collection, 0, -1);
        String childPaths[] = collection.getChildren();

        xmlWriter.writeStartElement(DumpConstants.CHILDREN);
        OMText emptyText = factory.createOMText("");
        emptyText.serialize(xmlWriter);
        xmlWriter.flush();
        for (String childPath : childPaths) {
            // we would be writing the start element of the child and its name here.
            try {
                String resourceName = RegistryUtils.getResourceName(childPath);
                writer.write("<resource name=\"" + resourceName + "\"");
                writer.flush();
            } catch (IOException e) {
                String msg = "Error in writing the start element for the path: " + childPath + ".";
                log.error(msg, e);
                throw new RegistryException(msg, e);
            }
            if (!path.equals(childPath)) {
                recursionRepository.dumpRecursivelyLite(childPath, new DumpWriter(writer));
            }

        }
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();
    xmlWriter.flush();
}

From source file:org.wso2.carbon.registry.lifecycle.test.server.mgt.RegistryConfiguratorTestCase.java

private void changeServiceCreationElement() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {/*from  w w  w. java2s.  c  om*/
        AXIOMXPath xpathExpression = new AXIOMXPath("/wso2registry/handler/property");
        List<OMElement> nodes = xpathExpression.selectNodes(documentElement);
        for (OMElement node : nodes) {
            if (node.getAttributeValue(new QName("name")).equals("createSOAPService")) {
                node.setText("false");
            }
        }
        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        documentElement.serialize(writer);
        documentElement.build();
        Thread.sleep(2000);

    } catch (Exception e) {
        log.error("Failed to modify registry.xml " + e.getMessage());
        throw new Exception("Failed to modify registry.xml " + e.getMessage());
    } finally {
        assert fileOutputStream != null;
        fileOutputStream.close();
        assert writer != null;
        writer.flush();
    }

}

From source file:org.wso2.carbon.registry.lifecycle.test.server.mgt.RegistryConfiguratorTestCase.java

private void increaseSearchIndexStartTimeDelay() throws Exception {

    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {/*  w w  w.  ja  v  a  2s.c om*/
        AXIOMXPath xpathExpression = new AXIOMXPath(
                "/wso2registry/indexingConfiguration/startingDelayInSeconds");
        OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement);
        indexConfigNode.setText("30");
        AXIOMXPath xpathExpression1 = new AXIOMXPath(
                "/wso2registry/indexingConfiguration/indexingFrequencyInSeconds");
        OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement);
        indexConfigNode1.setText("3");
        AXIOMXPath xpathExpression2 = new AXIOMXPath("/wso2registry/indexingConfiguration/batchSize");
        OMElement indexConfigNode2 = (OMElement) xpathExpression2.selectSingleNode(documentElement);
        indexConfigNode2.setText("70");
        AXIOMXPath xpathExpression3 = new AXIOMXPath("/wso2registry/indexingConfiguration/indexerPoolSize");
        OMElement indexConfigNode3 = (OMElement) xpathExpression3.selectSingleNode(documentElement);
        indexConfigNode3.setText("50");
        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        documentElement.serialize(writer);
        documentElement.build();
        Thread.sleep(2000);

    } catch (Exception e) {
        log.error("registry.xml edit fails" + e.getMessage());
        throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
        assert fileOutputStream != null;
        fileOutputStream.close();
        assert writer != null;
        writer.flush();
    }
}

From source file:org.wso2.carbon.registry.lifecycle.test.server.mgt.RegistryConfiguratorTestCase.java

private void enableJmxManagement() throws Exception {

    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {//from  w w  w.  j  ava  2s . c  o  m
        AXIOMXPath xpathExpression = new AXIOMXPath("/wso2registry/jmx");
        OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement);
        OMAttribute omAttribute = indexConfigNode.getAttribute(new QName("enabled"));
        omAttribute.setAttributeValue("true");
        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        documentElement.serialize(writer);
        documentElement.build();
        Thread.sleep(2000);

    } catch (Exception e) {
        log.error("registry.xml edit fails" + e.getMessage());
        throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
        if (fileOutputStream != null) {
            fileOutputStream.close();
        }
        if (writer != null) {
            writer.flush();
        }
    }
}

From source file:org.wso2.carbon.registry.lifecycle.test.server.mgt.RegistryConfiguratorTestCase.java

private void enableWorkList() throws Exception {

    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    String workList;//from ww w .j  av a2s . co  m
    workList = "<workList serverURL=\"local://services/\" remote=\"false\">\n" + "        <username>"
            + automationContext.getContextTenant().getContextUser().getUserName() + "</username>\n"
            + "        <password>" + automationContext.getContextTenant().getContextUser().getPassword()
            + "</password>\n" + "    </workList>";

    try {
        OMElement registryXML = getRegistryXmlOmElement();
        registryXML.addChild(AXIOMUtil.stringToOM(workList));
        registryXML.build();
        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        registryXML.serialize(writer);

    } catch (Exception e) {
        throw new Exception("registry.xml update fails");
    } finally {
        if (fileOutputStream != null) {
            fileOutputStream.close();
        }
        if (writer != null) {
            writer.flush();
        }
    }

}

From source file:org.wso2.carbon.registry.lifecycle.test.server.mgt.RegistryConfiguratorTestCase.java

private void increaseConnectionTimeoutValue() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getAxis2XmlOmElement();
    try {/*from  ww  w  .  ja v a 2 s.  c o  m*/
        AXIOMXPath xpathExpression = new AXIOMXPath("/axisconfig/transportSender/parameter");
        List<OMElement> nodes = xpathExpression.selectNodes(documentElement);
        for (OMElement node : nodes) {
            if (node.getAttributeValue(new QName("name")).equals("SO_TIMEOUT")) {
                node.setText("240000");
            }
            if (node.getAttributeValue(new QName("name")).equals("CONNECTION_TIMEOUT")) {
                node.setText("240000");
            }
        }
        fileOutputStream = new FileOutputStream(getAxis2XMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        documentElement.serialize(writer);
        documentElement.build();
        Thread.sleep(2000);

    } catch (Exception e) {
        log.error("axis2_client.xml edit fails" + e.getMessage());
        throw new Exception("axis2_client.xml edit fails" + e.getMessage());
    } finally {
        assert fileOutputStream != null;
        fileOutputStream.close();
        assert writer != null;
        writer.flush();
    }
}

From source file:org.wso2.carbon.registry.scm.test.SvnTestCase.java

private void addScmConfiguration() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    try {/*from   w w  w. j a v a2  s  .c om*/
        OMElement regConfig = getRegistryXmlOmElement();
        File checkOutDir = new File(getTempLocation());

        String scmConfig = "<scm>"
                + "        <connection checkOutURL=\"scm:svn:https://svn.wso2.org/repos/wso2/carbon/"
                + "platform/trunk/platform-integration/platform-automated-test-suite/"
                + "org.wso2.carbon.automation.test.repo/src/main/resources/artifacts/GREG/"
                + "policy\" workingDir=\"" + getTempLocation() + "\" mountPoint=\"/_system/"
                + "governance/policy\" checkInURL=\"\" readOnly=\"\" updateFrequency=\"1\">"
                + "                <username>anonymoususer</username>"
                + "                <password>anonymoususer123</password>" + "        </connection>"
                + "    </scm>";

        OMElement scmConfigOMElement = AXIOMUtil.stringToOM(scmConfig);
        scmConfigOMElement.build();
        regConfig.addChild(scmConfigOMElement);
        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        regConfig.serialize(writer);
        regConfig.build();
        isSCMConfigAdded = true;
        if (!checkOutDir.exists()) {
            checkOutDir.mkdir();
        }
        Thread.sleep(2000);
    } catch (Exception e) {
        log.error("registry.xml edit fails" + e.getMessage());
        throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
        assert fileOutputStream != null;
        assert writer != null;
        writer.flush();
        writer.close();
        fileOutputStream.close();
    }
}

From source file:org.wso2.carbon.registry.scm.test.SvnTestCase.java

private void removeScmConfiguration() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    try {/*ww w  .j  a  v  a2 s  .com*/
        OMElement regConfig = RegistryConfiguratorTestCase.getRegistryXmlOmElement();
        regConfig.getFirstChildWithName(new QName("scm")).discard();
        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        regConfig.serialize(writer);
        regConfig.build();
        Thread.sleep(2000);
    } catch (Exception e) {
        log.error("registry.xml edit fails" + e.getMessage());
        throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
        assert fileOutputStream != null;
        assert writer != null;
        writer.flush();
        writer.close();
        fileOutputStream.close();
    }
}

From source file:org.wso2.carbon.registry.server.mgt.RegistryConfiguratorTestCase.java

private void increaseSearchIndexStartTimeDelay() throws Exception {

    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {//  ww w. ja  va  2s  . c o  m
        AXIOMXPath xpathExpression = new AXIOMXPath(
                "/wso2registry/indexingConfiguration/startingDelayInSeconds");
        OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement);
        indexConfigNode.setText("30");
        AXIOMXPath xpathExpression1 = new AXIOMXPath(
                "/wso2registry/indexingConfiguration/indexingFrequencyInSeconds");
        OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement);
        indexConfigNode1.setText("3");
        AXIOMXPath xpathExpression2 = new AXIOMXPath("/wso2registry/indexingConfiguration/batchSize");
        OMElement indexConfigNode2 = (OMElement) xpathExpression2.selectSingleNode(documentElement);
        indexConfigNode2.setText("70");
        AXIOMXPath xpathExpression3 = new AXIOMXPath("/wso2registry/indexingConfiguration/indexerPoolSize");
        OMElement indexConfigNode3 = (OMElement) xpathExpression3.selectSingleNode(documentElement);
        indexConfigNode3.setText("50");

        fileOutputStream = new FileOutputStream(getRegistryXMLPath());
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
        documentElement.serialize(writer);
        documentElement.build();
        Thread.sleep(2000);

    } catch (Exception e) {
        log.error("registry.xml edit fails" + e.getMessage());
        throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
        assert fileOutputStream != null;
        fileOutputStream.close();
        assert writer != null;
        writer.flush();
    }
}