Example usage for java.io StringReader close

List of usage examples for java.io StringReader close

Introduction

In this page you can find the example usage for java.io StringReader close.

Prototype

public void close() 

Source Link

Document

Closes the stream and releases any system resources associated with it.

Usage

From source file:org.kalypso.ogc.sensor.view.actions.ViewWQRelationHandler.java

/**
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */// w w  w. j  a  v a 2s  .  c  o m
@Override
public Object execute(final ExecutionEvent event) {
    final IEvaluationContext context = (IEvaluationContext) event.getApplicationContext();
    final Shell shell = (Shell) context.getVariable(ISources.ACTIVE_SHELL_NAME);
    final IWorkbenchPart part = (IWorkbenchPart) context.getVariable(ISources.ACTIVE_PART_NAME);
    final ObservationChooser chooser = (ObservationChooser) part.getAdapter(ObservationChooser.class);

    final IObservation obs = chooser.isObservationSelected(chooser.getSelection());
    if (obs == null)
        return Status.OK_STATUS;

    final String propTable = obs.getMetadataList().getProperty(ITimeseriesConstants.MD_WQ_TABLE);
    if (propTable == null)
        return Status.OK_STATUS;

    final StringReader reader = new StringReader(propTable);
    try {
        final WQTableSet set = WQTableFactory.parse(new InputSource(reader));
        reader.close();

        final WQRelationDialog dlg = new WQRelationDialog(shell,
                Messages.getString("org.kalypso.ogc.sensor.view.actions.ViewWQRelationHandler.0") //$NON-NLS-1$
                        + obs.getName(),
                set);
        dlg.open();
    } catch (final WQException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(reader);
    }

    return Status.OK_STATUS;
}

From source file:com.siemens.scr.avt.ad.io.AnnotationBatchLoader.java

protected List<String> getSegmentAttachmentIds(File aimFile) throws IOException, JDOMException {
    List<String> segmentAttachmentIds = new ArrayList<String>();
    FileInputStream fin = new FileInputStream(aimFile);
    String aimXML = ResourceLocator.getStringFromStream(fin);

    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);//  w w w  .j  ava2  s  .  c  o m
    builder.setIgnoringElementContentWhitespace(true);
    StringReader reader = new StringReader(aimXML);
    Document doc;
    try {
        doc = builder.build(reader);
    } finally {
        reader.close();
    }
    Element root = doc.getRootElement();
    Element probabilityMapCollection = root.getChild("probabilityMapCollection",
            Namespace.getNamespace("gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM"));
    if (probabilityMapCollection != null) {
        List<Element> ProbabilityMaps = new ArrayList<Element>();
        List<Element> tempProbabilityMaps = probabilityMapCollection.getChildren("ProbabilityMap",
                Namespace.getNamespace("gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM"));
        ProbabilityMaps.addAll(tempProbabilityMaps);
        for (Element element : ProbabilityMaps) {
            String refInstanceUID = element.getAttributeValue("referencedInstanceUID");
            segmentAttachmentIds.add(refInstanceUID);
        }
    }
    fin.close();
    return segmentAttachmentIds;

}

From source file:org.kalypso.ogc.gml.typehandler.ZmlInlineTypeHandler.java

/**
 * @see org.kalypsodeegree.model.typeHandler.XsdBaseTypeHandler#convertToJavaValue(java.lang.String)
 *//*from  w  w  w .  ja  va 2s . com*/
