Example usage for org.apache.commons.io.output WriterOutputStream close

List of usage examples for org.apache.commons.io.output WriterOutputStream close

Introduction

In this page you can find the example usage for org.apache.commons.io.output WriterOutputStream close.

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Close the stream.

Usage

From source file:ee.ria.xroad.common.util.PasswordStore.java

private static char[] byteToChar(byte[] bytes) throws IOException {
    if (bytes == null) {
        return null;
    }//  w  ww.  j a  v a2  s  .co  m

    CharArrayWriter writer = new CharArrayWriter(bytes.length);
    WriterOutputStream os = new WriterOutputStream(writer, UTF_8);
    os.write(bytes);
    os.close();

    return writer.toCharArray();
}

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

public static String writeToString(EObject instance, NonContainmentReferenceHandling refOption,
        HashMap<String, Object> saveOptions) throws IOException {
    StringWriter stringWriter = new StringWriter();
    WriterOutputStream os = new WriterOutputStream(stringWriter, Charset.forName("UTF-8"));
    writeToStream(instance, os, refOption, saveOptions);
    os.close();
    return stringWriter.toString().trim();
}

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

public static String writeToJsonString(EObject instance, NonContainmentReferenceHandling refOption,
        HashMap<String, Object> saveOptions) throws IOException {
    StringWriter stringWriter = new StringWriter();
    WriterOutputStream os = new WriterOutputStream(stringWriter, Charset.forName("UTF-8"));
    JsonResourceFactory factory = new JsonResourceFactory();
    Resource resource = factory.createResource(URI.createURI(""));
    write(instance, resource, os, refOption, saveOptions);
    os.close();
    return stringWriter.toString().trim();
}

From source file:com.quartercode.disconnected.test.profile.ProfileSerializerTest.java

@Test
public void testSerializeEquals() throws IOException, JAXBException {

    StringWriter serialized = new StringWriter();
    WriterOutputStream outputStream = new WriterOutputStream(serialized);
    ProfileSerializer.serialize(outputStream, simulation);
    outputStream.close();

    Simulation copy = ProfileSerializer//from w  ww .j  ava2 s. com
            .deserialize(new ReaderInputStream(new StringReader(serialized.toString())));
    Assert.assertEquals("Simulation equals serialized-deserialized copy", simulation, copy);
}

From source file:org.zanata.rest.service.TMXStreamingOutputTest.java

private Document writeToXmlWithValidation(StreamingOutput output) throws IOException, SAXException {
    StringBuilderWriter sbWriter = new StringBuilderWriter();
    WriterOutputStream writerOutputStream = new WriterOutputStream(sbWriter);
    output.write(writerOutputStream);//from  w  w w .  j  a  v  a 2s  . co  m
    writerOutputStream.close();
    String xml = sbWriter.toString();
    assertValidTMX(xml);
    DocumentBuilder controlParser = XMLUnit.newControlParser();
    controlParser.setEntityResolver(new TmxDtdResolver());
    Document doc = XMLUnit.buildDocument(controlParser, new StringReader(xml));
    return doc;
}

From source file:us.ihmc.rtps.visualizer.HexStringMessage.java

@Override
public String toString() {
    try {/*from  w  ww . j  a  va  2 s .  c  o m*/
        StringBuilderWriter writer = new StringBuilderWriter(data.length << 1 + 2);
        writer.write("Encapsulation: ");
        writer.write(endianness);
        writer.write(System.lineSeparator());
        WriterOutputStream os = new WriterOutputStream(writer);
        HexDump.dump(data, 0, os, 0);
        os.close();
        return writer.toString();
    } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException | IOException e) {
        return e.getMessage();
    }

}