List of usage examples for org.apache.commons.io IOUtils write
public static void write(StringBuffer data, OutputStream output) throws IOException
StringBuffer
to bytes on an OutputStream
using the default character encoding of the platform. From source file:ductive.console.jline.NonInteractiveTerminal.java
@Override public void print(String value) throws IOException { IOUtils.write(value, out); }
From source file:com.stratio.ingestion.sink.cassandra.CassandraSinkIT.java
private void _do() throws TTransportException, IOException, InterruptedException { final Context context = new Context(); final InetSocketAddress contactPoint = CassandraTestHelper.getCassandraContactPoint(); context.put("tables", "keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT"); context.put("hosts", contactPoint.getAddress().getHostAddress()); context.put("batchSize", "1"); context.put("consistency", "QUORUM"); final File cqlFile = File.createTempFile("flumeTest", "cql"); cqlFile.deleteOnExit();/* w w w. j a v a 2 s . c om*/ IOUtils.write( "CREATE KEYSPACE IF NOT EXISTS keyspaceTestCassandraSinkIT WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };\n\n" + "CREATE TABLE IF NOT EXISTS keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT (" + "id uuid, bool_field boolean, int_field int, PRIMARY KEY (int_field)" + ");\n\n", new FileOutputStream(cqlFile)); context.put("cqlFile", cqlFile.getAbsolutePath()); sink = new CassandraSink(); sink.configure(context); Context channelContext = new Context(); channelContext.put("capacity", "10000"); channelContext.put("transactionCapacity", "200"); channel = new MemoryChannel(); channel.setName("junitChannel"); Configurables.configure(channel, channelContext); sink.setChannel(channel); sink.start(); sink.stop(); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.text.TextWriter.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null;/*from ww w .ja v a 2 s.com*/ try { docOS = getOutputStream(aJCas, filenameSuffix); IOUtils.write(aJCas.getDocumentText(), docOS); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } }
From source file:com.ngdata.hbaseindexer.rest.IndexerDefinitionMessageBodyWriter.java
@Override public void writeTo(IndexerDefinition indexerDefinition, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException { byte[] jsonBytes = IndexerDefinitionJsonSerDeser.INSTANCE.toJsonBytes(indexerDefinition); IOUtils.write(jsonBytes, outputStream); }
From source file:at.tfr.securefs.ws.FileServiceBean.java
@MTOM(enabled = true, threshold = 10240) @WebMethod/*from ww w. ja va 2s. c o m*/ @Override public void write(@WebParam(name = "relativePath") String relPath, @WebParam(name = "bytes") byte[] b) throws IOException { log.debug("write File: " + relPath); try { String tmpFileName = Paths.get(relPath).getFileName().toString() + System.currentTimeMillis(); Path tmpPath = Files.createFile(configuration.getTmpPath().resolve(tmpFileName)); try { try (OutputStream os = Files.newOutputStream(tmpPath)) { IOUtils.write(b, os); } preProcessor.preProcess(tmpPath); log.debug("preprocessed File: " + relPath); } finally { Files.deleteIfExists(tmpPath); } } catch (ModuleException me) { String message = "preProcessing of relPath failed: " + me.getMessage(); if (log.isDebugEnabled()) { log.debug(message, me); } log.info(message); throw new IOException(message); } Path path = SecureFileSystemBean.resolvePath(relPath, configuration.getBasePath(), configuration.isRestrictedToBasePath()); log.debug("write File: " + relPath + " to " + path); Path parent = path.getParent(); Files.createDirectories(parent); // create parent directories unconditionally OutputStream encrypter = crypterProvider.getEncrypter(path); try { IOUtils.copyLarge(new ByteArrayInputStream(b), encrypter); } finally { encrypter.close(); } logInfo("written File: " + path, null); }
From source file:ductive.console.jline.NonInteractiveTerminal.java
@Override public void print(Ansi value) throws IOException { IOUtils.write(value.toString(), out); }
From source file:net.scran24.admin.server.services.SurveyManagementServiceImpl.java
public void copyTemplate(String srcPath, File dstFile, String surveyId, String locale) throws IOException { InputStream pageTemplate = getServletContext().getResourceAsStream(srcPath); String page = IOUtils.toString(pageTemplate).replace("$AUTH_REALM$", surveyId).replace("$LOCALE$", locale); dstFile.createNewFile();//from w w w .j a v a2 s .c o m OutputStream pageOut = new FileOutputStream(dstFile); IOUtils.write(page, pageOut); pageTemplate.close(); pageOut.close(); }
From source file:mitm.common.security.crypto.PBEncryptedStreamTest.java
@Test public void testEncryptDecrypt() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); char[] password = "test".toCharArray(); OutputStream encryptionStream = new PBEncryptionOutputStream(bos, password); String message = "test 123"; IOUtils.write(message, encryptionStream); encryptionStream.close();//from w ww .j av a 2 s .c om ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); InputStream decryptionStream = new PBDecryptionInputStream(bis, password); String decryptedMessage = IOUtils.toString(decryptionStream); assertEquals(message, decryptedMessage); }
From source file:com.github.brandtg.pantopod.crawler.FileBasedCrawlingEventHandler.java
@Override protected boolean handleData(URI url, byte[] data) throws IOException { File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath()); FileUtils.forceMkdir(outputRoot);//from w w w .j av a2s . co m File outputData = new File(outputRoot, DAT_FILE); if (!outputData.exists()) { try (OutputStream os = new FileOutputStream(outputData)) { IOUtils.write(data, os); LOG.info("Wrote {}", outputRoot); } return true; } return false; }
From source file:com.technophobia.substeps.report.ScreenshotWriter.java
public Void visit(StepImplementationNode executionNode) { if (executionNode.getResult() != null) { byte[] screenshot = executionNode.getResult().getScreenshot(); if (screenshot != null) { File screenshotFile = new File(directoryForScreenshots, executionNode.getId() + SCREENSHOT_SUFFIX); try { IOUtils.write(screenshot, new FileOutputStream(screenshotFile)); } catch (Exception e) { log.error("Unable to create screenshot", e); }/*from ww w . j ava 2s. c o m*/ } } return null; }