Example usage for org.apache.commons.io IOUtils toByteArray

List of usage examples for org.apache.commons.io IOUtils toByteArray

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils toByteArray.

Prototype

public static byte[] toByteArray(String input) throws IOException 

Source Link

Document

Get the contents of a String as a byte[] using the default character encoding of the platform.

Usage

From source file:net.rptools.lib.FileUtil.java

public static byte[] loadResource(String resource) throws IOException {
    InputStream is = null;/*from   w  ww  .j  a va  2s  .co m*/
    try {
        is = FileUtil.class.getClassLoader().getResourceAsStream(resource);
        if (is == null) {
            throw new IOException("Resource \"" + resource + "\" cannot be opened as stream.");
        }
        return IOUtils.toByteArray(new InputStreamReader(is, "UTF-8"));
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:info.magnolia.ui.mediaeditor.action.InstantMediaEditorAction.java

@Override
public void execute() throws ActionExecutionException {
    dataSource.startAction(StringUtils.lowerCase(getDefinition().getLabel()));
    InputStream result = new ByteArrayInputStream(dataSource.getValue());
    try {//from w ww.  j av a  2  s  .  co  m
        result = performModification(result);
        dataSource.setValue(IOUtils.toByteArray(result));
        eventBus.fireEvent(new MediaEditorInternalEvent(MediaEditorInternalEvent.EventType.APPLY));
    } catch (IOException e) {
        log.error("Failed to perform instant operation on media.", e);
        IOUtils.closeQuietly(result);
    }
}

From source file:ezbake.deployer.publishers.artifact.ArtifactDataEntryResourceCreator.java

/**
 * Create an ArtifactDataEntry using the specified resource
 * @param artifactPath name path of the artifact archive entry
 * @param resourcePath path to the resource used in creating the artifact data
 * @return created artifact data entry/*from w  ww  .j av  a2s.  co  m*/
 * @throws IOException
 */
public ArtifactDataEntry createFromClassPathResource(String artifactPath, String resourcePath)
        throws IOException {
    return new ArtifactDataEntry(createTarArchiveEntry(artifactPath),
            IOUtils.toByteArray(JavaWebAppArtifactContentsPublisher.class
                    .getResourceAsStream(Files.get("/", resourcePath).toString())));
}