本文整理了Java中java.io.PrintWriter.write()
方法的一些代码示例,展示了PrintWriter.write()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintWriter.write()
方法的具体详情如下:
包路径:java.io.PrintWriter
类名称:PrintWriter
方法名:write
[英]Writes one character to the target. Only the two least significant bytes of the integer oneChar are written.
This writer's error flag is set to true if this writer is closed or an I/O error occurs.
[中]将一个字符写入目标。只写入整数oneChar的两个最低有效字节。
如果此写入程序已关闭或发生I/O错误,则此写入程序的错误标志将设置为true。
代码示例来源:origin: spring-projects/spring-framework
@Override
public void write(char[] buf, int off, int len) {
super.write(buf, off, len);
super.flush();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Assert.state(this.liveBeansView != null, "No LiveBeansView available");
String content = this.liveBeansView.getSnapshotAsJson();
response.setContentType("application/json");
response.setContentLength(content.length());
response.getWriter().write(content);
}
代码示例来源:origin: gocd/gocd
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter writer = response.getWriter();
writer.write(content);
writer.close();
}
代码示例来源:origin: gocd/gocd
public ModelAndView respond(HttpServletResponse response) throws Exception {
response.setStatus(status);
response.setContentType(contentType);
response.getWriter().write(message);
return null;
}
}
代码示例来源:origin: redwarp/9-Patch-Resizer
@Override
protected Void doInBackground() throws Exception {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(DENSITIES_PATHNAME);
PrintWriter writer = new PrintWriter(fos);
writer.write(mSavePayload);
writer.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Couldn't save");
}
return null;
}
代码示例来源:origin: apache/hbase
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(HRegionServer.REGIONSERVER);
assert hrs != null : "No RS in context!";
resp.setContentType("text/html");
if (!hrs.isOnline()) {
resp.getWriter().write("The RegionServer is initializing!");
resp.getWriter().close();
return;
}
RSStatusTmpl tmpl = new RSStatusTmpl();
if (req.getParameter("format") != null)
tmpl.setFormat(req.getParameter("format"));
if (req.getParameter("filter") != null)
tmpl.setFilter(req.getParameter("filter"));
if (req.getParameter("bcn") != null)
tmpl.setBcn(req.getParameter("bcn"));
if (req.getParameter("bcv") != null)
tmpl.setBcv(req.getParameter("bcv"));
tmpl.render(resp.getWriter(), hrs);
}
}
代码示例来源:origin: apache/hive
@Override
public void saveField(Type type, String id, String key, String val)
throws NotFoundException {
if (val == null) {
return;
}
PrintWriter out = null;
//todo: FileSystem#setPermission() - should this make sure to set 777 on jobs/ ?
Path keyfile= new Path(getPath(type) + "/" + id + "/" + key);
try {
// This will replace the old value if there is one
// Overwrite the existing file
out = new PrintWriter(new OutputStreamWriter(fs.create(keyfile)));
out.write(val);
out.flush();
} catch (Exception e) {
String errMsg = "Couldn't write to " + keyfile + ": " + e.getMessage();
LOG.error(errMsg, e);
throw new NotFoundException(errMsg, e);
} finally {
close(out);
}
}
代码示例来源:origin: org.mockito/mockito-core
/**
* Writes text to file
*/
public static void writeText(String text, File output) {
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileWriter(output));
pw.write(text);
} catch (Exception e) {
throw new MockitoException("Problems writing text to file: " + output, e);
} finally {
close(pw);
}
}
代码示例来源:origin: sd4324530/fastweixin
/**
* 绑定服务器的方法
* @param request 请求
* @param response 响应
*/
public void bindServer(HttpServletRequest request, HttpServletResponse response) {
if (isLegal(request)) {
try {
PrintWriter pw = response.getWriter();
pw.write(request.getParameter("echostr"));
pw.flush();
pw.close();
} catch (Exception e) {
LOG.error("绑定服务器异常", e);
}
}
}
代码示例来源:origin: javaee-samples/javaee7-samples
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().write("Public resource invoked\n");
if (request.getParameter("doLogout") != null) {
request.logout();
}
}
代码示例来源:origin: spring-projects/spring-framework
@RequestMapping(method = {RequestMethod.POST, RequestMethod.GET}, params = "surprise")
public void mySurpriseHandle(HttpServletResponse response) throws IOException {
response.getWriter().write("mySurpriseView");
}
}
代码示例来源:origin: jenkinsci/gitlab-plugin
private void writeBody(StaplerResponse response, JSONObject body) throws IOException {
response.setContentType("application/json");
PrintWriter writer = response.getWriter();
writer.write(body.toString());
writer.flush();
writer.close();
}
}
代码示例来源:origin: javamelody/javamelody
public static void showAlertAndRedirectTo(HttpServletResponse resp, String message,
String redirectTo) throws IOException {
final PrintWriter writer = createWriterFromOutputStream(resp);
writer.write("<script type='text/javascript'>alert('");
writer.write(I18N.javascriptEncode(message));
writer.write("');location.href='");
writer.write(redirectTo);
writer.write("';</script>");
writer.close();
}
代码示例来源:origin: lihengming/spring-boot-api-project-seed
private void responseResult(HttpServletResponse response, Result result) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(200);
try {
response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) {
logger.error(ex.getMessage());
}
}
代码示例来源:origin: gocd/gocd
public ModelAndView respond(HttpServletResponse response) throws Exception {
response.setStatus(status);
response.setContentType(contentType);
response.setHeader("Content-Disposition", "Inline; filename=" + jobName + "Properties.csv");
response.getWriter().write(message);
return null;
}
}
代码示例来源:origin: FudanNLP/fnlp
public void eval2File(AbstractClassifier cl,String path){
PrintWriter pw;
try {
pw = new PrintWriter(path, "utf8");
String s = eval(cl);
pw.write(s);
pw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
代码示例来源:origin: DeemOpen/zkui
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
logger.debug("Export Get Action!");
try {
Properties globalProps = (Properties) this.getServletContext().getAttribute("globalProps");
String zkServer = globalProps.getProperty("zkServer");
String[] zkServerLst = zkServer.split(",");
String authRole = (String) request.getSession().getAttribute("authRole");
if (authRole == null) {
authRole = ZooKeeperUtil.ROLE_USER;
}
String zkPath = request.getParameter("zkPath");
StringBuilder output = new StringBuilder();
output.append("#App Config Dashboard (ACD) dump created on :").append(new Date()).append("\n");
Set<LeafBean> leaves = ZooKeeperUtil.INSTANCE.exportTree(zkPath, ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0], globalProps), authRole);
for (LeafBean leaf : leaves) {
output.append(leaf.getPath()).append('=').append(leaf.getName()).append('=').append(ServletUtil.INSTANCE.externalizeNodeValue(leaf.getValue())).append('\n');
}// for all leaves
response.setContentType("text/plain;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.write(output.toString());
}
} catch (InterruptedException | KeeperException ex) {
logger.error(Arrays.toString(ex.getStackTrace()));
ServletUtil.INSTANCE.renderError(request, response, ex.getMessage());
}
}
}
代码示例来源:origin: stackoverflow.com
PrintWriter out = new PrintWriter(socket.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.write("HTTP/1.1 101 Switching Protocols\r\n"
+ "Upgrade: websocket\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: " + hash + "\r\n"
+ "\r\n");
out.flush();
代码示例来源:origin: jooby-project/jooby
private void writeFile(File output, String chunk) throws IOException {
if (!output.getParentFile().exists()) {
final boolean mkdirsResult = output.getParentFile().mkdirs();
if (!mkdirsResult) {
throw new IOException("Directory " + output.getCanonicalPath() + " could not be created!");
}
}
try (PrintWriter writer = new PrintWriter(output, "UTF-8")) {
writer.write(chunk);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void write(char[] buf, int off, int len) {
super.write(buf, off, len);
super.flush();
setCommittedIfBufferSizeExceeded();
}
内容来源于网络,如有侵权,请联系作者删除!