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:io.ingenieux.lambada.invoker.fixtures.Fixture.java

public void doSomethingRawWithContext(InputStream is, OutputStream os, Context c) throws Exception {
    Integer value = Integer.valueOf(IOUtils.toString(is));

    final int result = 2 * value;

    c.getLogger().log("" + (result * 2));

    IOUtils.write("" + result, os);
}

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

@LambadaFunction(timeout = 300)
@ApiGateway(path = "/sayhello/2")
public void sayHelloLowLevel2(OutputStream os, Context ctx) throws Exception {
    IOUtils.write("Hello, World!", os);
}

From source file:gui.CompressDecompress.java

public static List<List<BigInteger>> decompressBuffer(byte[] bytes) {

    try {/* w  w w . ja va  2  s  .  c o m*/
        String loc = "temp.dat";

        OutputStream out = new FileOutputStream(loc);
        IOUtils.write(bytes, out);
        out.close();

        byte[] decArray = AdaptiveArithmeticDecompress.decoder(loc);
        List<List<BigInteger>> encBuffer = deserialize(decArray);
        return encBuffer;

    } catch (IOException ex) {
        Logger.getLogger(CompressDecompress.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(CompressDecompress.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:com.erigir.maven.plugin.processor.ValidationProcessor.java

@Override
public boolean innerProcess(Log log, File src, File dst) throws MojoExecutionException, IOException {
    validator.validate(src);/* w w w .  j  a  v  a2 s  .  com*/

    String input = IOUtils.toString(new FileInputStream(src));
    IOUtils.write(input, new FileOutputStream(dst));
    return true;
}

From source file:com.betfair.tornjak.monitor.active.url.CheckResponseAbstractTest.java

private void write(String s) throws IOException {
    IOUtils.write(s, new FileOutputStream(fileName));
}

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

/**
 * ?/*from   w  ww  .  jav a 2 s . c o  m*/
 * 
 * @param response
 * @param uri   ?
 * @return
 * @throws IOException
 */
protected boolean output(HttpServletResponse response, String uri) throws IOException {
    TemplateSource source = templateSourceService.getTemplateSourceByUniquePath(uri);
    if (source == null) {
        logger.debug("TemplateSource is not exist,uri is {}", uri);
        return false;
    }
    TemplatesrcEntity entity = source.getSourceEntity();
    if (entity == null || entity.getSrcEntity() == null) {
        return false;
    }

    IOUtils.write(entity.getSrcEntity(), response.getOutputStream());
    response.flushBuffer();

    return true;
}

From source file:mongosensors_client.JsonFile.java

public void write(JSONObject jsonStream) throws Exception {
    File f = new File(this.path);
    if (!f.exists()) {
        f.createNewFile();/*from w w  w .j  a  va  2s .  co  m*/
    }
    OutputStream is = new FileOutputStream(this.path);
    String jsonTxt = jsonStream.toString();
    IOUtils.write(jsonTxt, is);
}

From source file:com.github.jjYBdx4IL.utils.fma.FMAConfig.java

@SuppressWarnings("deprecation")
public static Object readConfig(String filename, Class<?> clazz) throws IOException {
    try {/* w  w w  .  j a va  2s.c  o  m*/
        File configFile = new File(CFG_DIR, filename);

        XStream xstream = new XStream(new StaxDriver());
        xstream.autodetectAnnotations(true);

        if (configFile.exists()) {
            return xstream.fromXML(configFile);
        }

        // save empty config so user is able to add his details
        configFile.getParentFile().mkdirs();
        Object config = clazz.newInstance();
        String xml = xstream.toXML(config);
        try (OutputStream os = new FileOutputStream(configFile)) {
            IOUtils.write(formatXml(xml), os);
        }
        return config;
    } catch (InstantiationException | IllegalAccessException ex) {
        throw new IOException(ex);
    }
}

From source file:com.adaptris.core.services.jdbc.types.StringColumnTranslator.java

@Override
public void write(JdbcResultRow rs, int column, OutputStream out) throws SQLException, IOException {
    IOUtils.write(toString(rs.getFieldValue(column)), out);
}

From source file:com.logsniffer.model.file.FileLogTest.java

@Test
public void testReadInt() throws IOException {
    File openFile = File.createTempFile("test", "txt");
    openFile.deleteOnExit();/*from  ww  w  .  ja  v  a  2  s .c om*/
    FileOutputStream out = new FileOutputStream(openFile);
    FileLog flog = new FileLog(openFile);
    IOUtils.write("line1\n", out);
    out.flush();
    ByteLogInputStream lis = new DirectFileLogAccess(flog).getInputStream(null);
    // Log instanatiated before data is written
    assertEquals(-1, lis.read());
    flog = new FileLog(openFile);
    lis = new DirectFileLogAccess(flog).getInputStream(null);
    assertEquals('l', lis.read());
    assertEquals('i', lis.read());
    assertEquals('n', lis.read());
    assertEquals('e', lis.read());
    assertEquals('1', lis.read());
    assertEquals('\n', lis.read());
    assertEquals(-1, lis.read());

    // Write more, but lis doesn't see the new data due to size limitation
    IOUtils.write("l2\n", out);
    out.flush();
    assertEquals(-1, lis.read());
    lis.close();
}