Search in sources :

Example 6 with TemplateOutputException

use of org.thymeleaf.exceptions.TemplateOutputException in project thymeleaf by thymeleaf.

the class ThrottledTemplateWriterWriterAdapter method allow.

public void allow(final int limit) {
    if (limit == Integer.MAX_VALUE || limit < 0) {
        this.unlimited = true;
        this.limit = -1;
    } else {
        this.unlimited = false;
        this.limit = limit;
    }
    this.flowController.stopProcessing = (this.limit == 0);
    if (this.overflowSize == 0 || this.limit == 0) {
        return;
    }
    try {
        if (this.unlimited || this.limit > this.overflowSize) {
            this.writer.write(this.overflow, 0, this.overflowSize);
            if (!this.unlimited) {
                this.limit -= this.overflowSize;
            }
            this.writtenCount += this.overflowSize;
            this.overflowSize = 0;
            return;
        }
        this.writer.write(this.overflow, 0, this.limit);
        if (this.limit < this.overflowSize) {
            System.arraycopy(this.overflow, this.limit, this.overflow, 0, this.overflowSize - this.limit);
        }
        this.overflowSize -= this.limit;
        this.writtenCount += this.limit;
        this.limit = 0;
        this.flowController.stopProcessing = true;
    } catch (final IOException e) {
        throw new TemplateOutputException("Exception while trying to write overflowed buffer in throttled template", this.templateName, -1, -1, e);
    }
}
Also used : TemplateOutputException(org.thymeleaf.exceptions.TemplateOutputException) IOException(java.io.IOException)

Aggregations

TemplateOutputException (org.thymeleaf.exceptions.TemplateOutputException)6 IOException (java.io.IOException)4 BigDecimal (java.math.BigDecimal)3 TemplateEngineException (org.thymeleaf.exceptions.TemplateEngineException)3 TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)3 TemplateManager (org.thymeleaf.engine.TemplateManager)2 WritableByteChannel (java.nio.channels.WritableByteChannel)1 CharsetEncoder (java.nio.charset.CharsetEncoder)1