use of org.mvel2.templates.TemplateError in project mvel by mikebrock.
the class TemplateTools method readInFile.
public static String readInFile(File file) {
try {
FileChannel fc = new FileInputStream(file).getChannel();
ByteBuffer buf = allocateDirect(10);
StringBuilder appender = new StringBuilder();
int read;
while (true) {
buf.rewind();
if ((read = fc.read(buf)) != -1) {
buf.rewind();
for (; read != 0; read--) {
appender.append((char) buf.get());
}
} else {
break;
}
}
fc.close();
return appender.toString();
} catch (FileNotFoundException e) {
throw new TemplateError("cannot include template '" + file.getName() + "': file not found.");
} catch (IOException e) {
throw new TemplateError("unknown I/O exception while including '" + file.getName() + "' (stacktrace nested)", e);
}
}
use of org.mvel2.templates.TemplateError in project mvel by mvel.
the class IncludeNode method readInFile.
public static String readInFile(TemplateRuntime runtime, String fileName) {
File file = new File(String.valueOf(runtime.getRelPath().peek()) + "/" + fileName);
try {
FileInputStream instream = new FileInputStream(file);
BufferedInputStream bufstream = new BufferedInputStream(instream);
runtime.getRelPath().push(file.getParent());
byte[] buf = new byte[10];
int read;
int i;
StringBuilder appender = new StringBuilder();
while ((read = bufstream.read(buf)) != -1) {
for (i = 0; i < read; i++) {
appender.append((char) buf[i]);
}
}
bufstream.close();
instream.close();
runtime.getRelPath().pop();
return appender.toString();
} catch (FileNotFoundException e) {
throw new TemplateError("cannot include template '" + fileName + "': file not found.");
} catch (IOException e) {
throw new TemplateError("unknown I/O exception while including '" + fileName + "' (stacktrace nested)", e);
}
}
Aggregations