Search in sources :

Example 1 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project OpenGrok by OpenGrok.

the class RuntimeEnvironmentTest method testLoadInvalidStatistics.

@Test(expected = ParseException.class)
public void testLoadInvalidStatistics() throws ParseException, IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String json = "{ malformed json with missing bracket";
    try (InputStream in = new StringInputStream(json)) {
        env.loadStatistics(in);
    }
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project OpenGrok by OpenGrok.

the class RuntimeEnvironmentTest method testLoadEmptyStatistics.

@Test
public void testLoadEmptyStatistics() throws IOException, ParseException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String json = "{}";
    try (InputStream in = new StringInputStream(json)) {
        env.loadStatistics(in);
    }
    Assert.assertEquals(new Statistics().toJson(), env.getStatistics().toJson());
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) InputStream(java.io.InputStream) Statistics(org.opensolaris.opengrok.web.Statistics) Test(org.junit.Test)

Example 3 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project jbosstools-hibernate by jbosstools.

the class CoreMappingTestHelper method createCfgXMLFile.

private void createCfgXMLFile(String packageName) throws Exception {
    IPath cfgFilePath = new Path(TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
    IFile cfgFile = testProject.getIProject().getFile(cfgFilePath);
    String cfgXmlString = CfgXmlFileHelper.constructCfgXmlString(packageName, testProject.getIProject());
    cfgFile.create(new StringInputStream(cfgXmlString), true, null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) StringInputStream(org.apache.tools.ant.filters.StringInputStream) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath)

Example 4 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project jbosstools-hibernate by jbosstools.

the class MappingTestHelper method createCfgXMLFile.

private void createCfgXMLFile() throws Exception {
    IPath cfgFilePath = new Path(TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
    IFile cfgFile = testProject.getIProject().getFile(cfgFilePath);
    cfgFile.create(new StringInputStream(cfgXml), true, null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) StringInputStream(org.apache.tools.ant.filters.StringInputStream) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath)

Example 5 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project Gemma by PavlidisLab.

the class DatasetCombiner method findGDSforGSE.

/**
 * @param seriesAccession series accession
 * @return GDSs that correspond to the given series. It will be empty if there is no GDS matching.
 */
public static Collection<String> findGDSforGSE(String seriesAccession) {
    Collection<String> associatedDatasetAccessions = new HashSet<>();
    try {
        String details = EutilFetch.fetch("gds", seriesAccession, 100);
        if (details.equalsIgnoreCase("no results")) {
            return associatedDatasetAccessions;
        }
        XPathFactory xf = XPathFactory.newInstance();
        XPath xpath = xf.newXPath();
        /*
             * Get all Items of type GDS that are from a DocSum with an Item entryType of GDS.
             */
        XPathExpression xgds = xpath.compile("/eSummaryResult/DocSum[Item/@Name=\"entryType\" and (Item=\"GDS\")]/Item[@Name=\"GDS\"][1]/text()");
        DocumentBuilder builder = DatasetCombiner.factory.newDocumentBuilder();
        /*
             * Bug 2690. There must be a better way.
             */
        details = details.replaceAll("encoding=\"UTF-8\"", "");
        try (StringInputStream sis = new StringInputStream(StringUtils.trim(details))) {
            Document document = builder.parse(sis);
            NodeList result = (NodeList) xgds.evaluate(document, XPathConstants.NODESET);
            for (int i = 0; i < result.getLength(); i++) {
                String nodeValue = result.item(i).getNodeValue();
                // if ( nodeValue.contains( ";" ) ) continue; //
                associatedDatasetAccessions.add("GDS" + nodeValue);
            }
            return associatedDatasetAccessions;
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not parse XML data from remote server", e);
    } catch (ParserConfigurationException | SAXException | XPathExpressionException e) {
        throw new RuntimeException("XML parsing error of remote data", e);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) StringInputStream(org.apache.tools.ant.filters.StringInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

StringInputStream (org.apache.tools.ant.filters.StringInputStream)17 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 IFile (org.eclipse.core.resources.IFile)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)2 DiagramImpl (org.kie.workbench.common.stunner.core.diagram.DiagramImpl)2 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Statistics (org.opensolaris.opengrok.web.Statistics)2 Document (org.w3c.dom.Document)2 SAXException (org.xml.sax.SAXException)2