@Override
public IObservation convertToJavaValue(final String zmlStr) {
    if (zmlStr == null || zmlStr.isEmpty())
        return null;

    final StringReader reader = new StringReader(zmlStr.trim());
    try {
        final IObservation obs = ZmlFactory.parseXML(new InputSource(reader), null); //$NON-NLS-1$
        reader.close();
        return obs;
    } catch (final SensorException e) {
        e.printStackTrace();
        return null;
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.openossad.util.core.xml.XMLHandler.java

/**
 * Load a String into an XML document//from  w w  w  . j  a  v a  2 s  .  c o  m
 * @param string The XML text to load into a document
 * @return the Document if all went well, null if an error occurred!
 */
public static final Document loadXMLString(String string) throws OpenDESIGNERXMLException {
    DocumentBuilderFactory dbf;
    DocumentBuilder db;
    Document doc;

    try {
        // Check and open XML document
        dbf = DocumentBuilderFactory.newInstance();
        db = dbf.newDocumentBuilder();
        StringReader stringReader = new java.io.StringReader(string);
        InputSource inputSource = new InputSource(stringReader);
        try {
            doc = db.parse(inputSource);
        } catch (IOException ef) {
            throw new OpenDESIGNERXMLException("Error parsing XML", ef);
        } finally {
            stringReader.close();
        }

        return doc;
    } catch (Exception e) {
        throw new OpenDESIGNERXMLException("Error reading information from XML string : " + Const.CR + string,
                e);
    }
}

From source file:com.commercehub.bamboo.plugins.grailswrapper.GrailsWrapperTask.java

private Properties loadEnvironmentProperties(@NotNull TaskContext taskContext) {
    Properties environmentProps = new Properties();
    String environmentVars = taskContext.getConfigurationMap()
            .get(GrailsWrapperTaskConfigurator.ENVIRONMENT_VARIABLES);
    if (environmentVars != null) {
        StringReader reader = new StringReader(environmentVars);
        try {/*from  w ww  .ja va  2 s  . c o  m*/
            environmentProps.load(reader);
        } catch (IOException ex) {
            // Ignore
        } finally {
            reader.close();
        }
    }
    return environmentProps;
}

From source file:com.hypirion.io.PipeTest.java

/**
 * Test that reading from multiple readers doesn't change or stop the
 * writer.//from   w  ww .  j  a  va  2 s.  c o  m
 */
@Test(timeout = 1000)
public void testReaderConcatenation() throws Exception {
    String input = "";
    StringWriter wrt = new StringWriter();
    for (int i = 0; i < 10; i++) {
        String thisInput = RandomStringUtils.random(3708);
        input += thisInput;
        StringReader rdr = new StringReader(thisInput);
        Pipe p = new Pipe(rdr, wrt);
        p.start();
        p.join();
        rdr.close();
    }
    String output = wrt.toString();
    wrt.close();
    assertEquals(input, output);
}

From source file:fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.service.POMExportServiceTest.java

@Test
@SuppressWarnings("unchecked")
public void testExport() throws IOException, URISyntaxException, SAXException {

    //TEST DATA/*w w  w  .  j  a v a 2 s .  c  o m*/
    StringWriter writer = new StringWriter();
    String org = "fr.synchrotron.soleil.ica.ci.lib";
    String name = "maven-versionresolver";
    String version = "1.0.0";
    String status = "RELEASE";
    File inputPomFile = new File(this.getClass().getResource("pom-1.xml").toURI());
    PomReaderService pomReaderService = new PomReaderService();
    FileReader inputPomFileReader = new FileReader(inputPomFile);
    Model inputPomFileModel = pomReaderService.getModel(inputPomFileReader);
    inputPomFileReader.close();

    pomImportService.importPomFile(inputPomFile);
    pomExportService.exportPomFile(writer, new ArtifactDocumentKey(org, name, version, status));

    final String outputPomContent = writer.toString();
    //  System.out.println(outputPomContent);
    assertNotNull(outputPomContent);
    final StringReader outputPomContentStringReader = new StringReader(outputPomContent);
    Model outputPomFileModel = pomReaderService.getModel(outputPomContentStringReader);
    outputPomContentStringReader.close();
    assertEquals(inputPomFileModel.getDescription(), outputPomFileModel.getDescription());
    //                      getModelVersion vraiment utile?
    //assertEquals(inputPomFileModel.getModelVersion(), outputPomFileModel.getModelVersion());
    assertEquals(inputPomFileModel.getGroupId(), outputPomFileModel.getGroupId());
    assertEquals(inputPomFileModel.getArtifactId(), outputPomFileModel.getArtifactId());
    assertEquals(inputPomFileModel.getVersion() + "." + status, outputPomFileModel.getVersion());
    assertEquals(inputPomFileModel.getPackaging(), outputPomFileModel.getPackaging());
    assertEquals(inputPomFileModel.getInceptionYear(), outputPomFileModel.getInceptionYear());
    assertTrue(EqualsBuilder.reflectionEquals(inputPomFileModel.getOrganization(),
            outputPomFileModel.getOrganization()));
    //TODO           assertEquals(inputPomFileModel.getParent(), outputPomFileModel.getParent());
    //TODO project classifier  ?
    List<License> licenses = inputPomFileModel.getLicenses();
    List<License> licensesOut = outputPomFileModel.getLicenses();
    assertEquals(licenses.size(), licensesOut.size());
    for (int i = 0; i < licenses.size(); i++) {
        License licenseIn = licenses.get(i);
        License licenseOut = licensesOut.get(i);
        assertTrue(EqualsBuilder.reflectionEquals(licenseIn, licenseOut));
        //            assertEquals(licenseIn.getName(), licenseOut.getName());
        //            assertEquals(licenseIn.getUrl(), licenseOut.getUrl());
        //            assertEquals(licenseIn.getComments(), licenseOut.getComments());
        //            assertEquals(licenseIn.getDistribution(), licenseOut.getDistribution());

    }

    // SCM - "scm:git:" removed by pomimporter
    assertEquals(inputPomFileModel.getScm().getConnection(),
            "scm:git:" + outputPomFileModel.getScm().getConnection());
    // dependencies
    List<Dependency> inputDependencies = inputPomFileModel.getDependencies();
    List<Dependency> outputDependencies = outputPomFileModel.getDependencies();
    assertEquals(inputDependencies.size(), outputDependencies.size());
    for (int i = 0; i < inputDependencies.size(); i++) {
        Dependency inputDependency = inputDependencies.get(i);
        Dependency outputDependency = outputDependencies.get(i);
        //      System.out.println("in: "+ToStringBuilder.reflectionToString(inputDependency));
        //    System.out.println("out: "+ToStringBuilder.reflectionToString(outputDependency));
        // exclude test version in not imported in mongodb
        assertTrue(EqualsBuilder.reflectionEquals(inputDependency, outputDependency,
                new String[] { "version", "exclusions" }));

        //     assertEquals(inputDependency.getGroupId(), outputDependency.getGroupId());
        //   assertEquals(inputDependency.getArtifactId(), outputDependency.getArtifactId());
        //  assertEquals(inputDependency.getScope(), outputDependency.getScope());
        //TODO? assertEquals(inputDependency.getSystemPath(), outputDependency.getSystemPath());
        //TODO? assertEquals(inputDependency.getType(), outputDependency.getType());
        //TODO? assertEquals(inputDependency.getClassifier(), outputDependency.getClassifier());
        // System.out.println(inputDependency.getExclusions());
        assertTrue(EqualsBuilder.reflectionEquals(inputDependency.getExclusions(),
                outputDependency.getExclusions()));
    }
    // developers info
    assertTrue(EqualsBuilder.reflectionEquals(inputPomFileModel.getDevelopers(),
            outputPomFileModel.getDevelopers()));
    //TODO contributors
    //   assertEquals(inputPomFileModel.getContributors(), outputPomFileModel.getContributors());

    assertEquals(inputPomFileModel.getModules(), outputPomFileModel.getModules());
    //TODO build?
    //TODO properties

    //TODO dependency management? transitive  exclusion can be done in dep man

}

From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java

public DataDisplayer parse(String xml, ImportResults results) throws Exception {
    DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
    dFactory.setIgnoringComments(true);//  www .j av a2s . co m
    StringReader isr = new StringReader(xml);
    Document doc = dBuilder.parse(new InputSource(isr));
    isr.close();
    return parse(doc.getChildNodes(), results);
}

From source file:org.geoserver.test.NamespacesWfsTest.java

private StoredQueryDescriptionType createTestStoredQueryDefinition(Map<String, String> parameters)
        throws Exception {
    Parser p = new Parser(new WFSConfiguration());
    p.setRootElementType(WFS.StoredQueryDescriptionType);

    String queryDefinition = substitutePlaceHolders(TEST_STORED_QUERY_DEFINITION, parameters);
    StringReader reader = new StringReader(queryDefinition);
    try {//from   w  w w . j av a 2s . com
        return (StoredQueryDescriptionType) p.parse(reader);
    } finally {
        reader.close();
    }
}

From source file:org.opendatakit.aggregate.parser.BaseFormParserForJavaRosa.java

private static synchronized final XFormParserWithBindEnhancements parseFormDefinition(String xml,
        BaseFormParserForJavaRosa parser) throws ODKIncompleteSubmissionData {

    StringReader isr = null;
    try {//from   w w  w.jav  a  2s .  co m
        isr = new StringReader(xml);
        Document doc = XFormParser.getXMLDocument(isr);
        return new XFormParserWithBindEnhancements(parser, doc);
    } catch (Exception e) {
        throw new ODKIncompleteSubmissionData(e, Reason.BAD_JR_PARSE);
    } finally {
        isr.close();
    }
}