Java Code Examples for java.io.PrintWriter#print()
The following examples show how to use
java.io.PrintWriter#print() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodGenClone24.java From openjdk-8-source with GNU General Public License v2.0 | 8 votes |
/** * <d62023> - delete method templates for valuetypes **/ protected void interfaceMethod (Hashtable symbolTable, MethodEntry m, PrintWriter stream) { this.symbolTable = symbolTable; this.m = m; this.stream = stream; if (m.comment () != null) m.comment ().generate (" ", stream); stream.print (" "); writeMethodSignature (); stream.println (";"); }
Example 2
Source File: StringUtils.java From dubbox with Apache License 2.0 | 6 votes |
/** * * @param e * @return string */ public static String toString(Throwable e) { UnsafeStringWriter w = new UnsafeStringWriter(); PrintWriter p = new PrintWriter(w); p.print(e.getClass().getName()); if (e.getMessage() != null) { p.print(": " + e.getMessage()); } p.println(); try { e.printStackTrace(p); return w.toString(); } finally { p.close(); } }
Example 3
Source File: TestNamingContext.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain;UTF-8"); PrintWriter out = resp.getWriter(); try { Context initCtx = new InitialContext(); Boolean b1 = (Boolean) initCtx.lookup(JNDI_NAME); Boolean b2 = (Boolean) initCtx.lookup( new CompositeName(JNDI_NAME)); out.print(b1); out.print(b2); } catch (NamingException ne) { throw new ServletException(ne); } }
Example 4
Source File: Servicestatus.java From dubbox with Apache License 2.0 | 6 votes |
public void execute(Map<String,Object> context) throws Exception { String uri = request.getRequestURI(); String contextPath = request.getContextPath(); if (contextPath != null && ! "/".equals(contextPath)) { uri = uri.substring(contextPath.length()); } if (uri.startsWith("/status/")) { uri = uri.substring("/status/".length()); } // Map<String, String> providers = registryCache.getServices().get(uri); // if (providers == null || providers.size() == 0) { // providers = providerDAO.lookup(uri); // } // if (providers == null || providers.size() == 0) { // context.put("message", "ERROR" // + new SimpleDateFormat(" [yyyy-MM-dd HH:mm:ss] ").format(new Date()) // + Status.filterOK("No such any provider for service " + uri)); // } else { // context.put("message", "OK"); // } PrintWriter writer = response.getWriter(); writer.print(context.get("message").toString()); writer.flush(); }
Example 5
Source File: UPMiner.java From api-mining with GNU General Public License v3.0 | 6 votes |
private static void saveFrequentSequencesArffFile(final File seqFile, final BiMap<String, Integer> dictionary, final File arffFile) throws IOException { final SortedMap<Sequence, Integer> freqSeqs = FrequentSequenceMiner.readFrequentSequences(seqFile); final PrintWriter out = new PrintWriter(new FileWriter(arffFile, true)); int count = 0; for (final Entry<Sequence, Integer> entry : freqSeqs.entrySet()) { out.print("'unknown" + count + "','"); String prefix = ""; for (final int item : entry.getKey()) { out.print(prefix + dictionary.inverse().get(item)); prefix = " "; } out.println("'"); count++; } out.close(); }
Example 6
Source File: ContentNode.java From letv with Apache License 2.0 | 5 votes |
private void outputPropertyAttributes(PrintWriter ps, ContentProperty prop) { int nAttributes = prop.getNAttributes(); for (int n = 0; n < nAttributes; n++) { Attribute attr = prop.getAttribute(n); ps.print(" " + attr.getName() + "=\"" + attr.getValue() + "\""); } }
Example 7
Source File: AtUtil.java From LPAd_SM-DPPlus_Connector with Apache License 2.0 | 5 votes |
public static void send(final PrintWriter writer, final String line) { LOG.finest("sending: " + line); writer.print(line); writer.print("\r"); writer.flush(); }
Example 8
Source File: InjectBytecodes.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Print an integer so that it takes 'length' characters in * the output. Temporary until formatting code is stable. */ private void traceFixedWidthInt(int x, int length) { if (Inject.verbose) { CharArrayWriter baStream = new CharArrayWriter(); PrintWriter pStream = new PrintWriter(baStream); pStream.print(x); String str = baStream.toString(); for (int cnt = length - str.length(); cnt > 0; --cnt) trace(" "); trace(str); } }
Example 9
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int cmdUnset(Dictionary<?, ?> opts, Reader in, PrintWriter out, Session session) { int retcode = 1; // 1 initially not set to 0 until end of try block try { if (getCurrent(session) == null) { throw new Exception("No configuration open currently"); } final String p = (String) opts.get("property"); final Dictionary<String, Object> dict = getEditingDict(session); final Object o = dict.remove(p); if (o == null) { throw new Exception("No property named " + p + " in current configuration."); } retcode = 0; // Success! } catch (final Exception e) { out.print("Unset failed. Details:"); final String reason = e.getMessage(); out.println(reason == null ? "<unknown>" : reason); } finally { } return retcode; }
Example 10
Source File: StatusTransformer.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Write detailed information about a manager. */ public static void writeManager(PrintWriter writer, ObjectName objectName, MBeanServer mBeanServer, int mode) throws Exception { if (mode == 0) { writer.print("<br>"); writer.print(" Active sessions: "); writer.print(mBeanServer.getAttribute (objectName, "activeSessions")); writer.print(" Session count: "); writer.print(mBeanServer.getAttribute (objectName, "sessionCounter")); writer.print(" Max active sessions: "); writer.print(mBeanServer.getAttribute(objectName, "maxActive")); writer.print(" Rejected session creations: "); writer.print(mBeanServer.getAttribute (objectName, "rejectedSessions")); writer.print(" Expired sessions: "); writer.print(mBeanServer.getAttribute (objectName, "expiredSessions")); writer.print(" Longest session alive time: "); writer.print(formatSeconds(mBeanServer.getAttribute( objectName, "sessionMaxAliveTime"))); writer.print(" Average session alive time: "); writer.print(formatSeconds(mBeanServer.getAttribute( objectName, "sessionAverageAliveTime"))); writer.print(" Processing time: "); writer.print(formatTime(mBeanServer.getAttribute (objectName, "processingTime"), false)); } else if (mode == 1) { // for now we don't write out the wrapper details } }
Example 11
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int cmdShow(Dictionary<?, ?> opts, Reader in, PrintWriter out, Session session) { ConfigurationAdmin srvCA = null; final boolean printTypes = opts.get("-t") != null; try { srvCA = getCA(); final String[] selection = (String[]) opts.get("selection"); final Configuration[] cs = getConfigurations(out, session, srvCA, selection); if (cs == null || cs.length == 0) { throw new Exception("No matching configurations for selection."); } sortConfigurationArray(cs); for (final Configuration cfg : cs) { printConfiguration(out, session, cfg, printTypes); } } catch (final Exception e) { out.print("Show failed. Details:"); final String reason = e.getMessage(); out.println(reason == null ? "<unknown>" : reason); } finally { if (srvCA != null) { bc.ungetService(refCA); } } return 0; }
Example 12
Source File: FragmentActivity.java From guideshow with MIT License | 5 votes |
/** * Print the Activity's state into the given stream. This gets invoked if * you run "adb shell dumpsys activity <activity_component_name>". * * @param prefix Desired prefix to prepend at each line of output. * @param fd The raw file descriptor that the dump is being sent to. * @param writer The PrintWriter to which you should dump your state. This will be * closed for you after you return. * @param args additional arguments to the dump request. */ public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) { // XXX This can only work if we can call the super-class impl. :/ //ActivityCompatHoneycomb.dump(this, prefix, fd, writer, args); } writer.print(prefix); writer.print("Local FragmentActivity "); writer.print(Integer.toHexString(System.identityHashCode(this))); writer.println(" State:"); String innerPrefix = prefix + " "; writer.print(innerPrefix); writer.print("mCreated="); writer.print(mCreated); writer.print("mResumed="); writer.print(mResumed); writer.print(" mStopped="); writer.print(mStopped); writer.print(" mReallyStopped="); writer.println(mReallyStopped); writer.print(innerPrefix); writer.print("mLoadersStarted="); writer.println(mLoadersStarted); if (mLoaderManager != null) { writer.print(prefix); writer.print("Loader Manager "); writer.print(Integer.toHexString(System.identityHashCode(mLoaderManager))); writer.println(":"); mLoaderManager.dump(prefix + " ", fd, writer, args); } mFragments.dump(prefix, fd, writer, args); writer.print(prefix); writer.println("View Hierarchy:"); dumpViewHierarchy(prefix + " ", writer, getWindow().getDecorView()); }
Example 13
Source File: SourceModel.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void generate(PrintWriter pw) { generateAccessFlags(pw); pw.print("interface "); generateName(pw); pw.print(" "); generateBody(pw, "extends"); }
Example 14
Source File: DebugUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public static void printSizeValue(PrintWriter pw, long number) { float result = number; String suffix = ""; if (result > 900) { suffix = "KB"; result = result / 1024; } if (result > 900) { suffix = "MB"; result = result / 1024; } if (result > 900) { suffix = "GB"; result = result / 1024; } if (result > 900) { suffix = "TB"; result = result / 1024; } if (result > 900) { suffix = "PB"; result = result / 1024; } String value; if (result < 1) { value = String.format("%.2f", result); } else if (result < 10) { value = String.format("%.1f", result); } else if (result < 100) { value = String.format("%.0f", result); } else { value = String.format("%.0f", result); } pw.print(value); pw.print(suffix); }
Example 15
Source File: JobSchedulerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private boolean printError(int errCode, String pkgName, int userId, int jobId) { PrintWriter pw; switch (errCode) { case CMD_ERR_NO_PACKAGE: pw = getErrPrintWriter(); pw.print("Package not found: "); pw.print(pkgName); pw.print(" / user "); pw.println(userId); return true; case CMD_ERR_NO_JOB: pw = getErrPrintWriter(); pw.print("Could not find job "); pw.print(jobId); pw.print(" in package "); pw.print(pkgName); pw.print(" / user "); pw.println(userId); return true; case CMD_ERR_CONSTRAINTS: pw = getErrPrintWriter(); pw.print("Job "); pw.print(jobId); pw.print(" in package "); pw.print(pkgName); pw.print(" / user "); pw.print(userId); pw.println(" has functional constraints but --force not specified"); return true; default: return false; } }
Example 16
Source File: DebugStringBuilder.java From Bats with Apache License 2.0 | 5 votes |
public DebugStringBuilder( Object obj ) { strWriter = new StringWriter( ); writer = new PrintWriter( strWriter ); writer.print( "[" ); writer.print( obj.getClass().getSimpleName() ); writer.print( ": " ); fmt = new JFormatter( writer ); }
Example 17
Source File: SensorInternetVS.java From gsn with GNU General Public License v3.0 | 5 votes |
@Override public void dataAvailable(String inputStreamName, StreamElement streamElement) { try { // Init the HTTP Connection HttpURLConnection siConnection = (HttpURLConnection) siUrl.openConnection(); siConnection.setRequestMethod("POST"); siConnection.setDoOutput(true); siConnection.setRequestProperty( "User-Agent", REQUEST_AGENT ); siConnection.connect(); // Build and send the parameters PrintWriter out = new PrintWriter(siConnection.getOutputStream()); String postParams = buildParameters(streamElement.getFieldNames(), streamElement.getData(), streamElement.getTimeStamp()) ; logger.debug("POST parameters: " + postParams) ; out.print(postParams); out.flush(); out.close(); if (siConnection.getResponseCode() == 200) { logger.debug("data successfully sent"); } else { logger.error("Unable to send the data. Check you configuration file. " + siConnection.getResponseMessage() + " Code (" + siConnection.getResponseCode() + ")"); } } catch (IOException e) { logger.error(e.getMessage()) ; } }
Example 18
Source File: SourceModel.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
protected void generateAccessFlags(PrintWriter pw) { StringJoiner joiner = new StringJoiner(" ", "", " "); accessFlags.stream().map(AccessFlag::toString).forEach(joiner::add); pw.print(joiner.toString()); }
Example 19
Source File: BaseServlet.java From document-management-system with GNU General Public License v2.0 | 4 votes |
/** * Print ok messages */ public void ok(PrintWriter out, String msg) { out.print("<div class=\"ok\">" + msg + "</div>"); }
Example 20
Source File: StatusTransformer.java From tomcatsrc with Apache License 2.0 | 3 votes |
/** * Write the manager webapp information. * * @param writer The output writer * @param args What to write * @param mode 0 means write */ public static void writeManager(PrintWriter writer, Object[] args, int mode) { if (mode == 0){ writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args)); } }