Java Code Examples for java.io.PrintWriter.println()

The following are Jave code examples for showing how to use println() of the java.io.PrintWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: ValueBoxGen.java   View Source Code Vote up 7 votes
protected void streamableRead (String entryName, SymtabEntry entry, PrintWriter stream)
{
  Vector vMembers = ( (ValueBoxEntry) entry ).state ();
  TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry;
  SymtabEntry mType = member.type ();
  if (mType instanceof PrimitiveEntry || mType instanceof SequenceEntry || mType instanceof TypedefEntry ||
      mType instanceof StringEntry || !member.arrayInfo ().isEmpty ())
  {
    SymtabEntry mEntry = (SymtabEntry) ((InterfaceState) vMembers.elementAt (0)).entry;
    ((JavaGenerator)member.generator ()).read (0, "    ", entryName + ".value", member, stream);
  }
  else if (mType instanceof ValueEntry || mType instanceof ValueBoxEntry)
    stream.println ("    " + entryName + ".value = (" + Util.javaQualifiedName (mType) + ") ((org.omg.CORBA_2_3.portable.InputStream)istream).read_value (" + Util.helperName(mType, true) + ".get_instance ());"); // <d60929> // <d61056>
  else
    stream.println ("    " + entryName + ".value = " + Util.helperName (mType, true) + ".read (istream);"); // <d61056>
}
 
Example 2
Project: ditb   File: TimedOutTestsListener.java   View Source Code Vote up 7 votes
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());
  }
}
 
Example 3
Project: jerrydog   File: ManagerServlet.java   View Source Code Vote up 6 votes
/**
 * Remove the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param path Context path of the application to be removed
 */
protected void remove(PrintWriter writer, String path) {

    if (debug >= 1)
        log("remove: Removing web application at '" + path + "'");

    if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
        writer.println(sm.getString("managerServlet.invalidPath", path));
        return;
    }
    String displayPath = path;
    if( path.equals("/") )
        path = "";

    try {
        Context context = deployer.findDeployedApp(path);
        if (context == null) {
            writer.println(sm.getString("managerServlet.noContext", displayPath));
            return;
        }
        // It isn't possible for the manager to remove itself
        if (context.getPath().equals(this.context.getPath())) {
            writer.println(sm.getString("managerServlet.noSelf"));
            return;
        }
        deployer.remove(path);
        writer.println(sm.getString("managerServlet.removed", displayPath));
    } catch (Throwable t) {
        log("ManagerServlet.remove[" + displayPath + "]", t);
        writer.println(sm.getString("managerServlet.exception",
                                    t.toString()));
    }

}
 
Example 4
Project: dubbocloud   File: IOUtils.java   View Source Code Vote up 6 votes
/**
 * write lines.
 * 
 * @param os output stream.
 * @param lines lines.
 * @throws IOException
 */
public static void writeLines(OutputStream os, String[] lines) throws IOException
{
	PrintWriter writer = new PrintWriter(new OutputStreamWriter(os));
	try
	{
		for( String line : lines )
			writer.println(line);
		writer.flush();
	}
	finally
	{
		writer.close();
	}
}
 
Example 5
Project: FJ-VDMJ   File: DBGPReader.java   View Source Code Vote up 6 votes
private void processStack(DBGPCommand c) throws IOException, DBGPException
{
	if ((status != DBGPStatus.BREAK && status != DBGPStatus.STOPPING)
		|| breakpoint == null)
	{
		throw new DBGPException(DBGPErrorCode.NOT_AVAILABLE, c.toString());
	}

	OutputStream out = new ByteArrayOutputStream();
	PrintWriter pw = new PrintWriter(out);
	pw.println("Stopped [" + Thread.currentThread().getName() + "] " + breakpoint.location);
	breakContext.printStackTrace(pw, true);
	pw.close();
	cdataResponse(out.toString());
}
 
