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

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

Introduction

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

Prototype

public static void write(StringBuffer data, OutputStream output) throws IOException 

Source Link

Document

Writes chars from a StringBuffer to bytes on an OutputStream using the default character encoding of the platform.

Usage

From source file:ch.aonyx.broker.ib.api.io.OutputStreamRequestSender.java

@Override
public void send(final Request request) throws RequestException {
    try {/*from  w  ww .j ava2  s  . c o  m*/
        IOUtils.write(request.getBytes(), outputStream);
    } catch (final IOException e) {
        throw new PublisherException(ClientMessageCode.CANT_PUBLISH_REQUEST, e.getMessage(), request, e);
    }
}

From source file:com.helegris.szorengeteg.ui.MediaLoader.java

/**
 * Creates playable JavaFX audio from a byte array. To achieve this, it
 * creates and deletes a temporary file.
 *
 * @param audioBytes/*w w w.j  a  va  2s  .c om*/
 * @return audio
 * @throws IOException
 */
public Media loadAudio(byte[] audioBytes) throws IOException {
    File tempFile = File.createTempFile("audio", null);
    tempFile.deleteOnExit();
    IOUtils.write(audioBytes, new FileOutputStream(tempFile));
    Media media = new Media(tempFile.toURI().toString());
    return media;
}

From source file:br.com.ingenieux.lambada.example.ExampleApiGateway1.java

@LambadaFunction(timeout = 300)
@ApiGateway(path = "/sayhello/1")
public void sayHelloLowLevel(InputStream is, OutputStream os, Context ctx) throws Exception {
    String whom = OBJECT_MAPPER.readValue(is, String.class);

    IOUtils.write(String.format("Hello, %s!", whom), os);
}

From source file:net.egelke.chrome.eid.Main.java

private static void respond(Message msg) throws IOException {
    byte[] buffer = mapper.writeValueAsBytes(msg);

    bb.rewind();/*  w ww .  j  a  v a 2 s.co  m*/
    bb.putInt(buffer.length);
    IOUtils.write(bb.array(), System.out);
    IOUtils.write(buffer, System.out);
}

From source file:com.voa.weixin.work.DownloadFileWork.java

@Override
public void toDo() throws WorkException {
    try {//  w  w  w.  j  a  v a 2  s  .  co  m
        DownloadFileTask task = (DownloadFileTask) this.task;
        byte[] bs = IOUtils.toByteArray(task.getInputStream());

        FileOutputStream out = new FileOutputStream(new File("c:/tt.jpg"));
        IOUtils.write(bs, out);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.jayway.restassured.examples.springmvc.controller.FileUploadUsingStandardRestAssuredITest.java

@Test
public void file_uploading_works_using_standard_rest_assured() throws IOException {
    File something = folder.newFile("something");
    IOUtils.write("Something21", new FileOutputStream(something));

    given().multiPart(something).when().post("/fileUpload").then().body("size", greaterThan(10)).body("name",
            equalTo("file"));
}

From source file:de.weltraumschaf.registermachine.bytecode.ByteCodeWriter.java

/**
 * Write byte array to file./*  w  w  w .ja v a  2  s  .  c  o m*/
 *
 * @param code byte code array
 * @throws IOException if, file I/O errors happened
 */
public void write(final byte[] code) throws IOException {
    IOUtils.write(code, output);
    IOUtils.closeQuietly(output);
}

From source file:net.link.util.servlet.BufferedServletResponseWrapper.java

/**
 * This method will commit the buffered response to the real output response.
 *
 * @throws IOException//from ww  w. j  av  a 2s. c  om
 */
public void commit(HttpServletResponse response) throws IOException {

    IOUtils.write(commitData(), response.getOutputStream());
}

From source file:com.ewcms.publication.filter.render.TemplateSourceRender.java

/**
 * ?//from  w  w  w .j  a  va2s.c om
 * 
 * @param response
 * @param uri   ?
 * @return
 * @throws IOException
 */
protected boolean output(HttpServletResponse response, Long siteId, String uri) throws IOException {
    TemplateSource source = templateSourcePublishDao.findByUri(siteId, uri);
    if (source == null) {
        logger.debug("TemplateSource is not exist,uri is {}", uri);
        return false;
    }
    IOUtils.write(source.getContent(), response.getOutputStream());
    response.flushBuffer();
    return true;
}

From source file:com.simiacryptus.mindseye.test.unit.SerializationTest.java

/**
 * Compress gz byte [ ]./*  w  w w . j  av  a 2 s .  c  om*/
 *
 * @param bytes the bytes
 * @return the byte [ ]
 */
public static byte[] compressGZ(byte[] bytes) {
    @Nonnull
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        try (@Nonnull
        GZIPOutputStream out = new GZIPOutputStream(byteArrayOutputStream)) {
            IOUtils.write(bytes, out);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return byteArrayOutputStream.toByteArray();
}