Scalate模板大小限制为64k?

时间:2016-07-21 23:28:54

标签: scalate ssp

尝试包含一堆HTML是一个SSP模板,我有以下例外:

Caused by: java.lang.IllegalArgumentException: null
at scala.tools.asm.ByteVector.putUTF8(ByteVector.java:213)
at scala.tools.asm.ClassWriter.newUTF8(ClassWriter.java:1092)
at scala.tools.asm.ClassWriter.newString(ClassWriter.java:1525)
at scala.tools.asm.ClassWriter.newConstItem(ClassWriter.java:1042)
at scala.tools.asm.MethodWriter.visitLdcInsn(MethodWriter.java:1134)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genConstant(GenASM.scala:1582)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.scala$tools$nsc$backend$jvm$GenASM$JPlainBuilder$$genInstr$1(GenASM.scala:2296)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2227)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2213)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.foreach(BasicBlocks.scala:195)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlock$1(GenASM.scala:2213)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlocks$1(GenASM.scala:2151)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genCode(GenASM.scala:2746)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genMethod(GenASM.scala:1471)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1341)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.emitFor$1(GenASM.scala:198)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:204)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1501)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1486)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1481)
at scala.tools.nsc.Global$Run.compile(Global.scala:1582)
at org.fusesource.scalate.support.ScalaCompiler.compile(ScalaCompiler.scala:100)
at org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:757)

查看scala.tools.asm.ByteVector我发现了以下内容:

    public ByteVector putUTF8(String s) {
    int charLength = s.length();
    if(charLength > '\uffff') {
        throw new IllegalArgumentException();
    } else { ....

如果模板大小超过65536字节,则无法编译此模板。要将大量纯HTML格式包含在SSP模板中,需要做些什么? Include似乎只适用于模板文件。我应该在模板中手动加载和输出html文件吗?有没有更好的方法?

1 个答案:

答案 0 :(得分:2)

这似乎是一个固有的限制。

解决方法:手动读取文件并将其输出到模板中 (是的,它很难看,但有效):

<% include("header.ssp") %>

<%@ val book:Integer %>

<% val bookHtml = "./public/books/" + "book_" + book + ".html"%>
<% val source = scala.io.Source.fromFile(bookHtml)
val lines = try source.mkString finally source.close()
%>

${unescape(lines)}

<% include("footer.ssp") %>