Example 6
Project: openjdk-jdk10   File: GetObjectSizeOverflow.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws Exception  {

        if (!Platform.is64bit()) {
            System.out.println("Test needs a 4GB heap and can only be run as a 64bit process, skipping.");
            return;
        }

        PrintWriter pw = new PrintWriter("MANIFEST.MF");
        pw.println("Premain-Class: GetObjectSizeOverflowAgent");
        pw.close();

        ProcessBuilder pb = new ProcessBuilder();
        pb.command(new String[] { JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF", "agent.jar", "GetObjectSizeOverflowAgent.class"});
        pb.start().waitFor();

        ProcessBuilder pt = ProcessTools.createJavaProcessBuilder(true, "-Xmx4000m", "-javaagent:agent.jar",  "GetObjectSizeOverflowAgent");
        OutputAnalyzer output = new OutputAnalyzer(pt.start());

        if (output.getStdout().contains("Could not reserve enough space") || output.getStderr().contains("java.lang.OutOfMemoryError")) {
            System.out.println("stdout: " + output.getStdout());
            System.out.println("stderr: " + output.getStderr());
            System.out.println("Test could not reserve or allocate enough space, skipping");
            return;
        }

        output.stdoutShouldContain("GetObjectSizeOverflow passed");
    }
 
Example 7
Project: ProgressManager   File: a.java   View Source Code Vote up 6 votes
void dumpInner(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    writer.print(prefix); writer.print("Local Activity ");
    writer.print(Integer.toHexString(System.identityHashCode(this)));
    writer.println(" State:");
    String innerPrefix = prefix + "  ";
    writer.print(innerPrefix); writer.print("mResumed=");
    writer.print(mResumed); writer.print(" mStopped=");
    writer.print(mStopped); writer.print(" mFinished=");
    writer.println(mFinished);
    writer.print(innerPrefix); writer.print("mChangingConfigurations=");
    writer.println(mChangingConfigurations);
    writer.print(innerPrefix); writer.print("mCurrentConfig=");
    writer.println(mCurrentConfig);

    mFragments.dumpLoaders(innerPrefix, fd, writer, args);
    mFragments.getFragmentManager().dump(innerPrefix, fd, writer, args);
    if (mVoiceInteractor != null) {
        mVoiceInteractor.dump(innerPrefix, fd, writer, args);
    }

    if (getWindow() != null &&
            getWindow().peekDecorView() != null &&
            getWindow().peekDecorView().getViewRootImpl() != null) {
        getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args);
    }

    mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix);
}
 
Example 8
Project: pathological-reports   File: CustomBasicAuthenticationEntryPoint.java   View Source Code Vote up 6 votes
@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException {

	// Authentication failed, send error response.
	response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
	response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName() + "");

	PrintWriter writer = response.getWriter();
	writer.println("HTTP Status 401 : " + authException.getMessage());
}
 
Example 9
Project: Servlet_Applet_Communication   File: LoginServlet.java   View Source Code Vote up 6 votes
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();

    String uname = request.getParameter("uname");
       String upwd = request.getParameter("upwd");

    if(uname.equals("root") && upwd.equals("root")) {
        out.println("Login Success"); 
        }else {
      out.println("Login Failure");
    }
}
 
Example 10
Project: openjdk-jdk10   File: CodeGenerator.java   View Source Code Vote up 6 votes
/**
 * Debug code used to print symbols
 *
 * @param block the block we are in
 * @param function the function we are in
 * @param ident identifier for block or function where applicable
 */
private void printSymbols(final Block block, final FunctionNode function, final String ident) {
    if (compiler.getScriptEnvironment()._print_symbols || function.getDebugFlag(FunctionNode.DEBUG_PRINT_SYMBOLS)) {
        final PrintWriter out = compiler.getScriptEnvironment().getErr();
        out.println("[BLOCK in '" + ident + "']");
        if (!block.printSymbols(out)) {
            out.println("<no symbols>");
        }
        out.println();
    }
}
 
Example 11
Project: tomcat7   File: ChatServlet.java   View Source Code Vote up 6 votes
protected void end(CometEvent event, HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    log("End for session: " + request.getSession(true).getId());
    synchronized(connections) {
        connections.remove(response);
    }
    
    PrintWriter writer = response.getWriter();
    writer.println("</body></html>");
    
    event.close();
}
 
Example 12
Project: OpenJSharp   File: XPathException.java   View Source Code Vote up 6 votes
/**
 * <p>Print stack trace to specified <code>PrintWriter</code>.</p>
 *
 * @param s Print stack trace to this <code>PrintWriter</code>.
 */
public void printStackTrace(PrintWriter s) {

    if (getCause() != null) {
        getCause().printStackTrace(s);
      s.println("--------------- linked to ------------------");
    }

    super.printStackTrace(s);
}
 
Example 13
Project: parabuild-ci   File: Server.java   View Source Code Vote up 6 votes
/**
 * Prints the specified message, s, formatted to identify that the print
 * operation is against this server instance.
 *
 * @param msg The message to print
 */
protected void print(String msg) {

    PrintWriter writer = logWriter;

    if (writer != null) {
        writer.println("[" + serverId + "]: " + msg);
        writer.flush();
    }
}
 
Example 14
Project: hepek-classycle   File: Analyser.java   View Source Code Vote up 6 votes
/**
 * Prints for each class a raw output into the specified writer. This output includes all classes used by the class.
 *
 * @param writer
 *            Output stream.
 */
