Example usage for java.io Writer toString

List of usage examples for java.io Writer toString

Introduction

In this page you can find the example usage for java.io Writer toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.o2d.pkayjava.editor.CustomExceptionHandler.java

public void uncaughtException(Thread t, Throwable e) {
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);/*from  www  . j  a va 2s  . co  m*/
    String stacktrace = result.toString();
    String filename = "overlog.txt";
    writeToFile(stacktrace, filename);
    printWriter.close();

    sendError(stacktrace);

    showErrorDialog();
    //defaultUEH.uncaughtException(t, e);
}

From source file:org.ld4l.bib2lod.io.FileOutputDescriptorTest.java

private String modelToCanonicalString(String rdf, String lang) {
    Writer w = new StringWriter();
    ModelFactory.createDefaultModel().read(new StringReader(rdf), null, lang).write(w, "N-TRIPLE");
    return w.toString();
}

From source file:com.teradata.tempto.internal.convention.sql.SqlQueryConventionBasedTest.java

private String resolveTemplates(String query) {
    try {//from  ww w  .j a va2 s .  c o m
        Template template = new Template("name", new StringReader(query),
                new freemarker.template.Configuration());
        Map<String, Object> data = newHashMap();
        data.put("mutableTables", mutableTablesState().getNameInDatabaseMap());

        Writer writer = new StringWriter();
        template.process(data, writer);
        writer.flush();

        return writer.toString();
    } catch (TemplateException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.cvit.cabig.dmr.cmef.server.JobsResource.java

@Get("htm|html")
public Representation listJobsHtml() throws ResourceException {
    Iterator<ComputationJob> jobs = listJobs();

    List<ComputationJob> jobList = new ArrayList<ComputationJob>();
    while (jobs.hasNext()) {
        jobList.add(jobs.next());//w  ww.  j a va 2 s . c  o m
    }

    SimpleHash root = new SimpleHash();
    root.put("entryName", entryName);
    root.put("modelName", modelName);
    root.put("model", model);
    root.put("jobs", jobList);
    root.put("funcs", new TemplateFunctions());

    Configuration config = new Configuration();
    try {
        Template template = new Template("jobs.html", new StringReader(HTML_FTL), config);
        Writer out = new StringWriter();
        template.process(root, out);
        setStatus(Status.SUCCESS_OK);
        return new StringRepresentation(out.toString(), MediaType.TEXT_HTML);
    } catch (IOException e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Exception reading template.", e);
    } catch (TemplateException e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Template error: " + e.getMessage(), e);
    }
}

From source file:com.cisco.oss.foundation.tools.simulator.rest.resources.SimulatorQueueResource.java

/**
 * for the last request call /simulator/8888/queue/1
 * for the last 6 requests call /simulator/8888/queue/6
 * for all the requests call /simulator/8888/queue/all
 *//*from   w  w w.  j  a va  2 s .  com*/
@GET
@Path("/{numOfMessages}")
public Response getAllMessagesInQueue(@PathParam("port") final int port,
        @PathParam("numOfMessages") final String numOfMessages) throws Exception {

    if (!simulatorService.simulatorExists(port)) {
        String msg = "can not retrieve simulators queue. simulator on port " + port + " doesn't exist";
        logger.error(msg);
        return Response.status(Status.BAD_REQUEST).entity(msg).build();
    }

    String body = "[]";
    if ("all".equalsIgnoreCase(numOfMessages)) {
        List<SimulatorRequest> allQueueOfSimulator = simulatorService.getAllQueueOfSimulator(port);

        if (CollectionUtils.isNotEmpty(allQueueOfSimulator)) {
            Writer strWriter = new StringWriter();

            objectMapper.writeValue(strWriter, allQueueOfSimulator);
            body = strWriter.toString();
        }

    } else {
        if (NumberUtils.isNumber(numOfMessages)) {
            int numOfMsg = Integer.valueOf(numOfMessages);
            List<SimulatorRequest> queueOfSimulator = simulatorService.getQueueOfSimulator(port, numOfMsg);

            Writer strWriter = new StringWriter();

            objectMapper.writeValue(strWriter, queueOfSimulator);
            body = strWriter.toString();
        } else {
            String msg = "number of messages (" + numOfMessages + ") isn't a valid number";
            logger.error(msg);
            return Response.status(Status.BAD_REQUEST).entity("").build();
        }
    }

    return Response.status(Status.OK).entity(body).build();
}

From source file:com.sir_m2x.messenger.utils.CustomExceptionHandler.java

@Override
public void uncaughtException(final Thread t, final Throwable e) {
    ((NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
    Utils.saveEventLog(MessengerService.getEventLog());

    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HHMM");
    String timestamp = df.format(new Date(System.currentTimeMillis()));

    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);/*  w  w w. j  a v  a2s . com*/
    String stacktrace = result.toString();
    printWriter.close();
    String filename = timestamp + " " + Build.VERSION.SDK_INT + ".stacktrace";
    if (Preferences.logCrash)
        //      if (this.url != null)
        //         sendToServer(stacktrace, filename);
        if (this.localPath != null)
            writeToFile(stacktrace, filename);

    this.defaultUEH.uncaughtException(t, e);
}

From source file:org.jdal.gis.google.DirectionsService.java

private String responseToString(Object response) throws IOException {
    Writer writer = new StringWriter();
    InputStreamReader reader = new InputStreamReader((InputStream) response);
    int i;/*  www . ja va 2  s  .c  om*/
    while ((i = reader.read()) != -1)
        writer.write(i);

    return writer.toString();

}

From source file:com.oracle.tutorial.jdbc.ClobSample.java

public void addRowToCoffeeDescriptions(String coffeeName, String fileName) throws SQLException {
    PreparedStatement pstmt = null;
    try {/* w  w w .ja  v  a2  s . co m*/
        Clob myClob = this.con.createClob();

        Writer clobWriter = myClob.setCharacterStream(1);
        String str = this.readFile(fileName, clobWriter);
        System.out.println("Wrote the following: " + clobWriter.toString());
        if (this.settings.dbms.equals("mysql")) {
            System.out.println("MySQL, setting String in Clob object with setString method");
            myClob.setString(1, str);
        }
        System.out.println("Length of Clob: " + myClob.length());
        String sql = "INSERT INTO COFFEE_DESCRIPTIONS VALUES(?,?)";
        pstmt = this.con.prepareStatement(sql);
        pstmt.setString(1, coffeeName);
        pstmt.setClob(2, myClob);
        pstmt.executeUpdate();
    } catch (SQLException sqlex) {
        JDBCTutorialUtilities.printSQLException(sqlex);
    } catch (Exception ex) {
        System.out.println("Unexpected exception: " + ex.toString());
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
    }
}

From source file:de.kp.ames.web.core.rss.RssProvider.java

public String getFeed() {

    try {/*from   w  ww.  j av  a2s  .  co  m*/

        SyndFeed feed = new SyndFeedImpl();

        /* 
         * Describe feed
         */
        feed.setTitle(FEED_TITLE);
        feed.setDescription(FEED_DESC);

        feed.setFeedType(FEED_TYPE);
        feed.setUri(FEED_URI);

        /* 
         * Finally we get feeds from processor
         */
        List<SyndEntry> entries = processor.getEntries();
        feed.setEntries(entries);

        Writer writer = new StringWriter();

        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);

        String content = writer.toString();
        writer.close();

        return content;

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
    }

    return null;

}

From source file:com.aestheticsw.jobkeywords.liquibase.LiquibaseActuator.java

public void validate() {
    Liquibase liquibase;/* w  w  w  . j  a  v  a  2s .c  o  m*/
    try {
        liquibase = super.createLiquibase(dataSource.getConnection());
    } catch (LiquibaseException | SQLException e) {
        throw new RuntimeException("Liquibase could not be instantiated", e);
    }
    try {
        liquibase.validate();
        Writer statusWriter = new StringWriter();
        liquibase.reportStatus(true, "", statusWriter);
        log.info("\nLiquibase Status: \n\n" + statusWriter.toString());

        Writer unexpectedWriter = new StringWriter();
        liquibase.reportUnexpectedChangeSets(true, "", unexpectedWriter);
        log.info("\nLiquibase Unexpected Changesets: \n\n" + unexpectedWriter.toString());
    } catch (LiquibaseException e) {
        throw new RuntimeException("Liquibase could not validate", e);
    }
}