Example usage for java.io StringWriter close

List of usage examples for java.io StringWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closing a StringWriter has no effect.

Usage

From source file:com.eyeq.pivot4j.state.StateSavingIT.java

@Test
public void testSaveModelSettings() throws ConfigurationException, IOException {
    PivotModel model = getPivotModel();//from w  w w.j  ava 2s  . co  m
    model.setMdx(getTestQuery());
    model.initialize();

    model.setSorting(true);
    model.setTopBottomCount(3);
    model.setSortCriteria(SortCriteria.BOTTOMCOUNT);

    CellSet cellSet = model.getCellSet();
    CellSetAxis axis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal());

    model.sort(axis, axis.getPositions().get(0));

    String mdx = model.getCurrentMdx();

    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setDelimiterParsingDisabled(true);

    model.saveSettings(configuration);

    Logger logger = LoggerFactory.getLogger(getClass());
    if (logger.isDebugEnabled()) {
        StringWriter writer = new StringWriter();
        configuration.save(writer);
        writer.flush();
        writer.close();

        logger.debug("Loading report content :" + System.getProperty("line.separator"));
        logger.debug(writer.getBuffer().toString());
    }

    PivotModel newModel = new PivotModelImpl(getDataSource());
    newModel.restoreSettings(configuration);

    newModel.getCellSet();

    String newMdx = newModel.getCurrentMdx();
    if (newMdx != null) {
        // Currently the parser treats every number as double value.
        // It's inevitable now and does not impact the result.
        newMdx = newMdx.replaceAll("3\\.0", "3");
    }

    assertThat("MDX has been changed after the state restoration", newMdx, is(equalTo(mdx)));
    assertThat("Property 'sorting' has been changed after the state restoration", newModel.isSorting(),
            is(true));
    assertThat("Property 'topBottomCount' has been changed after the state restoration",
            newModel.getTopBottomCount(), is(equalTo(3)));
    assertThat("Property 'sortMode' has been changed after the state restoration", newModel.getSortCriteria(),
            is(equalTo(SortCriteria.BOTTOMCOUNT)));
}

From source file:TDS.Proctor.Web.presentation.taglib.GlobalJavascriptWriter.java

public void writeGlobalAccs() throws IOException {

    AccsDTO accsDTO = _presenter.getGlobalAccs();
    _writer.write("gTDS.globalAccs = ");
    StringWriter sw = new StringWriter();
    ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
    mapper.writeValue(sw, accsDTO);//from www . j a va2 s  .c o m
    sw.close();
    _writer.write(sw.toString());
    _writer.write(";");
    _writer.write("\r\n");
}

From source file:com.okta.sdk.framework.JsonApiClient.java

@Override
protected HttpEntity buildRequestEntity(Object object) throws IOException {
    if (object == "") {
        return new StringEntity("", "UTF-8");
    }/*from w w w.  j  a va 2  s .co  m*/
    StringWriter writer = new StringWriter();
    JsonGenerator generator = objectMapper.getFactory().createGenerator(writer);
    objectMapper.writeValue(generator, object);
    generator.close();
    writer.close();
    String string = writer.toString();
    return new StringEntity(string, "UTF-8");
}

From source file:ome.dsl.utests.ExampleUsageTest.java

@Test
public void testWithWriting() throws Exception {
    sr.parse();//www. j  av a  2  s . co  m
    List list = sr.process();
    for (Iterator it = list.iterator(); it.hasNext();) {
        SemanticType st = (SemanticType) it.next();
        VelocityHelper vh = new VelocityHelper();
        vh.put("type", st);
        // FileWriter fw = new
        // FileWriter("/tmp/"+st.getId().replaceAll("[.]","_")+".hbm.xml");
        StringWriter sw = new StringWriter();
        vh.invoke(DSLTask.getStream("ome/dsl/object.vm"), sw);
        sw.flush();
        sw.close();
        // fw.flush();
        // fw.close();
    }

}

From source file:org.trpr.platform.integration.impl.xml.XMLTranscoderImpl.java

/**
 * Interface method implementation. Note that the specified Object should be an XML schema derived type. 
 * @see XMLTranscoder#marshal(java.lang.Object)
 *///from   ww w  . j  a v a 2 s . c  o m
@SuppressWarnings("unchecked")
public String marshal(Object object) throws XMLDataException {
    StringWriter stringWriter = new StringWriter();
    this.marshalToResult(object, new StreamResult(stringWriter));
    try {
        stringWriter.close();
    } catch (IOException e) {
        // ignore
    }
    return stringWriter.toString();
}

From source file:ome.dsl.utests.ExampleUsageTest.java

