List of usage examples for java.io Writer toString
public String toString()
From source file:com.xpn.xwiki.internal.template.WikiTemplateRenderer.java
public String render(String template) throws IOException, ParseException, MissingParserException, XWikiVelocityException { Writer writer = new StringWriter(); render(template, writer);// w w w .j ava2s . co m return writer.toString(); }
From source file:eu.learnpad.core.impl.or.XwikiBridgeInterfaceRestResource.java
private void invokeSimulationTaskNotification(String restOperationName, String modelSetId, String modelId, String artifactId, String simulationId, SimulationData data) throws LpRestException { // <host>/learnpad/or/bridge/{modelsetid}/{modelid}/{restOperationName}?artifactid=aid,simulationid=id String contentType = "application/xml"; HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/or/bridge/%s/%s/%s", DefaultRestResource.REST_URI, modelSetId, modelId, restOperationName); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader("Content-Type", contentType); NameValuePair[] queryString = new NameValuePair[2]; queryString[0] = new NameValuePair("artifactid", artifactId); queryString[1] = new NameValuePair("simulationid", simulationId); postMethod.setQueryString(queryString); try {/*w w w.java 2s .c om*/ Writer simDataWriter = new StringWriter(); JAXBContext jc = JAXBContext.newInstance(SimulationData.class); jc.createMarshaller().marshal(data, simDataWriter); RequestEntity requestEntity = new StringRequestEntity(simDataWriter.toString(), contentType, "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); } catch (JAXBException | IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:eu.learnpad.core.impl.or.XwikiBridgeInterfaceRestResource.java
@Override public void simulationInstanceNotification(String modelSetId, String modelId, String action, String simulationId, SimulationData data) throws LpRestException { // <host>/learnpad/or/bridge/{modelsetid}/{modelid}/simulationinstancenotification?action={started|stopped},simulationid=id String contentType = "application/xml"; HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/or/bridge/%s/%s/simulationinstancenotification", DefaultRestResource.REST_URI, modelSetId, modelId); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader("Content-Type", contentType); NameValuePair[] queryString = new NameValuePair[2]; queryString[0] = new NameValuePair("action", action); queryString[1] = new NameValuePair("simulationid", simulationId); postMethod.setQueryString(queryString); try {// w w w . j av a 2s.c om Writer simDataWriter = new StringWriter(); JAXBContext jc = JAXBContext.newInstance(SimulationData.class); jc.createMarshaller().marshal(data, simDataWriter); RequestEntity requestEntity = new StringRequestEntity(simDataWriter.toString(), contentType, "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); } catch (JAXBException | IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:org.apache.ambari.server.orm.helpers.dbms.GenericDbmsHelper.java
@Override public String getAddColumnStatement(String tableName, DBAccessor.DBColumnInfo columnInfo) { Writer writer = new StringWriter(); TableDefinition tableDefinition = new TableDefinition(); tableDefinition.setName(tableName);/*from w w w . j av a2 s . com*/ tableDefinition.buildAddFieldWriter(createStubAbstractSessionFromPlatform(databasePlatform), convertToFieldDefinition(columnInfo), writer); return writer.toString(); }
From source file:fr.mby.portal.web.controller.PortalController.java
/** * Perform internal rendering.//w w w .j a v a 2s .c om * * @param request * @param response * @param view * @param appsToRender * @throws ServletException * @throws IOException */ protected String preRenderApp(final HttpServletRequest request, final HttpServletResponse response, final IApp appToRender) throws ServletException, IOException { String appContent = ""; if (appToRender != null) { final ServletContext loginContext = this.servletContext.getContext(appToRender.getWebPath()); if (loginContext != null) { final Writer sout = new StringWriter(1024); final OpaHttpServletRequest opaRequest = new OpaHttpServletRequest(request, appToRender); final SwallowingHttpServletResponse swallowingResponse = new SwallowingHttpServletResponse(response, sout, "UTF-8"); loginContext.getRequestDispatcher("/").forward(opaRequest, swallowingResponse); final String appRendered = sout.toString(); appContent = this.stripHeaders(appRendered); } } return appContent; }
From source file:org.apache.ambari.server.orm.helpers.dbms.GenericDbmsHelper.java
@Override public String getDropUniqueConstraintStatement(String tableName, String constraintName) { UniqueKeyConstraint uniqueKeyConstraint = new UniqueKeyConstraint(); uniqueKeyConstraint.setName(constraintName); Writer writer = new StringWriter(); TableDefinition tableDefinition = new TableDefinition(); tableDefinition.setName(tableName);/* ww w . j av a 2s. c o m*/ tableDefinition.buildUniqueConstraintDeletionWriter(createStubAbstractSessionFromPlatform(databasePlatform), uniqueKeyConstraint, writer); return writer.toString(); }
From source file:gov.va.vinci.leo.listener.BaseListener.java
/** * Check for an error in the return status of the processed CAS. Return true * if there is an error./*from w ww .j a v a 2s .co m*/ * * @param aCas CAS that was processed * @param aStatus Status object that contains the exception if one is thrown * @return True if an error was returned, False otherwise */ protected boolean checkForError(CAS aCas, EntityProcessStatus aStatus) { if (aStatus != null && aStatus.isException()) { LOG.error("Exceptions thrown on getMeta call to remote service..."); List<Exception> exceptions = aStatus.getExceptions(); String errors = ""; this.lastException = ""; for (Exception exception : exceptions) { LOG.error(exception.getMessage(), exception); Writer result = new StringWriter(); PrintWriter printWriter = new PrintWriter(result); exception.printStackTrace(printWriter); errors += exception.toString() + "\n---\n"; errors += result.toString() + "\n\n"; } // for this.lastException = errors; // Write exception out to file if the output directory is set. if (mOutputDir != null) { BufferedWriter s = null; try { File errorOutFile = new File(mOutputDir, this.getReferenceLocation(aCas.getJCas()) + ".err"); s = new BufferedWriter(new FileWriter(errorOutFile)); s.write(errors); } catch (Exception e) { LOG.error("Error writing to stream: " + e); } finally { try { s.close(); } catch (Exception e) { /** Ignore this exception, we are just closing here **/ LOG.warn("Error closing write: " + e); } } // finally } // if return true; } // if aStatus != null && isException return false; }
From source file:org.saiku.web.rest.resources.BasicTagRepositoryResource.java
@GET @Produces({ "text/csv" }) @Path("/{cubeIdentifier}/{tagName}/export/csv") public Response getDrillthroughExport(@PathParam("cubeIdentifier") String cubeIdentifier, @PathParam("tagName") String tagName, @QueryParam("maxrows") @DefaultValue("0") Integer maxrows, @QueryParam("returns") String returns, @QueryParam("connection") String connection, @QueryParam("catalog") String catalog, @QueryParam("schema") String schema, @QueryParam("cube") String cube, @QueryParam("additional") String additional) { ResultSet rs = null;/* ww w .j av a2s .co m*/ try { List<Integer> cellPosition = new ArrayList<Integer>(); cellPosition.add(0); List<KeyValue<String, String>> additionalColumns = new ArrayList<KeyValue<String, String>>(); if (additional != null) { for (String kvs : additional.split(",")) { String[] kv = kvs.split(":"); if (kv.length == 2) { additionalColumns.add(new KeyValue<String, String>(kv[0], kv[1])); } } } SaikuTag tag = getTag(cubeIdentifier, tagName); if (tag != null) { String queryName = UUID.randomUUID().toString(); SaikuCube saikuCube = new SaikuCube(connection, cube, cube, cube, catalog, schema); olapQueryService.createNewOlapQuery(queryName, saikuCube); SaikuQuery q = olapQueryService.simulateTag(queryName, tag); if (!cube.startsWith("[")) { cube = "[" + cube + "]"; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); boolean first = true; for (SaikuTuple tuple : tag.getSaikuTuples()) { String mdx = null; for (SaikuMember member : tuple.getSaikuMembers()) { if (mdx == null) { mdx = "SELECT (" + member.getUniqueName(); } else { mdx += ", " + member.getUniqueName(); } } boolean where = true; if (tag.getSaikuDimensionSelections() != null) { for (SaikuDimensionSelection sdim : tag.getSaikuDimensionSelections()) { if (sdim.getSelections().size() > 1) { where = false; } } } if (where) { mdx += ") ON COLUMNS from " + cube; SelectNode sn = (new DefaultMdxParserImpl().parseSelect(q.getMdx())); final Writer writer = new StringWriter(); sn.getFilterAxis().unparse(new ParseTreeWriter(new PrintWriter(writer))); if (StringUtils.isNotBlank(writer.toString())) { mdx += "\r\nWHERE " + writer.toString(); } System.out.println("Executing... :" + mdx); olapQueryService.executeMdx(queryName, mdx); rs = olapQueryService.drillthrough(queryName, cellPosition, maxrows, returns); byte[] doc = olapQueryService.exportResultSetCsv(rs, ",", "\"", first, additionalColumns); first = false; outputStream.write(doc); } else { if (tag.getSaikuDimensionSelections() != null) { for (SaikuDimensionSelection sdim : tag.getSaikuDimensionSelections()) { for (SaikuSelection ss : sdim.getSelections()) { if (ss.getType() == Type.MEMBER) { String newmdx = mdx; newmdx += "," + ss.getUniqueName() + ") ON COLUMNS from " + cube; System.out.println("Executing... :" + newmdx); olapQueryService.executeMdx(queryName, newmdx); rs = olapQueryService.drillthrough(queryName, cellPosition, maxrows, returns); byte[] doc = olapQueryService.exportResultSetCsv(rs, ",", "\"", first, additionalColumns); first = false; outputStream.write(doc); } } } } } } byte csv[] = outputStream.toByteArray(); String name = SaikuProperties.webExportCsvName; return Response.ok(csv, MediaType.APPLICATION_OCTET_STREAM) .header("content-disposition", "attachment; filename = " + name + "-drillthrough.csv") .header("content-length", csv.length).build(); } } catch (Exception e) { log.error("Cannot export drillthrough tag (" + tagName + ")", e); return Response.serverError().build(); } finally { if (rs != null) { try { Statement statement = rs.getStatement(); statement.close(); rs.close(); } catch (SQLException e) { throw new SaikuServiceException(e); } finally { rs = null; } } } return Response.serverError().build(); }
From source file:com.xpn.xwiki.internal.template.WikiTemplateRenderer.java
private String evaluateString(String content) throws XWikiVelocityException { Writer writer = new StringWriter(); evaluateString(content, writer);// www. java 2s . c om return writer.toString(); }
From source file:com.cisco.oss.foundation.tools.simulator.rest.resources.SimulatorConfigurationResource.java
@GET public Response getSimulator(@PathParam("port") final int port) { if (!simulatorService.simulatorExists(port)) { String msg = "can not retrieve simulator. simulator on port " + port + " doesn't exist"; logger.error(msg);//from w w w . ja va2 s . co m return Response.status(Status.BAD_REQUEST).entity(msg).build(); } SimulatorEntity simulator = simulatorService.getSimulator(port); Writer strWriter = new StringWriter(); try { objectMapper.writeValue(strWriter, simulator.getSimulatorResponses()); } catch (Exception e) { logger.error("failed to write simulator to json", e); return Response.status(Status.INTERNAL_SERVER_ERROR).entity("failed to write simulator to json") .build(); } String simulatorStr = strWriter.toString(); return Response.status(Status.OK).entity(simulatorStr).build(); }