List of usage examples for java.io PrintStream println
public void println(Object x)
From source file:com.xylocore.copybook.runtime.internal.AbstractCopybookGenerator.java
/** * FILLIN/*from w w w .j ava 2s. c o m*/ * * @param aOutputStream * @param aModifiers * @param aMethodName * @param aReturnType * @param aParameters */ private static void generateMethodHeader(PrintStream aOutputStream, String aModifiers, String aMethodName, String aReturnType, List<Parameter> aParameters) { assert StringUtils.isNotBlank(aMethodName); assert StringUtils.isNotBlank(aModifiers); if (aReturnType == null) { aReturnType = "void"; } if (aParameters == null) { aParameters = Collections.<Parameter>emptyList(); } int myParameterCount = aParameters.size(); aOutputStream.println(" /**"); aOutputStream.println(" * FILLIN"); aOutputStream.println(" * "); for (Parameter myParameter : aParameters) { aOutputStream.println(" * @param " + myParameter.getName()); } if (!aReturnType.equals("void")) { aOutputStream.println(" * "); aOutputStream.println(" * @return"); } aOutputStream.println(" */"); String myMethodPrefix = " " + aModifiers + " " + aReturnType + " " + aMethodName; if (myParameterCount != 0) { String myParameterSeparator = (myParameterCount > 1) ? " " : " "; String myLastParameterSuffix = (myParameterCount > 1) ? " )" : ")"; StringBuilder myBuffer = new StringBuilder(); boolean myFirst = true; int myMaxParamTypeLength = 0; int myMaxParamNameLength = 0; for (Parameter myParameter : aParameters) { myMaxParamTypeLength = Math.max(myMaxParamTypeLength, myParameter.getDataType().length()); myMaxParamNameLength = Math.max(myMaxParamNameLength, myParameter.getName().length()); } for (Iterator<Parameter> myIterator = aParameters.iterator(); myIterator.hasNext();) { Parameter myParameter = myIterator.next(); myBuffer.setLength(0); if (myFirst) { myBuffer.append(myMethodPrefix).append("( "); myFirst = false; } else { FormatHelper.stringOfCharacters(myBuffer, ' ', myMethodPrefix.length() + 2); } String myParameterSuffix = (myIterator.hasNext()) ? "," : " "; FormatHelper.formatString(myBuffer, myParameter.getDataType(), myMaxParamTypeLength); myBuffer.append(myParameterSeparator); FormatHelper.formatString(myBuffer, myParameter.getName() + myParameterSuffix, myMaxParamNameLength + myParameterSuffix.length()); if (!myIterator.hasNext()) { myBuffer.append(myLastParameterSuffix); } aOutputStream.println(myBuffer.toString()); } } else { aOutputStream.println(myMethodPrefix + "()"); } }
From source file:com.googlecode.android_scripting.jsonrpc.JsonRpcServerTest.java
public void testInvalidHandshake() throws IOException, JSONException, InterruptedException { JsonRpcServer server = new JsonRpcServer(null, "foo"); InetSocketAddress address = server.startLocal(0); Socket client = new Socket(); client.connect(address);/*from www.j a v a 2s.c om*/ PrintStream out = new PrintStream(client.getOutputStream()); out.println(buildRequest(0, "_authenticate", Lists.newArrayList("bar"))); BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); JSONObject response = new JSONObject(in.readLine()); Object error = response.get("error"); assertTrue(JSONObject.NULL != error); while (!out.checkError()) { out.println(buildRequest(0, "makeToast", Lists.newArrayList("baz"))); } client.close(); // Further connections should fail; client = new Socket(); try { client.connect(address); fail(); } catch (IOException e) { } }
From source file:com.gs.obevo.db.impl.platforms.postgresql.PostgreSqlPgDumpReveng.java
@Override protected File printInstructions(PrintStream out, AquaRevengArgs args) { out.println("1) Run the following command to generate the DDL file:"); out.println(getCommandWithDefaults(args, "<username>", "<password>", "<dbHost>", "<dbPortNumber>", "<dbName>", "<dbSchema>", "<outputFile>")); out.println(""); out.println("Here is an example command (in case your values are not filled in):"); out.println(getCommandWithDefaults(args, "myuser", "mypassword", "myhost.myplace.com", "12345", "mydb", "myschema", "H:\\sybase-ddl-output.txt")); out.println(""); out.println("The pg_dump command will "); return null;//ww w . ja va 2s.co m }
From source file:com.mockey.ui.RequestInspectorAjaxServlet.java
/** * /*from w w w.j a va 2 s .c o m*/ */ public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Long fulfilledRequestId = null; JSONObject jsonObject = new JSONObject(); JSONArray array = new JSONArray(); try { for (Class<?> item : PluginStore.getInstance().getRequestInspectorImplClassList()) { array.put(item.getName()); } jsonObject.putOpt("request_inspectors", array); } catch (Exception e) { try { jsonObject.put("error", "" + "Sorry, history for this conversation (fulfilledRequestId=" + fulfilledRequestId + ") is not available."); } catch (JSONException e1) { logger.error("Unable to create JSON", e1); } } resp.setContentType("application/json"); PrintStream out = new PrintStream(resp.getOutputStream()); out.println(jsonObject.toString()); }
From source file:edu.harvard.hul.ois.fits.tools.ToolBelt.java
public void printToolInfo(boolean sysInfo, PrintStream p) { if (sysInfo) { //system info p.println("OS Name = " + System.getProperty("os.name")); p.println("OS Arch = " + System.getProperty("os.arch")); p.println("OS Version = " + System.getProperty("os.version")); p.println("------------------------------------"); }//from w w w .j a v a 2s . co m for (Tool t : tools) { p.print(t.getToolInfo().print()); } }
From source file:com.indeed.imhotep.web.QueryServlet.java
static void handleError(HttpServletResponse resp, boolean json, Throwable e, boolean status500, boolean isEventStream) throws IOException { if (!(e instanceof Exception || e instanceof OutOfMemoryError)) { throw Throwables.propagate(e); }//from w w w .j a v a2s . c o m // output parse/execute error if (!json) { final ServletOutputStream outputStream = resp.getOutputStream(); final PrintStream printStream = new PrintStream(outputStream); if (isEventStream) { resp.setContentType("text/event-stream"); final String[] stackTrace = Throwables.getStackTraceAsString(e).split("\\n"); printStream.println("event: servererror"); for (String s : stackTrace) { printStream.println("data: " + s); } printStream.println(); } else { resp.setStatus(500); e.printStackTrace(printStream); printStream.close(); } } else { if (status500) { resp.setStatus(500); } // construct a parsed error object to be JSON serialized String clause = ""; int offset = -1; if (e instanceof IQLParseException) { final IQLParseException IQLParseException = (IQLParseException) e; clause = IQLParseException.getClause(); offset = IQLParseException.getOffsetInClause(); } final String stackTrace = Throwables.getStackTraceAsString(Throwables.getRootCause(e)); final ErrorResult error = new ErrorResult(e.getClass().getSimpleName(), e.getMessage(), stackTrace, clause, offset); resp.setContentType("application/json"); final ObjectMapper jsonMapper = new ObjectMapper(); final ServletOutputStream outputStream = resp.getOutputStream(); jsonMapper.defaultPrettyPrintingWriter().writeValue(outputStream, error); outputStream.close(); } }
From source file:de.zib.scalaris.InterOpTest.java
private static int read_or_write(final TransactionSingleOp sc, final String key, final Object value, final Mode mode) { try {// w w w . ja v a2 s . c o m switch (mode) { case READ: final ErlangValue actual = sc.read(key); Object jresult = null; if (value instanceof Boolean) { jresult = actual.boolValue(); } else if (value instanceof Integer) { jresult = actual.intValue(); } else if (value instanceof Long) { jresult = actual.longValue(); } else if (value instanceof BigInteger) { jresult = actual.bigIntValue(); } else if (value instanceof Double) { jresult = actual.doubleValue(); } else if (value instanceof String) { jresult = actual.stringValue(); } else if (value instanceof byte[]) { jresult = actual.binaryValue(); } else if (value instanceof List<?>) { jresult = actual.listValue(); } else if (value instanceof Map<?, ?>) { jresult = actual.jsonValue(); } else { jresult = actual.value(); } PrintStream out; int result; String resultStr; if (compare(jresult, value)) { out = System.out; result = 0; resultStr = "ok"; } else { out = System.err; result = 1; resultStr = "fail"; } out.println("read(" + key + ")"); out.println(" expected: " + valueToStr(value)); out.println(" read raw: " + actual.value().toString()); out.println(" read java: " + valueToStr(jresult)); out.println(resultStr); return result; case WRITE: System.out.println("write(" + key + ", " + valueToStr(value) + ")"); sc.write(key, value); return 0; } } catch (final ConnectionException e) { System.out.println("failed with connection error"); } catch (final AbortException e) { System.out.println("failed with abort"); } catch (final NotFoundException e) { System.out.println("failed with not_found"); } catch (final UnknownException e) { System.out.println("failed with unknown"); e.printStackTrace(); } catch (final ClassCastException e) { System.out.println("failed with ClassCastException"); e.printStackTrace(); } return 1; }
From source file:android.database.DatabaseUtils.java
/** * Prints the contents of a Cursor to a PrintSteam. The position is restored * after printing./*from w w w . j av a 2 s .c o m*/ * * @param cursor the cursor to print * @param stream the stream to print to */ public static void dumpCursor(Cursor cursor, PrintStream stream) { stream.println(">>>>> Dumping cursor " + cursor); if (cursor != null) { int startPos = cursor.getPosition(); cursor.moveToPosition(-1); while (cursor.moveToNext()) { dumpCurrentRow(cursor, stream); } cursor.moveToPosition(startPos); } stream.println("<<<<<"); }
From source file:com.groupon.jenkins.dynamic.build.execution.DynamicBuildExection.java
public Result doRun(BuildListener listener) throws IOException, InterruptedException { try {/*from w w w . java 2 s . com*/ if (!buildEnvironment.initialize()) { return Result.FAILURE; } if (getBuildConfiguration().isSkipped()) { build.skip(); return Result.SUCCESS; } build.setDescription(build.getCause().getBuildDescription()); return dynamicBuildRunner.runBuild(listener); } catch (InterruptedException e) { Executor x = Executor.currentExecutor(); x.recordCauseOfInterruption(build, listener); return x.abortResult(); } catch (InvalidDotCiYmlException e) { throw e; } catch (Exception e) { PrintStream logger = listener.getLogger(); logger.println(e.getMessage()); logger.println(ExceptionUtils.getStackTrace(e)); Executor x = Executor.currentExecutor(); x.recordCauseOfInterruption(build, listener); x.doStop(); return Result.FAILURE; } finally { if (buildEnvironment.tearDownBuildEnvironments(listener)) { return Result.FAILURE; } } }
From source file:eu.ggnet.dwoss.util.gen.NameGenerator.java
public void showSourceData(PrintStream out) { if (out == null) return;/*from w ww . j a v a 2s . com*/ out.println("Business Enteties:"); for (String string : businessEntities) { out.println(" " + string); } out.println("Names Female First:"); for (String string : namesFemaleFirst) { out.println(" " + string); } out.println("Names Male First:"); for (String string : namesMaleFirst) { out.println(" " + string); } out.println("Names Last:"); for (String string : namesLast) { out.println(" " + string); } out.println("Streets:"); for (String string : streets) { out.println(" " + string); } out.println("Towns:"); for (String string : towns) { out.println(" " + string); } }