public void printRaw(PrintWriter writer) {
    final AtomicVertex[] graph = getClassGraph();
    for (int i = 0; i < graph.length; i++) {
        final AtomicVertex vertex = graph[i];
        writer.println(vertex.getAttributes());
        for (int j = 0, n = vertex.getNumberOfOutgoingArcs(); j < n; j++) {
            writer.println("    " + vertex.getHeadVertex(j).getAttributes());
        }
    }
    writer.close();
}
 
Example 15
Project: hadoop   File: TestFairScheduler.java   View Source Code Vote up 5 votes
@Test
public void testMaxRunningAppsHierarchicalQueues() throws Exception {
  conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE);
  MockClock clock = new MockClock();
  scheduler.setClock(clock);

  PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
  out.println("<?xml version=\"1.0\"?>");
  out.println("<allocations>");
  out.println("<queue name=\"queue1\">");
  out.println("  <maxRunningApps>3</maxRunningApps>");
  out.println("  <queue name=\"sub1\"></queue>");
  out.println("  <queue name=\"sub2\"></queue>");
  out.println("  <queue name=\"sub3\">");
  out.println("    <maxRunningApps>1</maxRunningApps>");
  out.println("  </queue>");
  out.println("</queue>");
  out.println("</allocations>");
  out.close();

  scheduler.init(conf);
  scheduler.start();
  scheduler.reinitialize(conf, resourceManager.getRMContext());

  // exceeds no limits
  ApplicationAttemptId attId1 = createSchedulingRequest(1024, "queue1.sub1", "user1");
  verifyAppRunnable(attId1, true);
  verifyQueueNumRunnable("queue1.sub1", 1, 0);
  clock.tick(10);
  // exceeds no limits
  ApplicationAttemptId attId2 = createSchedulingRequest(1024, "queue1.sub3", "user1");
  verifyAppRunnable(attId2, true);
  verifyQueueNumRunnable("queue1.sub3", 1, 0);
  clock.tick(10);
  // exceeds no limits
  ApplicationAttemptId attId3 = createSchedulingRequest(1024, "queue1.sub2", "user1");
  verifyAppRunnable(attId3, true);
  verifyQueueNumRunnable("queue1.sub2", 1, 0);
  clock.tick(10);
  // exceeds queue1 limit
  ApplicationAttemptId attId4 = createSchedulingRequest(1024, "queue1.sub2", "user1");
  verifyAppRunnable(attId4, false);
  verifyQueueNumRunnable("queue1.sub2", 1, 1);
  clock.tick(10);
  // exceeds sub3 limit
  ApplicationAttemptId attId5 = createSchedulingRequest(1024, "queue1.sub3", "user1");
  verifyAppRunnable(attId5, false);
  verifyQueueNumRunnable("queue1.sub3", 1, 1);
  clock.tick(10);
  
  // Even though the app was removed from sub3, the app from sub2 gets to go
  // because it came in first
  AppAttemptRemovedSchedulerEvent appRemovedEvent1 =
      new AppAttemptRemovedSchedulerEvent(attId2, RMAppAttemptState.FINISHED, false);
  scheduler.handle(appRemovedEvent1);
  verifyAppRunnable(attId4, true);
  verifyQueueNumRunnable("queue1.sub2", 2, 0);
  verifyAppRunnable(attId5, false);
  verifyQueueNumRunnable("queue1.sub3", 0, 1);

  // Now test removal of a non-runnable app
  AppAttemptRemovedSchedulerEvent appRemovedEvent2 =
      new AppAttemptRemovedSchedulerEvent(attId5, RMAppAttemptState.KILLED, true);
  scheduler.handle(appRemovedEvent2);
  assertEquals(0, scheduler.maxRunningEnforcer.usersNonRunnableApps
      .get("user1").size());
  // verify app gone in queue accounting
  verifyQueueNumRunnable("queue1.sub3", 0, 0);
  // verify it doesn't become runnable when there would be space for it
  AppAttemptRemovedSchedulerEvent appRemovedEvent3 =
      new AppAttemptRemovedSchedulerEvent(attId4, RMAppAttemptState.FINISHED, true);
  scheduler.handle(appRemovedEvent3);
  verifyQueueNumRunnable("queue1.sub2", 1, 0);
  verifyQueueNumRunnable("queue1.sub3", 0, 0);
}
 
Example 16
Project: monarch   File: RestoreScript.java   View Source Code Vote up 5 votes
public void writeCopyFile(PrintWriter writer, File backup, File original) {
  writer.println("cp -p '" + backup + "' '" + original + "'");
}
 
Example 17
Project: com.zsmartsystems.zigbee   File: ClassGenerator.java   View Source Code Vote up 5 votes
protected void outputImports(final PrintWriter out) {
    Collections.sort(importList);
    for (final String importClass : importList) {
        out.println("import " + importClass + ";");
    }
}
 
