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);
}
}
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());
}
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);
}
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);
}
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);
}
}
Aggregations