List of usage examples for java.io StringWriter append
public StringWriter append(char c)
From source file:Main.java
public static void main(String[] args) { StringWriter sw = new StringWriter(); // append a char System.out.println(sw.append("a")); System.out.println(sw.append("b")); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] args) { StringWriter sw = new StringWriter(); // create two new sequences CharSequence sq1 = "Hello"; CharSequence sq2 = " World from java2s.com"; // append sequence sw.append(sq1); System.out.println(sw.toString()); // append second sequence sw.append(sq2);/*from ww w.ja va 2 s . c o m*/ System.out.println(sw.toString()); }
From source file:com.datatorrent.stram.StreamingAppMaster.java
/** * @param args//www . j a v a 2s.c om * Command line args * @throws Throwable */ public static void main(final String[] args) throws Throwable { StdOutErrLog.tieSystemOutAndErrToLog(); LOG.info("Master starting with classpath: {}", System.getProperty("java.class.path")); LOG.info("version: {}", VersionInfo.APEX_VERSION.getBuildVersion()); StringWriter sw = new StringWriter(); for (Map.Entry<String, String> e : System.getenv().entrySet()) { sw.append("\n").append(e.getKey()).append("=").append(e.getValue()); } LOG.info("appmaster env:" + sw.toString()); Options opts = new Options(); opts.addOption("app_attempt_id", true, "App Attempt ID. Not to be used unless for testing purposes"); opts.addOption("help", false, "Print usage"); CommandLine cliParser = new GnuParser().parse(opts, args); // option "help" overrides and cancels any run if (cliParser.hasOption("help")) { new HelpFormatter().printHelp("ApplicationMaster", opts); return; } Map<String, String> envs = System.getenv(); ApplicationAttemptId appAttemptID = Records.newRecord(ApplicationAttemptId.class); if (!envs.containsKey(Environment.CONTAINER_ID.name())) { if (cliParser.hasOption("app_attempt_id")) { String appIdStr = cliParser.getOptionValue("app_attempt_id", ""); appAttemptID = ConverterUtils.toApplicationAttemptId(appIdStr); } else { throw new IllegalArgumentException("Application Attempt Id not set in the environment"); } } else { ContainerId containerId = ConverterUtils.toContainerId(envs.get(Environment.CONTAINER_ID.name())); appAttemptID = containerId.getApplicationAttemptId(); } boolean result = false; StreamingAppMasterService appMaster = null; try { appMaster = new StreamingAppMasterService(appAttemptID); LOG.info("Initializing Application Master."); Configuration conf = new YarnConfiguration(); appMaster.init(conf); appMaster.start(); result = appMaster.run(); } catch (Throwable t) { LOG.error("Exiting Application Master", t); System.exit(1); } finally { if (appMaster != null) { appMaster.stop(); } } if (result) { LOG.info("Application Master completed."); System.exit(0); } else { LOG.info("Application Master failed."); System.exit(2); } }
From source file:Main.java
public static int[] fileToIntArray(Context myContext, String filename, int size) { int[] array = new int[size]; int i = 0;// w w w . ja va 2 s .c o m FileInputStream inputStream; try { int c; inputStream = myContext.openFileInput(filename); StringWriter writer = new StringWriter(); while ((c = inputStream.read()) != -1) { writer.append((char) c); } String ints[] = writer.toString().split("\n"); for (String s : ints) { array[i++] = Integer.parseInt(s); } } catch (Exception e) { e.printStackTrace(); } return array; }
From source file:org.nuxeo.ecm.platform.pictures.tiles.service.TiledImagePreviewer.java
private static void appendPreviewSettings(StringWriter sb) { sb.append("<script type=\"text/javascript\">"); sb.append("var previewSettings = { "); sb.append("imageOnly: \"true\", "); sb.append("multiImageAnnotation: \"true\", "); sb.append("xPointerFilterPath: \"" + TilingPreviewConstant.ORG_NUXEO_ECM_PLATFORM_PICTURES_TILES_GWT_CLIENT_XPOINTER_FILTER + "\", "); sb.append("pointerAdapter: \"" + TilingPreviewConstant.ORG_NUXEO_ECM_PLATFORM_PICTURES_TILES_GWT_CLIENT_POINTER_ADAPTER + "\", "); sb.append("annotationDecoratorFunction: \"" + TilingPreviewConstant.ORG_NUXEO_ECM_PLATFORM_PICTURES_TILES_GWT_CLIENT_UPDATE_ANNOTATED_DOCUMENT + "\""); sb.append("}"); sb.append("</script>"); }
From source file:com.thinkbiganalytics.hive.util.HiveUtils.java
/** * Quotes the specified string for use in a Hive query. * * @param string the string to be quoted * @return the quoted string/*www. ja v a 2 s. co m*/ */ @Nonnull public static String quoteString(@Nonnull final String string) { try { final StringWriter writer = new StringWriter(string.length() + 2); writer.append('"'); StringEscapeUtils.ESCAPE_JAVA.translate(string, writer); writer.append('"'); return writer.toString(); } catch (final IOException e) { throw new IllegalArgumentException("String contains invalid characters: " + string, e); } }
From source file:Main.java
public static String toString(Collection<Integer> stack, String delimiterChars) { if (stack.isEmpty()) { return ""; }/*from w w w.ja v a2 s. c o m*/ if (stack.size() == 1) { return Integer.toString(stack.iterator().next()); } StringWriter writer = new StringWriter(); String delimiter = ""; for (Integer item : stack) { writer.append(delimiter); writer.append(Integer.toString(item)); delimiter = delimiterChars; } return writer.toString(); }
From source file:org.eclipse.gyrex.common.console.CommandUtil.java
static void printCommandHelp(final CommandInterpreter ci, final String name, final String command, final CmdLineParser parser) { final StringWriter stringWriter = new StringWriter(); stringWriter.append(String.format("%s %s", name, command)); parser.printSingleLineUsage(stringWriter, null); stringWriter.append(SystemUtils.LINE_SEPARATOR); parser.printUsage(stringWriter, null); stringWriter.flush();/*from ww w . j a va2 s . co m*/ ci.println(stringWriter.toString()); }
From source file:de.mpg.escidoc.services.cone.util.RdfHelper.java
/** * Formats an a Map of triples into RDF. * //from w w w. j a va 2 s. c o m * @param id The cone-id of the object * @param triples A map of s-p-o triples * * @return The RDF */ public static String formatMap(String id, TreeFragment triples, Model model) { if (triples != null) { StringWriter result = new StringWriter(); result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); result.append("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""); if (model.getRdfAboutTag() != null && model.getRdfAboutTag().getNamespaceURI() != null && !model .getRdfAboutTag().getNamespaceURI().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#")) { result.append(" xmlns:" + model.getRdfAboutTag().getPrefix() + "=\"" + model.getRdfAboutTag().getNamespaceURI() + "\""); } result.append(">\n"); result.append(triples.toRdf(model)); result.append("</rdf:RDF>\n"); return result.toString(); } else { return ""; } }
From source file:org.apache.hyracks.maven.license.LicenseUtil.java
public static String process(String input, boolean unpad, boolean wrap) throws IOException { try (BufferedReader reader = new BufferedReader(new StringReader(input))) { reader.mark(input.length() + 1); StringWriter sw = new StringWriter(); trim(sw, reader, unpad, wrap);/*w w w.ja v a 2 s . c o m*/ sw.append('\n'); return sw.toString(); } }