/** disabling; need proper logic to find common/ component FIXME */
public void DISABLEDtestReal() throws Exception {
    File currentDir = new File(System.getProperty("user.dir"));// TODO Util
    File mappings = new File(currentDir.getParent() + File.separator + "common" + File.separator + "resources"
            + File.separator + "Mappings.ome.xml"); // FIXME circular deps.
    log.error(mappings);// w  w  w  .  j a v a2 s  .  c  o  m
    SaxReader nsr = new SaxReader("psql", mappings);
    nsr.parse();
    for (Iterator it = nsr.process().iterator(); it.hasNext();) {
        SemanticType st = (SemanticType) it.next();
        VelocityHelper vh = new VelocityHelper();
        vh.put("type", st);
        // FileWriter fw = new
        // FileWriter("/tmp/"+st.getId().replaceAll("[.]","_")+".hbm.xml");
        StringWriter sw = new StringWriter();
        vh.invoke(DSLTask.getStream("ome/dsl/mapping.vm"), sw);
        sw.flush();
        sw.close();
        // fw.flush();
        // fw.close();
    }
}

From source file:org.openengsb.connector.promreport.internal.ProcessFileStore.java

private String marshal(ProcessInstance pi) throws JAXBException, IOException {
    Marshaller m = createMarshaller();
    StringWriter sw = new StringWriter();
    m.marshal(pi, sw);/*from w ww .java  2 s .c o m*/
    sw.close();
    return "    " + sw.toString().replace("\n", "\n        ");
}

From source file:org.dataconservancy.dcs.integration.dryvalleys.DryValleysFeatureExtractionIT.java

public void buildSip() throws IOException {
    final InputStream collectionMDStream = DryValleysFeatureExtractionIT.class
            .getResourceAsStream(COLLECTION_METADATA_RESOURCE);

    DcsMetadata collectionMD = new DcsMetadata();

    StringWriter out = new StringWriter();
    IOUtils.copy(collectionMDStream, out);
    out.close();

    collectionMD.setMetadata(out.toString());

    DcsCollection collection = new DcsCollection();
    collection.setTitle("McMurdoDryValleys");
    collection.setId("http://dataconservancy.org/collections/DryValleysCollection");
    collection.addMetadata(collectionMD);

    final InputStream fieldPhotoMDStream = DryValleysFeatureExtractionIT.class
            .getResourceAsStream(FIELD_PHOTO_METADATA_RESOURCE);

    DcsMetadata fieldPhotoMD = new DcsMetadata();

    StringWriter fieldPhotoMDWriter = new StringWriter();
    IOUtils.copy(fieldPhotoMDStream, fieldPhotoMDWriter);
    fieldPhotoMDWriter.close();/*from   ww  w .j  a  va  2s .co m*/

    fieldPhotoMD.setMetadata(fieldPhotoMDWriter.toString());

    DcsDeliverableUnit fieldPhotoDU = new DcsDeliverableUnit();
    fieldPhotoDU.addMetadata(fieldPhotoMD);
    fieldPhotoDU.addCollection(new DcsCollectionRef(collection.getId()));

    final InputStream rockSampleMDStream = DryValleysFeatureExtractionIT.class
            .getResourceAsStream(ROCK_SAMPLE_METADATA_RESOURCE);
    DcsMetadata rockSampleMD = new DcsMetadata();

    StringWriter rockSampleMDWriter = new StringWriter();
    IOUtils.copy(rockSampleMDStream, rockSampleMDWriter);
    rockSampleMDWriter.close();

    rockSampleMD.setMetadata(rockSampleMDWriter.toString());

    DcsDeliverableUnit rockSampleDU = new DcsDeliverableUnit();
    rockSampleDU.addMetadata(rockSampleMD);
    rockSampleDU.addCollection(new DcsCollectionRef(collection.getId()));

    sip = new Dcp();
    sip.addCollection(collection);
    sip.addDeliverableUnit(fieldPhotoDU, rockSampleDU);
}

From source file:org.jboss.dashboard.ui.panel.export.ExportDriver.java

public CommandResponse actionDownloadExport(final Panel panel, CommandRequest request) throws Exception {
    final boolean useBlanks = BooleanParameter.value(panel.getParameterValue(PARAM_USE_BLANKS), false);
    final ExportResult exportResult = getSessionInfo().getExportResult();

    super.fireAfterRenderPanel(panel, request.getRequestObject(), null);

    StringWriter writer = new StringWriter();
    exportResult.writeXMLversion(writer, useBlanks);
    writer.close();
    return new SendStreamResponse(new ByteArrayInputStream(writer.toString().getBytes("UTF-8")),
            new StringBuilder("inline;filename=").append(EXPORT_FILE_NAME).toString());
}

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat,
        boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {//from   w  w  w .  ja  v  a2 s.co m
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }

        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}