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:com.igormaznitsa.mindmap.exporters.PNGImageExporter.java
@Override public void doExport(final MindMapPanel panel, final JComponent options, final OutputStream out) throws IOException { for (final Component compo : ((JPanel) options).getComponents()) { if (compo instanceof JCheckBox) { final JCheckBox cb = (JCheckBox) compo; if ("unfold".equalsIgnoreCase(cb.getActionCommand())) { flagExpandAllNodes = cb.isSelected(); } else if ("back".equalsIgnoreCase(cb.getActionCommand())) { flagSaveBackground = cb.isSelected(); }/*from w w w . j a v a2 s . c om*/ } } final MindMapPanelConfig newConfig = new MindMapPanelConfig(panel.getConfiguration(), false); newConfig.setDrawBackground(flagSaveBackground); newConfig.setScale(1.0f); final RenderedImage image = MindMapPanel.renderMindMapAsImage(panel.getModel(), newConfig, flagExpandAllNodes); if (image == null) { if (out == null) { LOGGER.error("Can't render map as image"); panel.getController().getDialogProvider(panel) .msgError(BUNDLE.getString("PNGImageExporter.msgErrorDuringRendering")); return; } else { throw new IOException("Can't render image"); } } final ByteArrayOutputStream buff = new ByteArrayOutputStream(128000); ImageIO.write(image, "png", buff);//NOI18N final byte[] imageData = buff.toByteArray(); File fileToSaveMap = null; OutputStream theOut = out; if (theOut == null) { fileToSaveMap = selectFileForFileFilter(panel, BUNDLE.getString("PNGImageExporter.saveDialogTitle"), ".png", BUNDLE.getString("PNGImageExporter.filterDescription"), BUNDLE.getString("PNGImageExporter.approveButtonText")); fileToSaveMap = checkFileAndExtension(panel, fileToSaveMap, ".png");//NOI18N theOut = fileToSaveMap == null ? null : new BufferedOutputStream(new FileOutputStream(fileToSaveMap, false)); } if (theOut != null) { try { IOUtils.write(imageData, theOut); } finally { if (fileToSaveMap != null) { IOUtils.closeQuietly(theOut); } } } }
From source file:ctrus.pa.bow.core.Vocabulary.java
public final void writeTermFrequencyTo(OutputStream out) throws IOException { IOUtils.write("BUCKET,FREQ\n", out); for (Long bucket : _termFrequency.keySet()) { TermFreq tfq = _termFrequency.get(bucket); IOUtils.write(tfq.bucket + "," + tfq.freq + "\n", out); }/*from w ww . ja v a 2 s .c o m*/ }
From source file:com.hortonworks.iot.MyProcessor.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();//from ww w . j a va 2 s . com if (flowFile == null) { return; } final Boolean toUppercase = context.getProperty(PROP_TO_UPPERCASE).asBoolean(); final Double bufSize = context.getProperty(PROP_BUFFER_SIZE).asDataSize(DataUnit.B); if (flowFile.getSize() > bufSize) { getLogger().warn("Incoming string too big: {} vs buffer: {}", new Object[] { flowFile.getSize(), bufSize }); session.transfer(flowFile, REL_FAILURE); return; } try { if (toUppercase) { flowFile = session.write(flowFile, new StreamCallback() { @Override public void process(InputStream inputStream, OutputStream outputStream) throws IOException { String s = IOUtils.toString(inputStream); IOUtils.write(s.toUpperCase(), outputStream); } }); } session.transfer(flowFile, REL_SUCCESS); } catch (Exception e) { getLogger().error("Failed while processing a string", e); session.transfer(flowFile, REL_FAILURE); } }
From source file:ch.entwine.weblounge.test.site.GreeterHTMLAction.java
/** * {@inheritDoc}/* w ww .j ava 2s . c o m*/ * * @see ch.entwine.weblounge.common.impl.site.HTMLActionSupport#startStage(ch.entwine.weblounge.common.request.WebloungeRequest, * ch.entwine.weblounge.common.request.WebloungeResponse, * ch.entwine.weblounge.common.content.page.Composer) */ @Override public int startStage(WebloungeRequest request, WebloungeResponse response, Composer composer) throws ActionException { try { String htmlGreeting = StringEscapeUtils.escapeHtml(greeting); IOUtils.write("<h1>" + htmlGreeting + "</h1>", response.getWriter()); // Include another pagelet include(request, response, PAGELET_ID, null); return HTMLAction.SKIP_COMPOSER; } catch (IOException e) { throw new ActionException("Unable to send json response", e); } }
From source file:info.magnolia.ui.mediaeditor.data.EditHistoryTrackingPropertyImpl.java
@Override public void setValue(byte[] bytes) throws ReadOnlyException { if (!unDoneActions.isEmpty() && !unDoneActions.peek().actionName.equals(doneActions.peek().actionName)) { unDoneActions.clear();//from ww w .j a v a 2 s. co m } currentActionInitialized = true; FileOutputStream fos = null; try { fos = new FileOutputStream(doneActions.peek().file); IOUtils.write(bytes, fos); super.setValue(bytes); } catch (IOException e) { logErrorAndNotify(i18n.translate("ui-mediaeditor.editHistoryTrackingProperty.ioException.message"), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:ee.ria.xroad.signer.console.Utils.java
static void bytesToFile(String file, byte[] bytes) throws Exception { try (FileOutputStream out = new FileOutputStream(file)) { IOUtils.write(bytes, out); System.out.println(file); } catch (Exception e) { System.out.println("ERROR: Cannot save to file " + file + ":" + e); }/*from w w w . j a v a2s . com*/ }
From source file:io.restassured.examples.springmvc.controller.MultiPartFileUploadITest.java
@Test public void object_serialization_works() throws IOException { File file = folder.newFile("something"); IOUtils.write("Something3210", new FileOutputStream(file)); Greeting greeting = new Greeting(); greeting.setFirstName("John"); greeting.setLastName("Doe"); String content = RestAssuredMockMvc.given().multiPart("controlName1", file, "mime-type1") .multiPart("controlName2", greeting, "application/json").when().post("/multiFileUpload").then() .root("[%d]").body("size", withArgs(0), is(13)).body("name", withArgs(0), equalTo("controlName1")) .body("originalName", withArgs(0), equalTo("something")) .body("mimeType", withArgs(0), equalTo("mime-type1")) .body("content", withArgs(0), equalTo("Something3210")).body("size", withArgs(1), greaterThan(10)) .body("name", withArgs(1), equalTo("controlName2")) .body("originalName", withArgs(1), equalTo("file")) .body("mimeType", withArgs(1), equalTo("application/json")) .body("content", withArgs(1), notNullValue()).extract().path("[1].content"); JsonPath jsonPath = new JsonPath(content); assertThat(jsonPath.getString("firstName"), equalTo("John")); assertThat(jsonPath.getString("lastName"), equalTo("Doe")); }
From source file:com.haulmont.yarg.reporting.Reporting.java
protected void generateReport(Report report, ReportTemplate reportTemplate, OutputStream outputStream, Map<String, Object> handledParams, BandData rootBand) { String extension = StringUtils.substringAfterLast(reportTemplate.getDocumentName(), "."); if (reportTemplate.isCustom()) { try {/*from w ww .jav a 2 s .c om*/ byte[] bytes = reportTemplate.getCustomReport().createReport(report, rootBand, handledParams); IOUtils.write(bytes, outputStream); } catch (IOException e) { throw new ReportingException(format("An error occurred while processing custom template [%s].", reportTemplate.getDocumentName()), e); } } else { FormatterFactoryInput factoryInput = new FormatterFactoryInput(extension, rootBand, reportTemplate, outputStream); ReportFormatter formatter = formatterFactory.createFormatter(factoryInput); formatter.renderDocument(); } }
From source file:com.github.hipchat.api.HipChat.java
public boolean deleteRoom(String room_id) { String query = String.format(HipChatConstants.ROOMS_DELETE_QUERY_FORMAT, HipChatConstants.JSON_FORMAT, authToken);//from w w w . j av a2s . c om StringBuilder params = new StringBuilder(); if (room_id == null || room_id.length() == 0) { throw new IllegalArgumentException("Cannot delete room with null or empty id"); } else { params.append("room_id="); params.append(room_id); } final String paramsToSend = params.toString(); OutputStream output = null; InputStream input = null; HttpURLConnection connection = null; boolean result = false; try { URL requestUrl = getRequestUrl(HipChatConstants.API_BASE, HipChatConstants.ROOMS_DELETE, query); connection = getPostConnection(requestUrl, paramsToSend); output = new BufferedOutputStream(connection.getOutputStream()); IOUtils.write(paramsToSend, output); IOUtils.closeQuietly(output); input = connection.getInputStream(); result = UtilParser.parseDeleteResult(input); } catch (IOException e) { LogMF.error(logger, "IO Exception: {0}", new Object[] { e.getMessage() }); } finally { IOUtils.closeQuietly(input); connection.disconnect(); } return result; }
From source file:cz.lbenda.rcp.config.ConfigurationRW.java
/** Write stream with configuration to file * @param configFile name of configuration wile where is data write * @param content content which will be saved * @throws RuntimeException hold the IOException *//*from ww w . j a v a2 s . c om*/ public void writeConfig(String configFile, String content) throws RuntimeException { try (OutputStream os = writeConfig(configFile)) { IOUtils.write(content, os); } catch (IOException e) { throw new RuntimeException("Problem with write configuration to file: " + configFile, e); } }