Example usage for java.io Writer flush

List of usage examples for java.io Writer flush

Introduction

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

Prototype

public abstract void flush() throws IOException;

Source Link

Document

Flushes the stream.

Usage

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/shardDbStatus.do")
public void shardDbStatus(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int deviceCode = Integer.parseInt(Utility.isNullNumber(request.getParameter("deviceCode")));

    List<DbStatus> dbStatusLst = subDao.dbLstNan(deviceCode);
    PersonJson result = new PersonJson();
    result.setAaData(dbStatusLst);/*from  w  ww  . j av  a  2  s  . c o m*/

    JSONObject jsonObject = JSONObject.fromObject(result);

    Writer writer = setResponse(response).getWriter();
    writer.write(jsonObject.toString());

    writer.flush();

    log.debug("end - shardDbStatus()");
}

From source file:net.sf.taverna.raven.plugins.PluginManager.java

public void savePluginSites() {
    Element pluginSitesElement = new Element("pluginSites");
    for (PluginSite pluginSite : pluginSites) {
        if (!(pluginSite instanceof TavernaPluginSite))
            pluginSitesElement.addContent(pluginSite.toXml());
    }/*from   ww w  .ja v a 2 s  . c o  m*/
    File pluginSitesFile = new File(pluginsDir, "plugin-sites.xml");
    try {
        Writer writer = new FileWriter(pluginSitesFile);
        new XMLOutputter(Format.getPrettyFormat()).output(pluginSitesElement, writer);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        logger.error("Error writing plugin sites to " + pluginSitesFile.getPath());
    }
}

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/shardCllectionCommand.do")
public void shardCllectionCommand(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int deviceCode = Integer.parseInt(Utility.isNullNumber(request.getParameter("deviceCode")));
    String collectionName = request.getParameter("collectionName");

    List<Object> findMongoCollections = cllectionCommand(deviceCode, collectionName);

    PersonJson result = new PersonJson();
    result.setAaData(findMongoCollections);

    JSONObject jsonObject = JSONObject.fromObject(result);

    Writer writer = setResponse(response).getWriter();
    writer.write(jsonObject.toString());

    writer.flush();

    log.debug("end - shardCllectionCommand()");
}

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/subGraphDate.do")
public void subGraphDate(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String period = request.getParameter("period");

    String edDate = request.getParameter("edateStr");
    String stDate = DateUtil.getOffsetDateTime(edDate, -1, "yyyy-MM-dd HH:mm");

    if (period.equals("2h")) {
        stDate = DateUtil.getOffsetDateTime(edDate, -2, "yyyy-MM-dd HH:mm");
    } else if (period.equals("3h")) {
        stDate = DateUtil.getOffsetDateTime(edDate, -3, "yyyy-MM-dd HH:mm");
    } else if (period.equals("6h")) {
        stDate = DateUtil.getOffsetDateTime(edDate, -6, "yyyy-MM-dd HH:mm");
    } else if (period.equals("12h")) {
        stDate = DateUtil.getOffsetDateTime(edDate, -12, "yyyy-MM-dd HH:mm");
    } else if (period.equals("1d")) {
        stDate = DateUtil.getOffsetDate(edDate, -1, "yyyy-MM-dd HH:mm");
    } else if (period.equals("1w")) {
        stDate = DateUtil.getOffsetDate(edDate, -7, "yyyy-MM-dd HH:mm");
    } else if (period.equals("2w")) {
        stDate = DateUtil.getOffsetDate(edDate, -14, "yyyy-MM-dd HH:mm");
    } else if (period.equals("1m")) {
        stDate = DateUtil.getOffsetDate(edDate, -30, "yyyy-MM-dd HH:mm");
    } else if (period.equals("all")) {
        stDate = DateUtil.getOffsetDate(edDate, -1 * logRetentionPeriod, "yyyy-MM-dd HH:mm");
    }//w ww.  j a v  a 2 s . c o m

    String result = stDate + "|" + edDate;

    Writer writer = setResponse(response).getWriter();
    writer.write(result);

    writer.flush();

    log.debug("end - subGraphDate()");
}

From source file:org.jasig.portlet.cms.controller.ViewPostController.java

