List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.cleanDL.java
public static void main(String[] args) throws IOException { List<String> lines = FileUtils.readLines(new File("/Users/Shyam/mention.eval.dl")); for (String line : lines) { String[] parts = line.split("\\s+"); System.out.println(parts[0] + parts[1] + parts[2]); StringBuilder sb = new StringBuilder(); for (int i = 3; i < parts.length; i++) sb.append(parts[i] + " "); if (mentionFilter(parts)) { System.out.println("removing " + Arrays.asList(parts)); continue; }//w w w. j ava 2s . c o m if (mentions.containsKey(parts[0])) { mentions.get(parts[0]).add(new DocMention(parts[0], sb.toString(), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]))); } else { mentions.put(parts[0], new ArrayList<DocMention>()); mentions.get(parts[0]).add(new DocMention(parts[0], sb.toString(), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]))); } } for (String doc : mentions.keySet()) { handleDoc(mentions.get(doc)); } outputMentions(); }
From source file:org.eclipse.swt.snippets.Snippet375.java
public static void main(String[] args) throws Exception { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 375"); shell.setLayout(new GridLayout(1, false)); final StringBuilder sb = new StringBuilder(); final Random random = new Random(2546); for (int i = 0; i < 200; i++) { sb.append("Very very long text about ").append(random.nextInt(2000)).append("\t"); if (i % 10 == 0) { sb.append("\n"); }/*w w w.ja v a 2 s.c o m*/ } // H SCROLL final Label lbl1 = new Label(shell, SWT.NONE); lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl1.setText("Horizontal Scroll"); final StyledText txt1 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); txt1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt1.setText(sb.toString()); txt1.setMouseNavigatorEnabled(true); // V_SCROLL final Label lbl2 = new Label(shell, SWT.NONE); lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl2.setText("Vertical Scroll"); final StyledText txt2 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); txt2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt2.setText(sb.toString()); txt2.setMouseNavigatorEnabled(true); // H SCROLL & V_SCROLL final Label lbl3 = new Label(shell, SWT.NONE); lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl3.setText("Horizontal and Vertical Scroll"); final StyledText txt3 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); txt3.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt3.setText(sb.toString()); txt3.setMouseNavigatorEnabled(true); final Button enableDisableButton = new Button(shell, SWT.PUSH); enableDisableButton.setLayoutData(new GridData(GridData.END, GridData.FILL, true, false)); enableDisableButton.setText("Disable Mouse Navigation"); enableDisableButton.addListener(SWT.Selection, e -> { if (txt3.getMouseNavigatorEnabled()) { enableDisableButton.setText("Enable Mouse Navigation"); } else { enableDisableButton.setText("Disable Mouse Navigation"); } txt3.setMouseNavigatorEnabled(!txt3.getMouseNavigatorEnabled()); }); // Disabled Scroll at start final Label lbl4 = new Label(shell, SWT.NONE); lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl4.setText("No scroll at start"); final StyledText txt4 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true); gd.minimumHeight = 100; txt4.setLayoutData(gd); txt4.setText("Disabled scroll"); txt4.setMouseNavigatorEnabled(true); // Disabled Scroll final Label lbl5 = new Label(shell, SWT.NONE); lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl5.setText("No scroll"); final StyledText txt5 = new StyledText(shell, SWT.MULTI | SWT.BORDER); final GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true); gd5.minimumHeight = 100; txt5.setLayoutData(gd5); txt5.setText("No scroll"); txt5.setMouseNavigatorEnabled(true); shell.setSize(800, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:com.simpligility.maven.provisioner.MavenRepositoryProvisioner.java
public static void main(String[] args) { JCommander jcommander = null;/*from w w w .j a v a 2 s . c o m*/ Boolean validConfig = false; logger.info("-----------------------------------"); logger.info(" Maven Repository Provisioner "); logger.info(" simpligility technologies inc. "); logger.info(" http://www.simpligility.com "); logger.info("-----------------------------------"); StringBuilder usage = new StringBuilder(); config = new Configuration(); try { jcommander = new JCommander(config); jcommander.usage(usage); jcommander.parse(args); validConfig = true; } catch (Exception error) { logger.info(usage.toString()); } if (validConfig) { if (config.getHelp()) { logger.info(usage.toString()); } else { logger.info("Provisioning: " + config.getArtifactCoordinate()); logger.info("Source: " + config.getSourceUrl()); logger.info("Target: " + config.getTargetUrl()); logger.info("Username: " + config.getUsername()); if (config.getPassword() != null) { logger.info("Password: " + config.getPassword().replaceAll(".", "***")); } logger.info("IncludeSources:" + config.getIncludeSources()); logger.info("IncludeJavadoc:" + config.getIncludeJavadoc()); logger.info("Local cache directory: " + config.getCacheDirectory()); cacheDirectory = new File(config.getCacheDirectory()); if (cacheDirectory.exists() && cacheDirectory.isDirectory()) { logger.info("Detected local cache directory '" + config.getCacheDirectory() + "' from prior execution."); try { FileUtils.deleteDirectory(cacheDirectory); logger.info(config.getCacheDirectory() + " deleted."); } catch (IOException e) { logger.info(config.getCacheDirectory() + " deletion failed"); } cacheDirectory = new File(config.getCacheDirectory()); } ArtifactRetriever retriever = new ArtifactRetriever(cacheDirectory); retriever.retrieve(config.getArtifactCoordinates(), config.getSourceUrl(), config.getIncludeSources(), config.getIncludeJavadoc()); logger.info("--------------------------------------------"); logger.info("Artifact retrieval completed."); logger.info("--------------------------------------------"); MavenRepositoryHelper helper = new MavenRepositoryHelper(cacheDirectory); helper.deployToRemote(config.getTargetUrl(), config.getUsername(), config.getPassword()); logger.info("--------------------------------------------"); logger.info("Artifact deployment completed."); logger.info("--------------------------------------------"); } } }
From source file:ui.pack.MyFrame.java
public static void main(String... args) throws IOException { //MyFrame mf= new MyFrame(); HttpClient client = HttpClientBuilder.create().build(); String url = "http://localhost:8080/students/all"; HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuilder builder = new StringBuilder(); while (true) { String line = bufferedReader.readLine(); if (line == null) { break; } else {//from ww w . jav a2 s . c o m builder.append(line); } } bufferedReader.close(); String result = builder.toString(); System.out.println(result); JSONArray arr = new JSONArray(result); System.out.println(arr.length()); //client. }
From source file:de.tu.darmstadt.lt.ner.preprocessing.SentenceToCRFWriter.java
public static void main(String[] args) throws UIMAException, IllegalArgumentException, IOException { LineIterator sentIt = FileUtils.lineIterator(new File(args[0]), "UTF-8"); List<String> sentences = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); int index = 0; while (sentIt.hasNext()) { String line = sentIt.nextLine().toString().trim().split("\t")[1]; if (line.equals("")) { continue; }// w ww . j a v a 2 s . c o m sentences.add(line); } GermaNERMain.sentenceToCRFFormat(sentences, args[1], "de"); }
From source file:com.foxykeep.parcelablecodegenerator.Main.java
public static void main(String[] args) { File fileInputDir = new File("input"); if (!fileInputDir.exists() || !fileInputDir.isDirectory()) { return;//from w w w .j a v a 2s.c o m } ArrayList<FileInfo> fileInfoList = new ArrayList<FileInfo>(); findJsonFiles(fileInputDir, null, fileInfoList); StringBuilder sb = new StringBuilder(); // For each file in the input folder for (FileInfo fileInfo : fileInfoList) { String fileName = fileInfo.file.getName(); System.out.println("Generating code for " + fileName); char[] buffer = new char[2048]; sb.setLength(0); Reader in; try { in = new InputStreamReader(new FileInputStream(fileInfo.file), "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); if (read != -1) { sb.append(buffer, 0, read); } } while (read >= 0); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return; } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } String content = sb.toString(); if (content.length() == 0) { System.out.println("file is empty."); return; } try { JSONObject root = new JSONObject(content); // Classes generation String classPackage, className, superClassPackage, superClassName; boolean isSuperClassParcelable, hasSubClasses, isAbstract; classPackage = root.getString("package"); className = root.getString("name"); superClassPackage = JsonUtils.getStringFixFalseNull(root, "superClassPackage"); superClassName = JsonUtils.getStringFixFalseNull(root, "superClassName"); isSuperClassParcelable = root.optBoolean("isSuperClassParcelable"); hasSubClasses = root.optBoolean("hasSubClasses"); if (hasSubClasses) { isAbstract = root.optBoolean("isAbstract"); } else { isAbstract = false; } JSONArray fieldJsonArray = root.optJSONArray("fields"); ArrayList<FieldData> fieldDataList; if (fieldJsonArray != null) { fieldDataList = FieldData.getFieldsData(fieldJsonArray); } else { fieldDataList = new ArrayList<FieldData>(); } // Parcelable generation ParcelableGenerator.generate(fileInfo.dirPath, classPackage, className, superClassPackage, superClassName, isSuperClassParcelable, hasSubClasses, isAbstract, fieldDataList); } catch (JSONException e) { e.printStackTrace(); return; } } }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {" + " background-image: http://www.java2s.com/style/download.png;" + " background-repeat:no-repeat;" + " background-position:left top;" + " background-attachment: scroll;" + " color: #BBBBBB;" + "}" + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>"; String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus."; gui.setPreferredSize(new Dimension(400, 100)); StringBuilder sb = new StringBuilder(); sb.append(HTML);// w w w .j a v a 2 s . c om for (int ii = 0; ii < 10; ii++) { sb.append("<h2>Header 2</h2>"); sb.append(PARAGRAPH); } JEditorPane jep = new JEditorPane(); jep.setOpaque(false); jep.setContentType("text/html"); jep.setText(sb.toString()); JScrollPane jsp = new JScrollPane(jep) { BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB); @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(bg, 0, 0, this); } }; jsp.getViewport().setOpaque(false); gui.add(jsp); Main bih = new Main(); JFrame f = new JFrame(); f.add(gui); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:org.eclipse.swt.snippets.Snippet222.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("StyledText Bullet Example"); shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); StringBuilder text = new StringBuilder(); text.append("Here is StyledText with some bulleted lists:\n\n"); for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " + i + "\n"); text.append("\n"); for (int i = 0; i < 2; i++) text.append("Numbered List Item " + i + "\n"); for (int i = 0; i < 4; i++) text.append("Sub List Item " + i + "\n"); for (int i = 0; i < 2; i++) text.append("Numbered List Item " + (2 + i) + "\n"); text.append("\n"); for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " + i + "\n"); styledText.setText(text.toString()); StyleRange style0 = new StyleRange(); style0.metrics = new GlyphMetrics(0, 0, 40); style0.foreground = display.getSystemColor(SWT.COLOR_RED); Bullet bullet0 = new Bullet(style0); StyleRange style1 = new StyleRange(); style1.metrics = new GlyphMetrics(0, 0, 50); style1.foreground = display.getSystemColor(SWT.COLOR_BLUE); Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1); bullet1.text = "."; StyleRange style2 = new StyleRange(); style2.metrics = new GlyphMetrics(0, 0, 80); style2.foreground = display.getSystemColor(SWT.COLOR_GREEN); Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2); bullet2.text = "\u2713"; StyleRange style3 = new StyleRange(); style3.metrics = new GlyphMetrics(0, 0, 50); Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2); styledText.setLineBullet(2, 4, bullet0); styledText.setLineBullet(7, 2, bullet1); styledText.setLineBullet(9, 4, bullet2); styledText.setLineBullet(13, 2, bullet1); styledText.setLineBullet(16, 4, bullet3); styledText.addPaintObjectListener(event -> { Display display1 = event.display; StyleRange style = event.style;// ww w .j a v a 2 s .c om Font font = style.font; if (font == null) font = styledText.getFont(); TextLayout layout = new TextLayout(display1); layout.setAscent(event.ascent); layout.setDescent(event.descent); layout.setFont(font); layout.setText("\u2023 1." + event.bulletIndex + ")"); layout.draw(event.gc, event.x + 10, event.y); layout.dispose(); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.berrysys.ussdgw.Starter.java
/** * The main method.//w w w. java 2 s.co m * * @param args the arguments * @throws IOException Signals that an I/O exception has occurred. */ public static void main(String[] args) throws IOException { StringBuilder banner = new StringBuilder(); banner.append("\n").append(" ____ ____ \n") .append(" | __ ) ___ _ __ _ __ _ _/ ___| _ _ ___ \n") .append(" | _ \\ / _ \\ '__| '__| | | \\___ \\| | | / __|\n") .append(" | |_) | __/ | | | | |_| |___) | |_| \\__ \\\n") .append(" |____/ \\___|_| _|_| \\__, |____/ \\__, |___/\n") .append(" / ___|(_) __ _| |_ _ _|___/_ _ __ |___/ \n") .append(" \\___ \\| |/ _` | __| '__/ _` | '_ \\ \n") .append(" ___) | | (_| | |_| | | (_| | | | | \n") .append(" |____/|_|\\__, |\\__|_| \\__,_|_| |_| \n") .append(" _ _ __|___/__ ____ \n") .append(" | | | / ___/ ___|| _ \\ \n") .append(" | | | \\___ \\___ \\| | | | \n") .append(" | |_| |___) |__) | |_| | \n") .append(" \\___/|____/____/|____/ \n") .append(" / ___| __ _| |_ _____ ____ _ _ _ \n") .append(" | | _ / _` | __/ _ \\ \\ /\\ / / _` | | | | \n") .append(" | |_| | (_| | || __/\\ V V / (_| | |_| | \n") .append(" \\____|\\__,_|\\__\\___| \\_/\\_/ \\__,_|\\__, |\n") .append(" |___/ \n"); String berrysysUssdGW = banner.toString(); log.info(berrysysUssdGW); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/app-context.xml"); List<DialogListener> serverList = (List<DialogListener>) applicationContext.getBean("sctpServerList"); Iterator<DialogListener> i = serverList.iterator(); while (i.hasNext()) { final DialogListener dialogListenerItem = i.next(); DialogListenerThread dialogListenerThread = new DialogListenerThread(); dialogListenerThread.setDialogListener(dialogListenerItem); dialogListenerThread.start(); ThreadHolder.getInstance().getDialogListenerThreadList().add(dialogListenerThread); } Iterator<DialogListenerThread> j = ThreadHolder.getInstance().getDialogListenerThreadList().iterator(); while (j.hasNext()) { try { j.next().join(); } catch (InterruptedException e) { log.catching(e); } } }
From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.BncCheckDocuments.java
public static void main(String[] args) throws IOException { boolean enabled = false; for (File f : FileUtils.listFiles(new File(BASE), new String[] { "xml" }, true)) { BufferedInputStream bis = null; try {// www .java 2 s . c o m bis = new BufferedInputStream(new FileInputStream(f)); int c; StringBuilder sb = new StringBuilder(); while ((c = bis.read()) != '>') { if (enabled) { if (c == '"') { enabled = false; break; } else { sb.append((char) c); } } if (c == '"') { enabled = true; } } String name = f.getName().substring(0, 3); String id = sb.toString(); if (!name.equals(id)) { System.out.println("Name is [" + name + "], but ID is [" + id + "]."); } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(bis); } } }