Example usage for org.springframework.core.io WritableResource getOutputStream

List of usage examples for org.springframework.core.io WritableResource getOutputStream

Introduction

In this page you can find the example usage for org.springframework.core.io WritableResource getOutputStream.

Prototype

OutputStream getOutputStream() throws IOException;

Source Link

Document

Return an OutputStream for the underlying resource, allowing to (over-)write its content.

Usage

From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java

private void xStreamSave(Object object, WritableResource resource) {
    try (OutputStream outStream = resource.getOutputStream()) {
        xStream.toXML(object, outStream);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }/*  w w w. j a  v  a 2s .  c  o  m*/
}

From source file:org.mitre.mpf.wfm.util.PropertiesUtil.java

private static void copyResource(WritableResource target, InputStreamSource source) throws IOException {
    createParentDir(target);/*from   w  w w  .  j a v  a 2 s  .c  om*/
    try (InputStream inStream = source.getInputStream(); OutputStream outStream = target.getOutputStream()) {
        IOUtils.copy(inStream, outStream);
    }
}

From source file:org.opennms.core.config.impl.JaxbResourceConfiguration.java

public void save(final T config) throws ConfigurationResourceException {
    final Resource r = getResource();
    if (!(r instanceof WritableResource)) {
        throw new ConfigurationResourceException("Resource " + r + " is not writable!");
    }/*www .  jav a  2  s .  co  m*/
    final WritableResource resource = (WritableResource) r;
    OutputStream os = null;
    OutputStreamWriter osw = null;
    try {
        os = resource.getOutputStream();
        osw = new OutputStreamWriter(os);
        JaxbUtils.marshal(config, osw);
    } catch (final IOException e) {
        throw new ConfigurationResourceException("Failed to write to " + r, e);
    } catch (final Exception e) {
        throw new ConfigurationResourceException(
                "Failed to marshal configuration " + getClassType() + " to resource " + r, e);
    } finally {
        IOUtils.closeQuietly(osw);
        IOUtils.closeQuietly(os);
    }
}