本文整理汇总了Java中org.wiztools.commons.Charsets类的典型用法代码示例。如果您正苦于以下问题:Java Charsets类的具体用法?Java Charsets怎么用?Java Charsets使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Charsets类属于org.wiztools.commons包,在下文中一共展示了Charsets类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.wiztools.commons.Charsets; //导入依赖的package包/类
@Override
public String render(Map<String, Object> config, File templateFile) throws ExecutorException {
try {
final File tmplDir = templateFile.getParentFile();
final String tmplName = Util.getBaseFileName(templateFile.getName());
STGroup stg = new STRawGroupDir(tmplDir.toURI().toURL(),
Charsets.UTF_8.name(),
delimiterStartChar,
delimiterStopChar);
ST st = stg.getInstanceOf(tmplName);
// Populate data:
config.entrySet().stream().forEach((e) -> {
st.add(e.getKey(), e.getValue());
});
return st.render();
}
catch(MalformedURLException ex) {
throw new ExecutorException(ex);
}
}
示例2: process
import org.wiztools.commons.Charsets; //导入依赖的package包/类
private void process(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType(contentType);
resp.setCharacterEncoding(charset);
if(headers != null) {
for(String key: headers.keySet()) {
for(String value: headers.get(key)) {
resp.addHeader(key, value);
}
}
}
resp.setStatus(statusCode);
try(OutputStream os = resp.getOutputStream();) {
if(file != null && file.exists() && file.canRead()) {
try(InputStream is = new FileInputStream(file)) {
try(
final ReadableByteChannel inChannel = Channels.newChannel(is);
final WritableByteChannel outChannel = Channels.newChannel(os);
) {
final ByteBuffer buffer = ByteBuffer.allocate(1000); // 1000 bytes = 1 Kb
while(true) {
// throttle?
if(throttleMillis > 0l) {
try {
Thread.sleep(throttleMillis);
}
catch(InterruptedException ex) {
throw new ServletException(ex);
}
}
// read & write:
int bytesRead = inChannel.read(buffer);
if(bytesRead == -1) break;
buffer.flip();
while(buffer.hasRemaining()) outChannel.write(buffer);
buffer.clear();
}
}
}
}
else {
byte[] out = "<p>Hello World!</p>".getBytes(Charsets.UTF_8);
os.write(out);
}
}
}