Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何限制速度输出的大小_Java_Velocity - Fatal编程技术网

Java 如何限制速度输出的大小

Java 如何限制速度输出的大小,java,velocity,Java,Velocity,我正在使用java和ApacheVelocity1.7来评估模板 以下是示例代码: public void internalEvaluate(Map<String, Object> customContext, String templateText) throws IOException { // add custom context to VelocityContext VelocityContext context = new VelocityContext(

我正在使用java和ApacheVelocity1.7来评估模板

以下是示例代码:

public void internalEvaluate(Map<String, Object> customContext, String templateText) throws IOException {

    // add custom context to VelocityContext
    VelocityContext context = new VelocityContext();
    for (Map.Entry<String, Object> entry : customContext.entrySet()) {
        context.put(entry.getKey(), entry.getValue());
    }
    
    // define writer
    StringWriter output = new StringWriter();
    // define logTag
    String logTag = "TestVTL";
    
    // check input template text
    if (templateText == null)
        templateText = "$noDescription";
        
    Velocity.evaluate(context, output, logTag, templateText);
    
    // write output to file
    saveToFile(out);
}
public void internalEvaluate(映射customContext,字符串templateText)引发IOException{
//向VelocityContext添加自定义上下文
VelocityContext上下文=新的VelocityContext();
对于(Map.Entry:customContext.entrySet()){
put(entry.getKey(),entry.getValue());
}
//定义作者
StringWriter输出=新建StringWriter();
//定义日志标签
字符串logTag=“TestVTL”;
//检查输入模板文本
if(templateText==null)
templateText=“$noDescription”;
evaluate(上下文、输出、日志标记、模板文本);
//将输出写入文件
保存文件(输出);
}
但是,特定的customContext或templateText可能会产生较大的输出

输出可以创建为文件,但不能由编辑器打开

下面是我的问题

问题1。 我想在运行时(或调用evaluate()之前)限制或检查输出的大小,并抛出有关创建太大文件的警告消息

Velocity是否提供配置或Api来执行类似操作

问题2。 评估过程可能需要很长时间

我想知道速度评估过程的进展情况

有可能获得进度信息吗


请注意,

由于Velocity只看到一个
Writer
类,因此它无法计算输出大小

最好的选择是实现一个
CustomStringWriter
类,当其内部大小达到某个限制时,该类将抛出异常