List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:Tsne.java
/** * Plot tsne/*from w ww . j av a 2 s . co m*/ * @param matrix the matrix to plot * @param nDims the number * @param labels * @param path the path to write * @throws IOException */ public void plot(INDArray matrix, int nDims, List<String> labels, String path) throws IOException { calculate(matrix, nDims, perplexity); BufferedWriter write = new BufferedWriter(new FileWriter(new File(path), true)); for (int i = 0; i < y.rows(); i++) { if (i >= labels.size()) break; String word = labels.get(i); if (word == null) continue; StringBuffer sb = new StringBuffer(); INDArray wordVector = y.getRow(i); for (int j = 0; j < wordVector.length(); j++) { sb.append(wordVector.getDouble(j)); if (j < wordVector.length() - 1) sb.append(","); } sb.append(","); sb.append(word); sb.append(" "); sb.append("\n"); write.write(sb.toString()); } write.flush(); write.close(); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.web1t.util.Web1TConverter.java
private void writeNGramFile(ConditionalFrequencyDistribution<Integer, String> cfd, int level) throws IOException { FrequencyDistribution<String> letterFD = letterFDs.get(level); BufferedWriter writer = ngramWriters.get(level); for (String key : cfd.getFrequencyDistribution(level).getKeys()) { // add starting letter to frequency distribution if (key.length() > 1) { String subsKey = key.substring(0, 2); String subsKeyLowered = subsKey.toLowerCase(); letterFD.addSample(subsKeyLowered, 1); } else {/*from w ww . j a va2 s . c o m*/ String subsKey = key.substring(0, 1); String subsKeyLowered = subsKey.toLowerCase(); letterFD.addSample(subsKeyLowered, 1); } writer.write(key); writer.write(TAB); writer.write(Long.toString(cfd.getCount(level, key))); writer.write(LF); } writer.flush(); }
From source file:madkitgroupextension.export.Export.java
public void saveIndexList(File dst, File madkitindexfile) throws IOException { FileWriter fw = new FileWriter(dst); BufferedWriter bw = new BufferedWriter(fw); if (m_include_madkit) { FileReader fr = new FileReader(madkitindexfile); BufferedReader bf = new BufferedReader(fr); String line = null;//from ww w. j a va 2s . co m while ((line = bf.readLine()) != null) bw.write(line + "\n"); bf.close(); fr.close(); } else { bw.write("JarIndex-Version: 1.0\n\n"); } int l = (ExportPathTmp + "jardir/").length(); for (File f : FileTools.getTree(ExportPathTmp + "jardir/madkitgroupextension/")) { bw.write(f.getPath().substring(l) + "\n"); } bw.flush(); bw.close(); fw.close(); }
From source file:com.google.code.maven.plugin.http.client.transformer.JiraRssLinkedIssuesEnricher.java
private void enrich(final BufferedWriter writer, final HashSet<String> linkedIssues, final int depth) throws ClientProtocolException, IOException { // removes duplicates for (String jira : rssIssues) { linkedIssues.remove(jira);/*from w ww. j a v a 2s .co m*/ } // request for jira missing in the rss for (final String issue : linkedIssues) { remaining.incrementAndGet(); asyncTaskExecutor.execute(new Runnable() { public void run() { try { rssIssues.add(issue); String content = queryForJira(issue); if (content != null) { synchronized (writer) { writer.write(content); writer.newLine(); writer.flush(); } log.warn("issue [" + issue + "] added"); if (depth > 0) { enrich(writer, inspectItem(content), depth - 1); } } else { log.warn("issue [" + issue + "] not found"); } } catch (MojoExecutionException e) { log.warn("issue [" + issue + "] not found"); } catch (ClientProtocolException e) { log.warn("issue [" + issue + "] not found"); } catch (IOException e) { log.warn("issue [" + issue + "] not found"); } remaining.decrementAndGet(); } }); } }
From source file:org.tallison.cc.CCGetter.java
private void execute(Path indexFile, Path rootDir, Path statusFile) throws IOException { int count = 0; BufferedWriter writer = Files.newBufferedWriter(statusFile, StandardCharsets.UTF_8); InputStream is = null;/* w w w .j a v a 2 s. com*/ try { if (indexFile.endsWith(".gz")) { is = new BufferedInputStream(new GZIPInputStream(Files.newInputStream(indexFile))); } else { is = new BufferedInputStream(Files.newInputStream(indexFile)); } try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { String line = reader.readLine(); while (line != null) { processRow(line, rootDir, writer); if (++count % 100 == 0) { logger.info(indexFile.getFileName().toString() + ": " + count); } line = reader.readLine(); } } } finally { IOUtils.closeQuietly(is); try { writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.linuxbox.enkive.workspace.searchFolder.SearchFolder.java
/** * Writes a tar.gz file to the provided outputstream * //from w w w. jav a2 s .com * @param outputStream * @throws IOException */ public void exportSearchFolder(OutputStream outputStream) throws IOException { BufferedOutputStream out = new BufferedOutputStream(outputStream); GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(out); TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut); File mboxFile = File.createTempFile("mbox-export", ".mbox"); BufferedWriter mboxWriter = new BufferedWriter(new FileWriter(mboxFile)); // Write mbox to tempfile? for (String messageId : getMessageIds()) { try { Message message = retrieverService.retrieve(messageId); mboxWriter.write("From " + message.getDateStr() + "\r\n"); BufferedReader reader = new BufferedReader(new StringReader(message.getReconstitutedEmail())); String tmpLine; while ((tmpLine = reader.readLine()) != null) { if (tmpLine.startsWith("From ")) mboxWriter.write(">" + tmpLine); else mboxWriter.write(tmpLine); mboxWriter.write("\r\n"); } } catch (CannotRetrieveException e) { // Add errors to report // if (LOGGER.isErrorEnabled()) // LOGGER.error("Could not retrieve message with id" // + messageId); } } mboxWriter.flush(); mboxWriter.close(); // Add mbox to tarfile TarArchiveEntry mboxEntry = new TarArchiveEntry(mboxFile, "filename.mbox"); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tOut.putArchiveEntry(mboxEntry); IOUtils.copy(new FileInputStream(mboxFile), tOut); tOut.flush(); tOut.closeArchiveEntry(); mboxWriter.close(); mboxFile.delete(); // Create report in tempfile? // Add report to tarfile // Close out stream tOut.finish(); outputStream.flush(); tOut.close(); outputStream.close(); }
From source file:io.siddhi.extension.io.file.FileSourceRegexModeTestCase.java
@Test public void siddhiIoFileTest8() throws InterruptedException { log.info("test SiddhiIoFile [mode = regex] 8"); String streams = "" + "@App:name('TestSiddhiApp')" + "@source(type='file', mode='regex'," + "dir.uri='file:/" + dirUri + "/regex/xml', " + "begin.regex='(<events>)', " + "end.regex='(</events>)', " + "tailing='true', " + "@map(type='xml'))" + "define stream FooStream (symbol string, price float, volume long); " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("BarStream", new StreamCallback() { @Override/*from w w w . j a v a2 s. c o m*/ public void receive(Event[] events) { EventPrinter.print(events); int n = count.incrementAndGet(); for (Event event : events) { switch (n) { case 1: AssertJUnit.assertEquals(10000L, event.getData(2)); break; case 2: AssertJUnit.assertEquals(10001L, event.getData(2)); break; case 3: AssertJUnit.assertEquals(10002L, event.getData(2)); break; case 4: AssertJUnit.assertEquals(10003L, event.getData(2)); break; case 5: AssertJUnit.assertEquals(10004L, event.getData(2)); break; case 6: AssertJUnit.assertEquals(1000L, event.getData(2)); break; case 7: AssertJUnit.assertEquals(2000L, event.getData(2)); break; default: AssertJUnit.fail("More events received than expected."); } } } }); Thread t1 = new Thread(new Runnable() { public void run() { siddhiAppRuntime.start(); } }); t1.start(); SiddhiTestHelper.waitForEvents(waitTime, 5, count, timeout); Thread t2 = new Thread(new Runnable() { @Override public void run() { File file = new File(dirUri + "/regex/xml/xml_logs (3rd copy).txt"); try { StringBuilder sb = new StringBuilder(); sb.append("<events>\n").append("<event>\n").append("<symbol>").append("GOOGLE") .append("</symbol>\n").append("<price>").append("100").append("</price>\n") .append("<volume>").append("1000").append("</volume>\n").append("</event>\n") .append("</events>\n"); sb.append("<events>\n").append("<event>\n").append("<symbol>").append("YAHOO") .append("</symbol>\n").append("<price>").append("200").append("</price>\n") .append("<volume>").append("2000").append("</volume>\n").append("</event>\n") .append("</events>\n"); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, true)); bufferedWriter.write(sb.toString()); bufferedWriter.newLine(); bufferedWriter.flush(); bufferedWriter.close(); } catch (IOException e) { log.error(e.getMessage()); } } }); t2.start(); SiddhiTestHelper.waitForEvents(waitTime, 7, count, timeout); //assert event count AssertJUnit.assertEquals("Number of events", 7, count.get()); siddhiAppRuntime.shutdown(); }
From source file:org.pentaho.platform.plugin.action.jfreechart.ChartComponent.java
@Override protected boolean executeAction() { int height = -1; int width = -1; String title = ""; //$NON-NLS-1$ Node chartDocument = null;// w ww . j ava 2 s . c o m IPentahoResultSet data = (IPentahoResultSet) getInputValue(ChartComponent.CHART_DATA_PROP); if (!data.isScrollable()) { getLogger().debug("ResultSet is not scrollable. Copying into memory"); //$NON-NLS-1$ IPentahoResultSet memSet = data.memoryCopy(); data.close(); data = memSet; } String urlTemplate = (String) getInputValue(ChartComponent.URL_TEMPLATE); Node chartAttributes = null; String chartAttributeString = null; // Attempt to get chart attributes as an input string or as a resource file // If these don't trip, then we assume the chart attributes are defined in // the component-definition of the chart action. if (getInputNames().contains(ChartComponent.CHART_ATTRIBUTES_PROP)) { chartAttributeString = getInputStringValue(ChartComponent.CHART_ATTRIBUTES_PROP); } else if (isDefinedResource(ChartComponent.CHART_ATTRIBUTES_PROP)) { IActionSequenceResource resource = getResource(ChartComponent.CHART_ATTRIBUTES_PROP); chartAttributeString = getResourceAsString(resource); } // Realize chart attributes as an XML document if (chartAttributeString != null) { try { chartDocument = XmlDom4JHelper.getDocFromString(chartAttributeString, new PentahoEntityResolver()); } catch (XmlParseException e) { getLogger().error( Messages.getInstance().getString("ChartComponent.ERROR_0005_CANT_DOCUMENT_FROM_STRING"), e); //$NON-NLS-1$ return false; } chartAttributes = chartDocument.selectSingleNode(ChartComponent.CHART_ATTRIBUTES_PROP); // This line of code handles a discrepancy between the schema of a chart definition // handed to a dashboard versus a ChartComponent schema. The top level node for the dashboard charts // is <chart>, whereas the ChartComponent expects <chart-attributes>. // TODO: // This discrepancy should be resolved when we have ONE chart solution. if (chartAttributes == null) { chartAttributes = chartDocument.selectSingleNode(ChartComponent.ALTERNATIVE_CHART_ATTRIBUTES_PROP); } } // Default chart attributes are in the component-definition section of the action definition. if (chartAttributes == null) { chartAttributes = getComponentDefinition(true).selectSingleNode(ChartComponent.CHART_ATTRIBUTES_PROP); } // URL click-through attributes (useBaseURL, target) are only processed IF we // have an urlTemplate attribute if ((urlTemplate == null) || (urlTemplate.length() == 0)) { if (chartAttributes.selectSingleNode(ChartComponent.URL_TEMPLATE) != null) { urlTemplate = chartAttributes.selectSingleNode(ChartComponent.URL_TEMPLATE).getText(); } } // These parameters are replacement variables parsed into the // urlTemplate specifically when we have a URL that is a drill-through // link in a chart intended to drill down into the chart data. String parameterName = (String) getInputValue(ChartComponent.PARAMETER_NAME); if ((parameterName == null) || (parameterName.length() == 0)) { if (chartAttributes.selectSingleNode(ChartComponent.PARAMETER_NAME) != null) { parameterName = chartAttributes.selectSingleNode(ChartComponent.PARAMETER_NAME).getText(); } } // These parameters are replacement variables parsed into the // urlTemplate specifically when we have a URL that is a drill-through // link in a chart intended to drill down into the chart data. String outerParameterName = (String) getInputValue(ChartComponent.OUTER_PARAMETER_NAME); if ((outerParameterName == null) || (outerParameterName.length() == 0)) { if (chartAttributes.selectSingleNode(ChartComponent.OUTER_PARAMETER_NAME) != null) { outerParameterName = chartAttributes.selectSingleNode(ChartComponent.OUTER_PARAMETER_NAME) .getText(); } } String chartType = chartAttributes.selectSingleNode(ChartDefinition.TYPE_NODE_NAME).getText(); // --------------- This code allows inputs to override the chartAttributes // of width, height, and title Object widthObj = getInputValue(ChartDefinition.WIDTH_NODE_NAME); if (widthObj != null) { width = Integer.parseInt(widthObj.toString()); if (width != -1) { if (chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME) == null) { ((Element) chartAttributes).addElement(ChartDefinition.WIDTH_NODE_NAME); } chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME).setText(Integer.toString(width)); } } Object heightObj = getInputValue(ChartDefinition.HEIGHT_NODE_NAME); if (heightObj != null) { height = Integer.parseInt(heightObj.toString()); if (height != -1) { if (chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME) == null) { ((Element) chartAttributes).addElement(ChartDefinition.HEIGHT_NODE_NAME); } chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME) .setText(Integer.toString(height)); } } Object titleObj = getInputValue(ChartDefinition.TITLE_NODE_NAME); if (titleObj != null) { if (chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME) == null) { ((Element) chartAttributes).addElement(ChartDefinition.TITLE_NODE_NAME); } chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME).setText(titleObj.toString()); } // ----------------End of Override // ---------------Feed the Title and Subtitle information through the input substitution Node titleNode = chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME); if (titleNode != null) { String titleStr = titleNode.getText(); if (titleStr != null) { title = titleStr; String newTitle = applyInputsToFormat(titleStr); titleNode.setText(newTitle); } } List subtitles = chartAttributes.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME); if ((subtitles == null) || (subtitles.isEmpty())) { Node subTitlesNode = chartAttributes.selectSingleNode(ChartDefinition.SUBTITLES_NODE_NAME); if (subTitlesNode != null) { subtitles = chartAttributes.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME); } } else { // log a deprecation warning for this property... getLogger().warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", //$NON-NLS-1$ ChartDefinition.SUBTITLE_NODE_NAME, ChartDefinition.SUBTITLES_NODE_NAME)); getLogger().warn(Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", //$NON-NLS-1$ ChartDefinition.SUBTITLE_NODE_NAME)); } if (subtitles != null) { for (Iterator iter = subtitles.iterator(); iter.hasNext();) { Node subtitleNode = (Node) iter.next(); if (subtitleNode != null) { String subtitleStr = subtitleNode.getText(); if (subtitleStr != null) { String newSubtitle = applyInputsToFormat(subtitleStr); subtitleNode.setText(newSubtitle); } } } } // ----------------End of Format // Determine if we are going to read the chart data set by row or by column boolean byRow = false; if (getInputStringValue(ChartComponent.BY_ROW_PROP) != null) { byRow = Boolean.valueOf(getInputStringValue(ChartComponent.BY_ROW_PROP)).booleanValue(); } // TODO Figure out why these overrides are called here. Seems like we are doing the same thing we just did above, // but // could possibly step on the height and width values set previously. if (height == -1) { height = (int) getInputLongValue( ChartComponent.CHART_ATTRIBUTES_PROP + "/" + ChartDefinition.HEIGHT_NODE_NAME, 50); //$NON-NLS-1$ } if (width == -1) { width = (int) getInputLongValue( ChartComponent.CHART_ATTRIBUTES_PROP + "/" + ChartDefinition.WIDTH_NODE_NAME, 100); //$NON-NLS-1$ } if (title.length() <= 0) { title = getInputStringValue( ChartComponent.CHART_ATTRIBUTES_PROP + "/" + ChartDefinition.TITLE_NODE_NAME); //$NON-NLS-1$ } // Select the right dataset to use based on the chart type // Default to category dataset String datasetType = ChartDefinition.CATEGORY_DATASET_STR; boolean isStacked = false; Node datasetTypeNode = chartAttributes.selectSingleNode(ChartDefinition.DATASET_TYPE_NODE_NAME); if (datasetTypeNode != null) { datasetType = datasetTypeNode.getText(); } Dataset dataDefinition = null; if (ChartDefinition.XY_SERIES_COLLECTION_STR.equalsIgnoreCase(datasetType)) { dataDefinition = new XYSeriesCollectionChartDefinition(data, byRow, chartAttributes, getSession()); } else if (ChartDefinition.TIME_SERIES_COLLECTION_STR.equalsIgnoreCase(datasetType)) { Node stackedNode = chartAttributes.selectSingleNode(ChartDefinition.STACKED_NODE_NAME); if (stackedNode != null) { isStacked = Boolean.valueOf(stackedNode.getText()).booleanValue(); } if ((isStacked) && (ChartDefinition.AREA_CHART_STR.equalsIgnoreCase(chartType))) { dataDefinition = new TimeTableXYDatasetChartDefinition(data, byRow, chartAttributes, getSession()); } else { dataDefinition = new TimeSeriesCollectionChartDefinition(data, byRow, chartAttributes, getSession()); } } else if (ChartDefinition.PIE_CHART_STR.equalsIgnoreCase(chartType)) { dataDefinition = new PieDatasetChartDefinition(data, byRow, chartAttributes, getSession()); } else if (ChartDefinition.DIAL_CHART_STR.equalsIgnoreCase(chartType)) { dataDefinition = new DialWidgetDefinition(data, byRow, chartAttributes, width, height, getSession()); } else if (ChartDefinition.BAR_LINE_CHART_STR.equalsIgnoreCase(chartType)) { dataDefinition = new BarLineChartDefinition(data, byRow, chartAttributes, getSession()); } else if (ChartDefinition.BUBBLE_CHART_STR.equalsIgnoreCase(chartType)) { dataDefinition = new XYZSeriesCollectionChartDefinition(data, byRow, chartAttributes, getSession()); } else { dataDefinition = new CategoryDatasetChartDefinition(data, byRow, chartAttributes, getSession()); } // Determine what we are sending back - Default to OUTPUT_PNG output // OUTPUT_PNG = the chart gets written to a file in .png format // OUTPUT_SVG = the chart gets written to a file in .svg (XML) format // OUTPUT_CHART = the chart in a byte stream gets stored as as an IContentItem // OUTPUT_PNG_BYTES = the chart gets sent as a byte stream in .png format int outputType = JFreeChartEngine.OUTPUT_PNG; if (getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP) != null) { if (ChartComponent.SVG_TYPE.equalsIgnoreCase(getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP))) { outputType = JFreeChartEngine.OUTPUT_SVG; } else if (ChartComponent.CHART_TYPE .equalsIgnoreCase(getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP))) { outputType = JFreeChartEngine.OUTPUT_CHART; } else if (ChartComponent.PNG_BYTES_TYPE .equalsIgnoreCase(getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP))) { outputType = JFreeChartEngine.OUTPUT_PNG_BYTES; } } boolean keepTempFile = false; if (isDefinedInput(KEEP_TEMP_FILE_PROP)) { keepTempFile = getInputBooleanValue(KEEP_TEMP_FILE_PROP, false); } JFreeChart chart = null; switch (outputType) { /**************************** OUTPUT_PNG_BYTES *********************************************/ case JFreeChartEngine.OUTPUT_PNG_BYTES: chart = JFreeChartEngine.getChart(dataDefinition, title, "", width, height, this); //$NON-NLS-1$ // TODO Shouldn't the mime types and other strings here be constant somewhere? Where do we // put this type of general info ? String mimeType = "image/png"; //$NON-NLS-1$ IContentItem contentItem = getOutputItem("chartdata", mimeType, ".png"); //$NON-NLS-1$ //$NON-NLS-2$ contentItem.setMimeType(mimeType); try { OutputStream output = contentItem.getOutputStream(getActionName()); ChartUtilities.writeChartAsPNG(output, chart, width, height); } catch (Exception e) { error(Messages.getInstance().getErrorString("ChartComponent.ERROR_0004_CANT_CREATE_IMAGE"), e); //$NON-NLS-1$ return false; } break; /**************************** OUTPUT_SVG && OUTPUT_PNG *************************************/ case JFreeChartEngine.OUTPUT_SVG: // intentionally fall through to PNG case JFreeChartEngine.OUTPUT_PNG: // Don't include the map in a file if HTML_MAPPING_HTML is specified, as that // param sends the map back on the outputstream as a string boolean createMapFile = !isDefinedOutput(ChartComponent.HTML_MAPPING_HTML); boolean hasTemplate = urlTemplate != null && urlTemplate.length() > 0; File[] fileResults = createTempFile(outputType, hasTemplate, !keepTempFile); if (fileResults == null) { error(Messages.getInstance().getErrorString("ChartComponent.ERROR_0003_CANT_CREATE_TEMP_FILES")); //$NON-NLS-1$ return false; } String chartId = fileResults[ChartComponent.FILE_NAME].getName().substring(0, fileResults[ChartComponent.FILE_NAME].getName().indexOf('.')); String filePathWithoutExtension = ChartComponent.TEMP_DIRECTORY + chartId; PrintWriter printWriter = new PrintWriter(new StringWriter()); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(dataDefinition, title, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ outputType, printWriter, info, this); // Creating the image map boolean useBaseUrl = true; String urlTarget = "pentaho_popup"; //$NON-NLS-1$ // Prepend the base url to the front of every drill through link if (chartAttributes.selectSingleNode(ChartComponent.USE_BASE_URL_TAG) != null) { Boolean booleanValue = new Boolean( chartAttributes.selectSingleNode(ChartComponent.USE_BASE_URL_TAG).getText()); useBaseUrl = booleanValue.booleanValue(); } // What target for link? _parent, _blank, etc. if (chartAttributes.selectSingleNode(ChartComponent.URL_TARGET_TAG) != null) { urlTarget = chartAttributes.selectSingleNode(ChartComponent.URL_TARGET_TAG).getText(); } String mapString = null; if (hasTemplate) { try { String mapId = fileResults[ChartComponent.MAP_NAME].getName().substring(0, fileResults[ChartComponent.MAP_NAME].getName().indexOf('.')); mapString = ImageMapUtilities.getImageMap(mapId, info, new StandardToolTipTagFragmentGenerator(), new PentahoChartURLTagFragmentGenerator(urlTemplate, urlTarget, useBaseUrl, dataDefinition, parameterName, outerParameterName)); if (createMapFile) { BufferedWriter out = new BufferedWriter( new FileWriter(fileResults[ChartComponent.MAP_NAME])); out.write(mapString); out.flush(); out.close(); } } catch (IOException e) { error(Messages.getInstance().getErrorString("ChartComponent.ERROR_0001_CANT_WRITE_MAP", //$NON-NLS-1$ fileResults[ChartComponent.MAP_NAME].getPath())); return false; } catch (Exception e) { error(e.getLocalizedMessage(), e); return false; } } /******************************************************************************************************* * Legitimate outputs for the ChartComponent in an action sequence: * * CHART_OUTPUT (chart-output) Stores the chart in the content repository as an IContentItem. * * CHART_FILE_NAME_OUTPUT (chart-filename) Returns the name of the chart file, including the file extension * (with no path information) as a String. * * HTML_MAPPING_OUTPUT (chart-mapping) Returns the name of the file that the map has been saved to, including * the file extension (with no path information) as a String. Will be empty if url-template is undefined * * HTML_MAPPING_HTML (chart-map-html) Returns the chart image map HTML as a String. Will be empty if * url-template is undefined * * BASE_URL_OUTPUT (base-url) Returns the web app's base URL (ie., http://localhost:8080/pentaho) as a String. * * HTML_IMG_TAG (image-tag) Returns the HTML snippet including the image map, image (<IMG />) tag for the chart * image with src, width, height and usemap attributes defined. Usemap will not be included if url-template is * undefined. * *******************************************************************************************************/ // Now set the outputs Set outputs = getOutputNames(); if ((outputs != null) && (outputs.size() > 0)) { Iterator iter = outputs.iterator(); while (iter.hasNext()) { String outputName = (String) iter.next(); String outputValue = null; if (outputName.equals(ChartComponent.CHART_FILE_NAME_OUTPUT)) { outputValue = fileResults[ChartComponent.FILE_NAME].getName(); } else if (outputName.equals(ChartComponent.HTML_MAPPING_OUTPUT)) { if (hasTemplate) { outputValue = fileResults[ChartComponent.MAP_NAME].getName(); } } else if (outputName.equals(ChartComponent.HTML_MAPPING_HTML)) { outputValue = mapString; } else if (outputName.equals(ChartComponent.BASE_URL_OUTPUT)) { IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); outputValue = requestContext.getContextPath(); } else if (outputName.equals(ChartComponent.CONTEXT_PATH_OUTPUT)) { IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); outputValue = requestContext.getContextPath(); } else if (outputName.equals(ChartComponent.FULLY_QUALIFIED_SERVER_URL_OUTPUT)) { IApplicationContext applicationContext = PentahoSystem.getApplicationContext(); if (applicationContext != null) { outputValue = applicationContext.getFullyQualifiedServerURL(); } else { IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); outputValue = requestContext.getContextPath(); } } else if (outputName.equals(ChartComponent.HTML_IMG_TAG)) { outputValue = hasTemplate ? mapString : ""; //$NON-NLS-1$ outputValue += "<img border=\"0\" "; //$NON-NLS-1$ outputValue += "width=\"" + width + "\" "; //$NON-NLS-1$//$NON-NLS-2$ outputValue += "height=\"" + height + "\" "; //$NON-NLS-1$//$NON-NLS-2$ if (hasTemplate) { outputValue += "usemap=\"#" + fileResults[ChartComponent.MAP_NAME].getName().substring( 0, fileResults[ChartComponent.MAP_NAME].getName().indexOf('.')) + "\" "; //$NON-NLS-1$//$NON-NLS-2$ } IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); String contextPath = requestContext.getContextPath(); outputValue += "src=\"" + contextPath + "getImage?image=" //$NON-NLS-1$//$NON-NLS-2$ + fileResults[ChartComponent.FILE_NAME].getName() + "\"/>"; //$NON-NLS-1$ } if (outputValue != null) { setOutputValue(outputName, outputValue); } } } break; /************************** OUTPUT_CHART && DEFAULT *************************************/ case JFreeChartEngine.OUTPUT_CHART: // intentionally fall through to default default: String chartName = ChartComponent.CHART_OUTPUT; if (isDefinedInput(ChartComponent.CHART_NAME_PROP)) { chartName = getInputStringValue(ChartComponent.CHART_NAME_PROP); } chart = JFreeChartEngine.getChart(dataDefinition, title, "", width, height, this); //$NON-NLS-1$ setOutputValue(chartName, chart); break; } return true; }
From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java
String refreshToken(String refresh_token) { // android.os.Debug.waitForDebugger(); Log.d(TAG, "refreshToken= " + refresh_token); // check initialization if (mOcp == null || isEmpty(mOcp.m_server_url)) return null; // nothing to do if (isEmpty(refresh_token)) return null; String postUrl = mOcp.m_server_url + "token"; // set up connection HttpURLConnection huc = getHUC(postUrl); huc.setDoOutput(true);//from w w w . j ava 2 s . c o m huc.setInstanceFollowRedirects(false); huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // prepare parameters List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7); nameValuePairs.add(new BasicNameValuePair("client_id", mOcp.m_client_id)); nameValuePairs.add(new BasicNameValuePair("client_secret", mOcp.m_client_secret)); nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token")); nameValuePairs.add(new BasicNameValuePair("refresh_token", refresh_token)); if (!isEmpty(mOcp.m_scope)) nameValuePairs.add(new BasicNameValuePair("scope", mOcp.m_scope)); try { // write parameters to http connection OutputStream os = huc.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); // get URL encoded string from list of key value pairs String postParam = getQuery(nameValuePairs); Logd("refreshToken", "url: " + postUrl); Logd("refreshToken", "POST: " + postParam); writer.write(postParam); writer.flush(); writer.close(); os.close(); // try to connect huc.connect(); // connexion status int responseCode = huc.getResponseCode(); Logd(TAG, "refreshToken response: " + responseCode); // if 200 - OK, read the json string if (responseCode == 200) { sysout("refresh_token - code " + responseCode); InputStream is = huc.getInputStream(); String result = convertStreamToString(is); is.close(); huc.disconnect(); Logd("refreshToken", "result: " + result); sysout("refresh_token - content: " + result); return result; } huc.disconnect(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:it.cnr.icar.eric.client.xml.registry.jaas.LoginModuleManager.java
private void writeCfgFile(File configFile, String cfgFileContents, boolean append) throws JAXRException { BufferedWriter writer = null; try {//from w ww . ja v a2 s .com writer = new BufferedWriter(new FileWriter(configFile, append)); writer.write(cfgFileContents, 0, cfgFileContents.length()); writer.flush(); } catch (IOException ex) { throw new JAXRException(ex); } finally { if (writer != null) { try { writer.close(); } catch (IOException ex) { // ignore writer = null; } } } }