本文整理汇总了Java中java.io.PrintWriter.print方法的典型用法代码示例。如果您正苦于以下问题:Java PrintWriter.print方法的具体用法?Java PrintWriter.print怎么用?Java PrintWriter.print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PrintWriter
的用法示例。
在下文中一共展示了PrintWriter.print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
if (!useChunks) {
// Longer than it needs to be because response will fail before
// it is complete
resp.setContentLength(100);
}
PrintWriter pw = resp.getWriter();
pw.print("line01");
pw.flush();
resp.flushBuffer();
pw.print("line02");
pw.flush();
resp.flushBuffer();
pw.print("line03");
// Now throw a RuntimeException to end this request
throw new ServletException("Deliberate failure");
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:24,代码来源:TestAbstractHttp11Processor.java
示例2: doGet
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain;UTF-8");
PrintWriter out = resp.getWriter();
try {
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/bug50351");
TesterObject to = (TesterObject) obj;
out.print(to.getFoo());
} catch (NamingException ne) {
ne.printStackTrace(out);
}
}
示例3: printThread
import java.io.PrintWriter; //导入方法依赖的package包/类
private static void printThread(ThreadInfo ti, PrintWriter out) {
out.print("\"" + ti.getThreadName() + "\"" + " Id="
+ ti.getThreadId() + " in " + ti.getThreadState());
if (ti.getLockName() != null) {
out.print(" on lock=" + ti.getLockName());
}
if (ti.isSuspended()) {
out.print(" (suspended)");
}
if (ti.isInNative()) {
out.print(" (running in native)");
}
out.println();
if (ti.getLockOwnerName() != null) {
out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id="
+ ti.getLockOwnerId());
}
}
示例4: readBranch
import java.io.PrintWriter; //导入方法依赖的package包/类
private int readBranch (int index, String indent, String name, String disName, TypedefEntry entry, PrintWriter stream)
{
SymtabEntry type = entry.type ();
Util.writeInitializer (indent, '_' + name, "", entry, stream);
if (!entry.arrayInfo ().isEmpty () ||
type instanceof SequenceEntry ||
type instanceof PrimitiveEntry ||
type instanceof StringEntry) {
index = ((JavaGenerator)entry.generator ()).read (index, indent, '_' + name, entry, stream);
} else {
stream.println (indent + '_' + name + " = " + Util.helperName (type, true) + ".read (istream);");
}
stream.print (indent + "value." + name + " (");
if( disName == "" )
stream.println("_" + name + ");");
else
stream.println(disName + ", " + "_" + name + ");");
return index;
}
示例5: testGetClusterNodeLabelsWithLocalAccess
import java.io.PrintWriter; //导入方法依赖的package包/类
@Test
public void testGetClusterNodeLabelsWithLocalAccess() throws Exception {
YarnClient client = mock(YarnClient.class);
when(client.getClusterNodeLabels()).thenReturn(
ImmutableSet.of("remote1", "remote2"));
ClusterCLI cli = new ClusterCLI();
cli.setClient(client);
cli.setSysOutPrintStream(sysOut);
cli.setSysErrPrintStream(sysErr);
ClusterCLI.localNodeLabelsManager = mock(CommonNodeLabelsManager.class);
when(ClusterCLI.localNodeLabelsManager.getClusterNodeLabels())
.thenReturn(ImmutableSet.of("local1", "local2"));
int rc =
cli.run(new String[] { ClusterCLI.CMD,
"-" + ClusterCLI.LIST_LABELS_CMD,
"-" + ClusterCLI.DIRECTLY_ACCESS_NODE_LABEL_STORE });
assertEquals(0, rc);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
// it should return local* instead of remote*
pw.print("Node Labels: local1,local2");
pw.close();
verify(sysOut).println(baos.toString("UTF-8"));
}
示例6: dumpConf
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
public void dumpConf(PrintWriter pwriter) {
super.dumpConf(pwriter);
pwriter.print("initLimit=");
pwriter.println(self.getInitLimit());
pwriter.print("syncLimit=");
pwriter.println(self.getSyncLimit());
pwriter.print("electionAlg=");
pwriter.println(self.getElectionType());
pwriter.print("electionPort=");
pwriter.println(self.getElectionAddress().getPort());
pwriter.print("quorumPort=");
pwriter.println(self.getQuorumAddress().getPort());
pwriter.print("peerType=");
pwriter.println(self.getLearnerType().ordinal());
}
示例7: dumpViewHierarchy
import java.io.PrintWriter; //导入方法依赖的package包/类
private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) {
writer.print(prefix);
if (view == null) {
writer.println("null");
return;
}
writer.println(viewToString(view));
if (view instanceof ViewGroup) {
ViewGroup grp = (ViewGroup) view;
int N = grp.getChildCount();
if (N > 0) {
prefix = prefix + " ";
for (int i = 0; i < N; i++) {
dumpViewHierarchy(prefix, writer, grp.getChildAt(i));
}
}
}
}
示例8: createJavaFile
import java.io.PrintWriter; //导入方法依赖的package包/类
private FileObject createJavaFile (
final FileObject root,
final String pkg,
final String name,
final String content) throws IOException {
final FileObject file = FileUtil.createData(
root,
String.format("%s/%s.java",
FileObjects.convertPackage2Folder(pkg),
name));
final FileLock lck = file.lock();
try {
final PrintWriter out = new PrintWriter (new OutputStreamWriter(file.getOutputStream(lck)));
try {
out.print(content);
} finally {
out.close();
}
} finally {
lck.releaseLock();
}
return file;
}
示例9: doPost
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String rawContent = IOUtils.toString(request.getReader());
log.debug(String.format("request content: %s", rawContent));
out.print(goodsDAO.findById(1));
}
示例10: showConfigurations
import java.io.PrintWriter; //导入方法依赖的package包/类
private void showConfigurations ( final HttpServletResponse resp, final ConfigurationAdministrator admin, final String factoryId, final Configuration[] configurations ) throws IOException
{
final PrintWriter stream = resp.getWriter ();
stream.print ( "<table class='configuration' width='100%'>" );
stream.print ( "<tr><th>ID</th><th>State</th><th>Error</th><th>Data</th></tr>" );
Arrays.sort ( configurations, new Comparator<Configuration> () {
@Override
public int compare ( final Configuration o1, final Configuration o2 )
{
return o1.getId ().compareTo ( o2.getId () );
}
} );
for ( final Configuration cfg : configurations )
{
stream.print ( "<tr>" );
stream.print ( String.format ( "<td>%s</td>", cfg.getId () ) );
stream.print ( String.format ( "<td>%s</td>", cfg.getState () ) );
if ( cfg.getErrorInformation () != null )
{
stream.print ( String.format ( "<td>%s</td>", cfg.getErrorInformation ().getMessage () ) );
}
else
{
stream.print ( String.format ( "<td></td>" ) );
}
stream.print ( "<td><div style='float:right;'>" );
showData ( stream, cfg.getData (), factoryId, cfg.getId () );
stream.print ( "<form method='post'><input type='Submit' value='Delete' name='cmd_delete' /><input type='hidden' name='factoryId' value='" + factoryId + "' /><input type='hidden' name='configurationId' value=" + cfg.getId () + " /></form>" );
stream.print ( "</div></td>" );
stream.print ( "</tr>" );
}
stream.print ( "</table>" );
}
示例11: doGet
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
PrintWriter out = res.getWriter();
out.print("<p>" + getInitParameter("foo") + " "
+ getInitParameter("bar") + "</p>");
}
示例12: dump
import java.io.PrintWriter; //导入方法依赖的package包/类
void dump(PrintWriter stream) {
stream.print("[size=" + count);
for (int i = 0; i < count; i++) {
if (i != 0) {
stream.print(", ");
stream.print(timeStamps[i] - timeStamps[i - 1]);
} else {
stream.print(" " + timeStamps[i]);
}
}
stream.println("]");
}
示例13: doGet
import java.io.PrintWriter; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
// 调用service
LoginService service = new LoginServiceImpl();
MD5 md5 = new MD5();
// 获得姓名
String loginName = request.getParameter("loginName");
String loginPwd = request.getParameter("loginPwd"); //转成MD5存储
Login login;
int check = -1;
try {
login = service.queryLogin(loginName);
System.out.println(login);
login.setLoginPwd(loginPwd);
System.out.println(login);
check = service.updateLogin(login);
System.out.println(check);
System.out.println(service.queryLogin(loginName));
} catch (SQLException e) {
e.printStackTrace();
}
Gson gson = new Gson();
out.print(gson.toJson(check));
}
示例14: handle
import java.io.PrintWriter; //导入方法依赖的package包/类
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException
{
String scriptName = request.getPathInfo();
scriptName = LocalUtil.replace(scriptName, testHandlerUrl, "");
scriptName = LocalUtil.replace(scriptName, "/", "");
String page = debugPageGenerator.generateTestPage(request.getContextPath() + request.getServletPath(), scriptName);
response.setContentType(MimeConstants.MIME_HTML);
PrintWriter out = response.getWriter();
out.print(page);
}
示例15: getFailureText
import java.io.PrintWriter; //导入方法依赖的package包/类
private static String getFailureText(final Object orig, final Object copy) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
pw.println("Test FAILED: Deserialized object is not equal to the original object");
pw.print("\tOriginal: ");
printObject(pw, orig).println();
pw.print("\tCopy: ");
printObject(pw, copy).println();
pw.close();
return sw.toString();
}