Example 18
Project: hadoop   File: TestFairScheduler.java   View Source Code Vote up 5 votes
@Test (timeout = 500000)
public void testContainerReservationAttemptExceedingQueueMax()
    throws Exception {
  conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE);
  PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
  out.println("<?xml version=\"1.0\"?>");
  out.println("<allocations>");
  out.println("<queue name=\"root\">");
  out.println("<queue name=\"queue1\">");
  out.println("<maxResources>2048mb,5vcores,5gcores</maxResources>");
  out.println("</queue>");
  out.println("<queue name=\"queue2\">");
  out.println("<maxResources>2048mb,10vcores,10gcores</maxResources>");
  out.println("</queue>");
  out.println("</queue>");
  out.println("</allocations>");
  out.close();

  scheduler.init(conf);
  scheduler.start();
  scheduler.reinitialize(conf, resourceManager.getRMContext());

  // Add a node
  RMNode node1 =
      MockNodes
          .newNodeInfo(1, Resources.createResource(3072, 5, 5), 1, "127.0.0.1");
  NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);
  scheduler.handle(nodeEvent1);

  // Queue 1 requests full capacity of the queue
  createSchedulingRequest(2048, "queue1", "user1", 1);
  scheduler.update();
  NodeUpdateSchedulerEvent updateEvent = new NodeUpdateSchedulerEvent(node1);
  scheduler.handle(updateEvent);

  // Make sure queue 1 is allocated app capacity
  assertEquals(2048, scheduler.getQueueManager().getQueue("queue1").
      getResourceUsage().getMemory());

  // Now queue 2 requests likewise
  createSchedulingRequest(1024, "queue2", "user2", 1);
  scheduler.update();
  scheduler.handle(updateEvent);

  // Make sure queue 2 is allocated app capacity
  assertEquals(1024, scheduler.getQueueManager().getQueue("queue2").
      getResourceUsage().getMemory());

  ApplicationAttemptId attId1 = createSchedulingRequest(1024, "queue1", "user1", 1);
  scheduler.update();
  scheduler.handle(updateEvent);

  // Ensure the reservation does not get created as allocated memory of
  // queue1 exceeds max
  assertEquals(0, scheduler.getSchedulerApp(attId1).
      getCurrentReservation().getMemory());
}
 
Example 19
Project: OpenJSharp   File: JNI.java   View Source Code Vote up 5 votes
public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
        PrintWriter pw = wrapWriter(o);
        pw.println(guardBegin(cname));
        pw.println(cppGuardBegin());

        /* Write statics. */
        List<VariableElement> classfields = getAllFields(clazz);

        for (VariableElement v: classfields) {
            if (!v.getModifiers().contains(Modifier.STATIC))
                continue;
            String s = null;
            s = defineForStatic(clazz, v);
            if (s != null) {
                pw.println(s);
            }
        }

        /* Write methods. */
        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        for (ExecutableElement md: classmethods) {
            if(md.getModifiers().contains(Modifier.NATIVE)){
                TypeMirror mtr = types.erasure(md.getReturnType());
                String sig = signature(md);
                TypeSignature newtypesig = new TypeSignature(elems);
                CharSequence methodName = md.getSimpleName();
                boolean longName = false;
                for (ExecutableElement md2: classmethods) {
                    if ((md2 != md)
                        && (methodName.equals(md2.getSimpleName()))
                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                        longName = true;

                }
                pw.println("/*");
                pw.println(" * Class:     " + cname);
                pw.println(" * Method:    " +
                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                pw.println(" */");
                pw.println("JNIEXPORT " + jniType(mtr) +
                           " JNICALL " +
                           mangler.mangleMethod(md, clazz,
                                               (longName) ?
                                               Mangle.Type.METHOD_JNI_LONG :
                                               Mangle.Type.METHOD_JNI_SHORT));
                pw.print("  (JNIEnv *, ");
                List<? extends VariableElement> paramargs = md.getParameters();
                List<TypeMirror> args = new ArrayList<TypeMirror>();
                for (VariableElement p: paramargs) {
                    args.add(types.erasure(p.asType()));
                }
                if (md.getModifiers().contains(Modifier.STATIC))
                    pw.print("jclass");
                else
                    pw.print("jobject");

                for (TypeMirror arg: args) {
                    pw.print(", ");
                    pw.print(jniType(arg));
                }
                pw.println(");" + lineSep);
            }
        }
        pw.println(cppGuardEnd());
        pw.println(guardEnd(cname));
    } catch (TypeSignature.SignatureException e) {
        util.error("jni.sigerror", e.getMessage());
    }
}
 
Example 20
Project: TextHIN   File: Utils.java   View Source Code Vote up 5 votes
public static void writeTriple(PrintWriter out, String arg1, String property, String arg2) {
  out.println(arg1 + "\t" + property + "\t" + arg2 + ".");
}