001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import java.io.IOException; 022 023import lucee.runtime.PageContextImpl; 024import lucee.runtime.exp.PageException; 025import lucee.runtime.ext.tag.TagImpl; 026import lucee.runtime.op.Caster; 027 028/** 029* Flushes currently available data to the client. 030* 031* 032* 033**/ 034public final class Flush extends TagImpl { 035 036 /** Flush the output each time at least the specified number of bytes become available. HTML 037 ** headers, and any data that is already available when you make this call, are not included in 038 ** the count. */ 039 private double interval=-1; 040 041 @Override 042 public void release() { 043 super.release(); 044 interval=-1; 045 } 046 047 /** set the value interval 048 * Flush the output each time at least the specified number of bytes become available. HTML 049 * headers, and any data that is already available when you make this call, are not included in 050 * the count. 051 * @param interval value to set 052 **/ 053 public void setInterval(double interval) { 054 this.interval=interval; 055 } 056 057 058 @Override 059 public int doStartTag() throws PageException { 060 try { 061 if(interval==-1)((PageContextImpl)pageContext).getRootOut().flush(); 062 else ((PageContextImpl)pageContext).getRootOut().setBufferConfig((int)interval,true); 063 } catch (IOException e) { 064 throw Caster.toPageException(e); 065 } 066 return SKIP_BODY; 067 } 068 069 @Override 070 public int doEndTag() { 071 return EVAL_PAGE; 072 } 073}