@ResourceMapping
public void handleResourceRequest(final ResourceRequest request, final ResourceResponse response)
        throws Exception {

    final String postPath = PortletRequestUtils.getRequiredStringParameter(request, "postPath");
    final Writer writer = response.getWriter();

    logDebug("Retrieving post to process attachments...");

    final Post post = getRepositoryDao().getPost(postPath);
    if (post != null) {

        logDebug("Retrieved post to process attachments...");

        final List<Attachment> list = post.getAttachments();
        final StringBuilder builder = new StringBuilder();

        for (final Attachment attachment : list) {
            final AbstractAttachmentThumbnailCreator creator = AbstractAttachmentThumbnailCreator
                    .createImageThumbnailCreator(attachment, request, getPortletContext(), response);

            builder.append(creator.generateHtmlFragment());
        }/*from  w w w  .  j av  a2s  . c  o m*/

        if (builder.length() > 0) {

            logDebug("Writing output response data...");

            response.setContentType("text/html");
            writer.write(builder.toString());
            writer.flush();
        }
    }
}

From source file:com.openedit.generators.VelocityGenerator.java

public void generate(WebPageRequest inContext, Page inPage, Output inOut) throws OpenEditException {
    if (log.isDebugEnabled()) {
        log.debug("Rendering " + inPage);
    }/*from   w w w. j  ava 2 s  .  c om*/

    if (!inPage.exists()) //TODO: Create a new existed() method to speed up checks
    {
        String vir = inPage.get("virtual");
        if (!Boolean.parseBoolean(vir)) {
            log.info("Missing: " + inPage.getPath());
            try {
                inOut.getWriter().write("404: " + inPage.getPath());
                return;
            } catch (IOException e) {
                throw new ContentNotAvailableException("Missing: " + inPage.getPath(), inPage.getPath());
            }
        } else {
            return; //do nothing
        }
    }
    try {

        if (inPage.isBinary()) {
            //this should not happen
            InputStream in = inPage.getInputStream();
            new OutputFiller().fill(in, inContext.getOutputStream());
            return;
        }
        inContext.unpackageVariables(); //TODO: Remove this silliness
        VelocityContext context = new VelocityContext(inContext.getPageMap());
        Writer writer = inOut.getWriter();

        if (inPage.getContentItem() instanceof FileItem) //Faster and does cache
        {
            String path = inPage.getContentItem().getPath();
            //log.info( "Rendering " + inPage );
            String filter = inPage.getProperty("oetextfilter");
            if (filter != null) {
                path = path + "?filter=" + filter + "&locale=" + inContext.getLocale();
            }

            getEngine().mergeTemplate(path, inPage.getCharacterEncoding(), context, writer);
        } else //do a string eval MUCH SLOWER
        {
            Reader in = inPage.getReader();
            //log.info( "Eval " + inPage );
            getEngine().evaluate(context, writer, inPage.getPath(), in);
        }
        writer.flush();
    } catch (MethodInvocationException ex) {
        if (ex.getWrappedThrowable() instanceof ContentNotAvailableException) {
            throw new OpenEditException("Error generating " + inPage.getPath(),
                    (OpenEditException) ex.getWrappedThrowable());
        }
        if (ex.getWrappedThrowable() instanceof OpenEditException) {
            throw (OpenEditException) ex.getWrappedThrowable();
        }
        Throwable wrapped = ex.getWrappedThrowable();
        if (ignoreError(wrapped)) {
            //ignore
            return;
        }
        throw new OpenEditException(wrapped);
    } catch (ParseErrorException pex) {
        throw new OpenEditException(pex.getMessage() + " on " + inPage.getPath(), pex);
    } catch (Exception ioex) {
        if (ignoreError(ioex)) {
            log.info("Browser canceled request");
            return;
        }
        if (ioex instanceof OpenEditException) {
            throw (OpenEditException) ioex;
        }
        throw new OpenEditException(ioex);
    }
}

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/setGraphDate.do")
public void setGraphDate(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String period = request.getParameter("period");
    String selectDate = request.getParameter("selectDate");
    String selectHour = Utility.isNull(request.getParameter("selectHour"), "00");
    String selectMin = Utility.isNull(request.getParameter("selectMin"), "00");

    String fullDate = selectDate + " " + selectHour + ":" + selectMin;
    String stDate = DateUtil.getOffsetDateMin(fullDate, -30, "yyyy-MM-dd HH:mm");
    String edDate = DateUtil.getOffsetDateMin(fullDate, 30, "yyyy-MM-dd HH:mm");

    String stStr = "";
    String edStr = "";

    if (period.equals("2h")) {
        stDate = DateUtil.getOffsetDateTime(fullDate, -1, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDateTime(fullDate, 1, "yyyy-MM-dd HH:mm");
    } else if (period.equals("3h")) {
        stStr = DateUtil.getOffsetDateTime(fullDate, -1, "yyyy-MM-dd HH:mm");
        stDate = DateUtil.getOffsetDateMin(stStr, -30, "yyyy-MM-dd HH:mm");
        edStr = DateUtil.getOffsetDateTime(fullDate, 1, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDateMin(edStr, 30, "yyyy-MM-dd HH:mm");
    } else if (period.equals("6h")) {
        stDate = DateUtil.getOffsetDateTime(fullDate, -3, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDateTime(fullDate, 3, "yyyy-MM-dd HH:mm");
    } else if (period.equals("12h")) {
        stDate = DateUtil.getOffsetDateTime(fullDate, -6, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDateTime(fullDate, 6, "yyyy-MM-dd HH:mm");
    } else if (period.equals("1d")) {
        stDate = DateUtil.getOffsetDateTime(fullDate, -12, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDateTime(fullDate, 12, "yyyy-MM-dd HH:mm");
    } else if (period.equals("1w")) {
        stStr = DateUtil.getOffsetDate(fullDate, -3, "yyyy-MM-dd HH:mm");
        stDate = DateUtil.getOffsetDateTime(stStr, -12, "yyyy-MM-dd HH:mm");
        edStr = DateUtil.getOffsetDate(fullDate, 3, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDateTime(edStr, 12, "yyyy-MM-dd HH:mm");
    } else if (period.equals("2w")) {
        stDate = DateUtil.getOffsetDate(fullDate, -7, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDate(fullDate, 7, "yyyy-MM-dd HH:mm");
    } else if (period.equals("1m")) {
        stDate = DateUtil.getOffsetDate(fullDate, -15, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDate(fullDate, 15, "yyyy-MM-dd HH:mm");
    } else if (period.equals("3m")) {
        int halfPeriod = Math.round(logRetentionPeriod / 2);
        stDate = DateUtil.getOffsetDate(fullDate, -1 * halfPeriod, "yyyy-MM-dd HH:mm");
        edDate = DateUtil.getOffsetDate(fullDate, halfPeriod, "yyyy-MM-dd HH:mm");
    }// w  w w  .  ja  v a2s  .  c  o  m

    Date now = new Date();
    String strNow = DateUtil.getCurrentDate(now, "yyyy-MM-dd HH:mm");
    int compareDate = DateUtil.getCompareDate(strNow, edDate, "yyyy-MM-dd HH:mm");

    String result = stDate + "|" + edDate + "|" + compareDate;

    Writer writer = setResponse(response).getWriter();
    writer.write(result);

    writer.flush();

    log.debug("end - subGraphDate()");
}

From source file:com.joliciel.jochre.lexicon.LexiconErrorWriter.java

@Override
public void onFinish() {
    try {//from  www .ja  v a 2  s  .com
        knownWordErrorWriter.close();
        knownWordCorrectWriter.close();
        unknownWordErrorWriter.close();
        unknownWordCorrectWriter.close();
        allWordWriter.close();
        allErrorWriter.close();

        Writer statsWriter = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(new File(outputDir, baseName + "_KEMatrix.csv"), false), "UTF8"));
        writeStats(statsWriter, errorMap);

        statsWriter.flush();
        statsWriter.close();
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }

}

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/isShowGraph.do")
public void isShowGraph(CommonDto dto, HttpServletResponse response) throws Exception {
    log.debug("start - isShowGraph()");
    boolean isShowGraph = true;

    setDataSourceName(dto);//  w w  w.j  av a  2s.com
    String dsname = dto.getDsname();

    Map<String, StatusDatasourceName> allDatasource = new AllStatusRule().allStatusDatasourceNameByMap();
    StatusDatasourceName statusInfo = allDatasource.get(dsname);
    if (statusInfo == null) {
        isShowGraph = false;
    }

    JSONObject data = new JSONObject();
    data.put("dsname", dsname);
    data.put("isshow", isShowGraph);
    data.put("collname", dto.getCollname());
    data.put("dbname", Utility.isNull(dto.getDbname()));

    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("UTF-8");

    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");

    Writer writer = response.getWriter();
    writer.write(data.toString());

    log.debug(data.toString());
    writer.flush();

    log.debug("end - isShowGraph()");
}

From source file:ch.randelshofer.cubetwister.HTMLExporter.java

/**
 * Processes a HTML template./*from w w  w .  j av a  2  s  .co m*/
 *
 * @param filename The filename of the template.
 * @param tokens An input stream for reading the contents of the template.
 */
private void processHTMLTemplate(String filename, String[] tokens) throws IOException {
    p.setProgress(p.getProgress() + 1);
    putNextEntry(filename);
    Writer w = new OutputStreamWriter(entryOut, "UTF-8");
    writeData(w, tokens, 0, tokens.length);
    w.flush();
    closeEntry();
}