本文整理汇总了Java中java.io.PrintWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Java PrintWriter.write方法的具体用法?Java PrintWriter.write怎么用?Java PrintWriter.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PrintWriter
的用法示例。
在下文中一共展示了PrintWriter.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import java.io.PrintWriter; //导入方法依赖的package包/类
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
threadLocal = new ThreadLocal<JSONArray>() {
@Override
protected JSONArray initialValue() {
return new JSONArray();
}
};
loadElements(request);
out.write(threadLocal.get().toString());
} catch (Exception e) {
throw new ServletException(e);
} finally {
out.flush();
threadLocal.remove();
}
}
示例2: writeResponseBody
import java.io.PrintWriter; //导入方法依赖的package包/类
protected void writeResponseBody(HttpServletResponse response, String data, int returnCode, String encoding) {
response.setCharacterEncoding(encoding);
response.setStatus(returnCode);
try {
PrintWriter pw = response.getWriter();
pw.write(data);
pw.flush();
pw.close();
}
catch (IOException e) {
logger.error("BaseGlobalFilterHandler[" + getContext() + "] writes response FAIL.", e);
}
}
示例3: render
import java.io.PrintWriter; //导入方法依赖的package包/类
public void render() {
PrintWriter writer = null;
try {
RenderHelpler.actionCacheExec(text, contentType);
response.setHeader("Pragma", "no-cache"); // HTTP/1.0 caches might not implement Cache-Control and might only implement Pragma: no-cache
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType(contentType);
response.setCharacterEncoding(getEncoding()); // 与 contentType 分开设置
writer = response.getWriter();
writer.write(text);
writer.flush();
} catch (IOException e) {
throw new RenderException(e);
}
}
示例4: writeEdgeViz
import java.io.PrintWriter; //导入方法依赖的package包/类
/** Returns the String representation of an AlloyRelation's settings. */
private static String writeEdgeViz(VizState view, VizState defaultView, AlloyRelation x) throws IOException {
StringWriter sw=new StringWriter();
PrintWriter out=new PrintWriter(sw);
writeDotColor(out, view.edgeColor.get(x), defaultView.edgeColor.get(x));
writeDotStyle(out, view.edgeStyle.get(x), defaultView.edgeStyle.get(x));
writeBool(out, "visible", view.edgeVisible.get(x), defaultView.edgeVisible.get(x));
writeBool(out, "merge", view.mergeArrows.get(x), defaultView.mergeArrows.get(x));
writeBool(out, "layout", view.layoutBack.get(x), defaultView.layoutBack.get(x));
writeBool(out, "attribute", view.attribute.get(x), defaultView.attribute.get(x));
writeBool(out, "constraint",view.constraint.get(x), defaultView.constraint.get(x));
if (view.weight.get(x) != defaultView.weight.get(x)) out.write(" weight=\"" + view.weight.get(x) + "\"");
if (x!=null && !view.label.get(x).equals(defaultView.label.get(x)))
Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
if (out.checkError()) throw new IOException("PrintWriter IO Exception!");
return sw.toString();
}
示例5: releaseMarks
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
* Release mark
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward releaseMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
// get service then update report table
submitFilesService = getSubmitFilesService();
Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID));
submitFilesService.releaseMarksForSession(sessionID);
try {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
SubmitFilesSession session = submitFilesService.getSessionById(sessionID);
String sessionName = "";
if (session != null) {
sessionName = session.getSessionName();
}
out.write(getMessageService().getMessage("msg.mark.released", new String[] { sessionName }));
out.flush();
} catch (IOException e) {
}
return null;
}
示例6: doPost
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
protected void doPost ( final HttpServletRequest request, final HttpServletResponse response ) throws ServletException, IOException
{
if ( request.getPathInfo () == null )
{
send404Error ( request, response );
return;
}
if ( request.getPathInfo ().equals ( "/publish" ) || request.getPathInfo ().equals ( "/publish/" ) )
{
// read input
final BufferedReader reader = request.getReader ();
final char[] buffer = new char[4 * 1024];
int len;
final StringBuilder sb = new StringBuilder ();
while ( ( len = reader.read ( buffer, 0, buffer.length ) ) != -1 )
{
sb.append ( buffer, 0, len );
}
final Event event = EventSerializer.deserializeEvent ( sb.toString () );
this.injector.injectEvent ( event, new InjectionContext.Builder ().sourceModule ( "org.eclipse.scada.ae.server.http" ).build () );
// return output
response.setContentType ( "text/plain" );
final PrintWriter pw = new PrintWriter ( response.getOutputStream () );
pw.write ( "OK" );
pw.close ();
}
else
{
send404Error ( request, response );
}
}
示例7: process
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
* @see SSICommand
*/
public void process(SSIMediator ssiMediator,
String[] paramNames,
String[] paramValues,
PrintWriter writer) {
String configErrMsg = ssiMediator.getConfigErrMsg();
StringBuffer buf = new StringBuffer();
for(int i=0;i<paramNames.length;i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
try {
if ( paramName.equalsIgnoreCase("file") ||
paramName.equalsIgnoreCase("virtual") ) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
long lastModified = ssiMediator.getFileLastModified( paramValue, virtual );
Date date = new Date( lastModified );
String configTimeFmt = ssiMediator.getConfigTimeFmt();
writer.write( formatDate(date, configTimeFmt ) );
} else {
ssiMediator.log("#flastmod--Invalid attribute: " + paramName );
writer.write( configErrMsg );
}
} catch ( IOException e ) {
ssiMediator.log("#flastmod--Couldn't get last modified for file: " + paramValue, e );
writer.write( configErrMsg );
}
}
}
示例8: createUnauthorizedException
import java.io.PrintWriter; //导入方法依赖的package包/类
public static void createUnauthorizedException(final String msg, final ServletResponse res)
throws IOException {
((HttpServletResponse) res).setStatus(401);
((HttpServletResponse) res).setHeader("ContentType", "plain/text");
final PrintWriter writer = ((HttpServletResponse) res).getWriter();
writer.write(msg);
writer.close();
}
示例9: process
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
* @see SSICommand
*/
@Override
public long process(SSIMediator ssiMediator, String commandName,
String[] paramNames, String[] paramValues, PrintWriter writer) {
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
String substitutedValue = ssiMediator
.substituteVariables(paramValue);
try {
if (paramName.equalsIgnoreCase("file")
|| paramName.equalsIgnoreCase("virtual")) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
lastModified = ssiMediator.getFileLastModified(
substitutedValue, virtual);
Date date = new Date(lastModified);
String configTimeFmt = ssiMediator.getConfigTimeFmt();
writer.write(formatDate(date, configTimeFmt));
} else {
ssiMediator.log("#flastmod--Invalid attribute: "
+ paramName);
writer.write(configErrMsg);
}
} catch (IOException e) {
ssiMediator.log(
"#flastmod--Couldn't get last modified for file: "
+ substitutedValue, e);
writer.write(configErrMsg);
}
}
return lastModified;
}
示例10: process
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
* @see SSICommand
*/
@Override
public long process(SSIMediator ssiMediator, String commandName,
String[] paramNames, String[] paramValues, PrintWriter writer) {
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
String substitutedValue = ssiMediator
.substituteVariables(paramValue);
try {
if (paramName.equalsIgnoreCase("file")
|| paramName.equalsIgnoreCase("virtual")) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
lastModified = ssiMediator.getFileLastModified(
substitutedValue, virtual);
long size = ssiMediator.getFileSize(substitutedValue,
virtual);
String configSizeFmt = ssiMediator.getConfigSizeFmt();
writer.write(formatSize(size, configSizeFmt));
} else {
ssiMediator.log("#fsize--Invalid attribute: " + paramName);
writer.write(configErrMsg);
}
} catch (IOException e) {
ssiMediator.log("#fsize--Couldn't get size for file: "
+ substitutedValue, e);
writer.write(configErrMsg);
}
}
return lastModified;
}
示例11: dumpTo
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
* Dump the contents of the buffer to the given stream.
*/
public synchronized void dumpTo(PrintWriter out) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
for (LogMessage msg : messages) {
out.write(df.format(new Date(msg.timestamp)));
out.write(" ");
out.println(new String(msg.message, Charsets.UTF_8));
}
}
示例12: writeStringToFile
import java.io.PrintWriter; //导入方法依赖的package包/类
public static void writeStringToFile(String str, File file) throws FileNotFoundException {
PrintWriter out = new PrintWriter(file);
try {
out.write(str);
} finally {
out.close();
}
}
示例13: print
import java.io.PrintWriter; //导入方法依赖的package包/类
public static void print(DbIterator plan, String fileName) throws IOException {
File f = new File(fileName);
PrintWriter writer = new PrintWriter(f);
String graph = QueryPlanDotter.draw(plan);
writer.write(graph);
writer.close();
}
示例14: writeBool
import java.io.PrintWriter; //导入方法依赖的package包/类
/** Writes nothing if the value is equal to the default value. */
private static void writeBool(PrintWriter out, String key, Boolean value, Boolean defaultValue) throws IOException {
if (value==null && defaultValue==null) return;
if (value!=null && defaultValue!=null && value.booleanValue()==defaultValue.booleanValue()) return;
out.write(' ');
out.write(key);
if (value==null) out.write("=\"inherit\""); else out.write(value ? "=\"yes\"":"=\"no\"");
}
示例15: writeFooter
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
*
*/
public static void writeFooter(PrintWriter writer, int mode) {
if (mode == 0) {
// HTML Tail Section
writer.print(Constants.HTML_TAIL_SECTION);
} else if (mode == 1) {
writer.write("</status>");
}
}