List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:Main.java
public static void main(String[] args) throws Exception { String password = "secret"; String algorithm = "SHA"; byte[] plainText = password.getBytes(); MessageDigest md = MessageDigest.getInstance(algorithm); md.reset();//from w w w. j av a 2 s. c om md.update(plainText); byte[] encodedPassword = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < encodedPassword.length; i++) { if ((encodedPassword[i] & 0xff) < 0x10) { sb.append("0"); } sb.append(Long.toString(encodedPassword[i] & 0xff, 16)); } System.out.println("Plain : " + password); System.out.println("Encrypted: " + sb.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { InetAddress ip = InetAddress.getLocalHost(); System.out.println("Current IP address : " + ip.getHostAddress()); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); System.out.print("Current MAC address : "); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); }//from w w w . ja va 2 s. c om System.out.println(sb.toString()); }
From source file:Main.java
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.appendCodePoint(1064124);/*from w ww . j ava2 s . c o m*/ } Charset cs = StandardCharsets.UTF_8; System.out.println(bytesRequiredToEncode(new String(sb), cs)); System.out.println(new String(sb).getBytes(cs).length); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fileInputStream = new FileInputStream(new File("src/file.xml")); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc1 = builder.parse(fileInputStream); doc1.getDocumentElement().normalize(); NodeList kList1 = doc1.getElementsByTagName("item"); StringBuilder stringBuilder = new StringBuilder(); for (int temp = 0; temp < kList1.getLength(); temp++) { Node kNode1 = kList1.item(temp); System.out.println("\nCurrent Element :" + kNode1.getNodeName()); if (kNode1.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) kNode1; System.out.println("node name" + eElement.getNodeName()); Node in = eElement.getFirstChild(); if ((in.getTextContent() != null) && !(in.getTextContent()).isEmpty() && !(in.getTextContent().length() == 0)) stringBuilder.append(in.getTextContent()); }/* ww w. j a va 2 s . co m*/ } System.out.println(stringBuilder); }
From source file:br.ufjf.video.Video.java
public static void main(String args[]) { StringBuilder sb = new StringBuilder(); XMLManager.loadXMLFile("../files/ead_fonseca_05_sd.xml"); sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.TITLE, StringEscapeUtils.escapeJava(XMLManager.getValue("title")))); sb.append("\n"); sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.ABSTRACT, StringEscapeUtils.escapeJava(XMLManager.getValue("course")))); sb.append("\n"); sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.DATE, XMLManager.getValue("date"))); sb.append("\n"); //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.REFERENCES,XMLManager.getValue("title"))); //sb.append("\n"); //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.DESCRIPTION,XMLManager.getValue("title"))); //sb.append("\n"); sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.PUBLISHER, StringEscapeUtils.escapeJava(XMLManager.getValue("name")))); sb.append("\n"); sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.CREATOR, StringEscapeUtils.escapeJava(XMLManager.getValue("entity")))); sb.append("\n"); //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.LICENSE,XMLManager.getValue("title"))); //sb.append("\n"); sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.LANGUAGE, XMLManager.getValue("language"))); sb.append("\n"); //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.EDUCATIONLEVEL,XMLManager.getValue("title"))); //sb.append("\n"); FileManager.writeFile("../files/allegro.graph.nt", sb.toString()); System.out.println(sb.toString()); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(true);//from ww w . j av a2 s . c o m fc.setCurrentDirectory(new File("C:\\tmp")); JButton btn1 = new JButton("Show Dialog"); btn1.addActionListener(e -> fc.showDialog(frame, "Choose")); JButton btn2 = new JButton("Show Open Dialog"); btn2.addActionListener(e -> { int retVal = fc.showOpenDialog(frame); if (retVal == JFileChooser.APPROVE_OPTION) { File[] selectedfiles = fc.getSelectedFiles(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < selectedfiles.length; i++) { sb.append(selectedfiles[i].getName()); sb.append("\n"); } JOptionPane.showMessageDialog(frame, sb.toString()); } }); JButton btn3 = new JButton("Show Save Dialog"); btn3.addActionListener(e -> fc.showSaveDialog(frame)); Container pane = frame.getContentPane(); pane.setLayout(new GridLayout(3, 1, 10, 10)); pane.add(btn1); pane.add(btn2); pane.add(btn3); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:be.dnsbelgium.rdap.client.ManGenerator.java
public static void main(String[] args) { Options options = new RDAPOptions(Locale.ENGLISH); Iterator<Option> it = options.getOptions().iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { Option option = it.next(); sb.append(String.format(".IP \"%s\"\n%s\n", getOptionString(option), option.getDescription() == null ? "" : option.getDescription())); }//from w ww . ja v a 2 s . c om System.out.println(sb.toString()); }
From source file:com.util.finalProy.java
/** * @param args the command line arguments *///from w w w.j a va2s . c o m public static void main(String[] args) throws JSONException { // TODO code application logic her System.out.println("OBTENER SOLO UN ARRAY DE CADENA JSON"); String myURL = "http://192.168.5.44/app_dev.php/cus/getaccount/50241109321.json"; System.out.println("Requested URL:" + myURL); StringBuilder sb = new StringBuilder(); URLConnection urlConn = null; InputStreamReader in = null; try { URL url = new URL(myURL); urlConn = url.openConnection(); if (urlConn != null) { urlConn.setReadTimeout(60 * 1000); } if (urlConn != null && urlConn.getInputStream() != null) { in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); BufferedReader bufferedReader = new BufferedReader(in); if (bufferedReader != null) { int cp; while ((cp = bufferedReader.read()) != -1) { sb.append((char) cp); } bufferedReader.close(); } } in.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Exception while calling URL:" + myURL, e); } String jsonResult = sb.toString(); System.out.println(sb.toString()); System.out.println( "\n\n--------------------OBTENEMOS OBJETO JSON NATIVO DE LA PAGINA, USAMOS EL ARRAY DATA---------------------------\n\n"); JSONObject objJason = new JSONObject(jsonResult); JSONArray dataJson = new JSONArray(); dataJson = objJason.getJSONArray("data"); System.out.println("objeto normal 1 " + dataJson.toString()); // // System.out.println( "\n\n--------------------CREAMOS UN STRING JSON2 REEMPLAZANDO LOS CORCHETES QUE DAN ERROR---------------------------\n\n"); String jsonString2 = dataJson.toString(); String temp = dataJson.toString(); temp = jsonString2.replace("[", ""); jsonString2 = temp.replace("]", ""); System.out.println("new json string" + jsonString2); JSONObject objJson2 = new JSONObject(jsonString2); System.out.println("el objeto simple json es " + objJson2.toString()); System.out.println( "\n\n--------------------CREAMOS UN OBJETO JSON CON EL ARRAR ACCOUN---------------------------\n\n"); String account1 = objJson2.optString("account"); System.out.println(account1); JSONObject objJson3 = new JSONObject(account1); System.out.println("el ULTIMO OBJETO SIMPLE ES " + objJson3.toString()); System.out.println( "\n\n--------------------EMPEZAMOS A RECIBIR LOS PARAMETROS QUE HAY EN EL OBJETO JSON---------------------------\n\n"); String firstName = objJson3.getString("first_name"); System.out.println(firstName); System.out.println(objJson3.get("id")); System.out.println( "\n\n--------------------TRATAMOS DE PASAR TODO EL ACCOUNT A OBJETO JAVA---------------------------\n\n"); Gson gson = new Gson(); Account account = gson.fromJson(objJson3.toString(), Account.class); System.out.println(account.getFirst_name()); System.out.println(account.getCreation()); }
From source file:edu.cuhk.hccl.TripRealRatingsApp.java
public static void main(String[] args) throws IOException { File dir = new File(args[0]); File outFile = new File(args[1]); outFile.delete();/*from w w w . j a va2s. c o m*/ StringBuilder buffer = new StringBuilder(); for (File file : dir.listFiles()) { List<String> lines = FileUtils.readLines(file, "UTF-8"); String hotelID = file.getName().split("_")[1]; String author = null; boolean noContent = false; for (String line : lines) { if (line.startsWith("<Author>")) { try { author = line.split(">")[1].trim(); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("[ERROR] An error occured on this line:"); System.out.println(line); continue; } } else if (line.startsWith("<Content>")) { // ignore records if they have no content String content = line.split(">")[1].trim(); if (content == null || content.equals("")) noContent = true; } else if (line.startsWith("<Rating>")) { String[] rates = line.split(">")[1].trim().split("\t"); if (noContent || rates.length != 8) continue; // Change missing rating from -1 to 0 for (int i = 0; i < rates.length; i++) { if (rates[i].equals("-1")) rates[i] = "0"; } buffer.append(author + "\t"); buffer.append(hotelID + "\t"); // overall buffer.append(rates[0] + "\t"); // location buffer.append(rates[3] + "\t"); // room buffer.append(rates[2] + "\t"); // service buffer.append(rates[6] + "\t"); // value buffer.append(rates[1] + "\t"); // cleanliness buffer.append(rates[4] + "\t"); buffer.append("\n"); } } // Write once for each file FileUtils.writeStringToFile(outFile, buffer.toString(), true); // Clear buffer buffer.setLength(0); System.out.printf("[INFO] Finished processing %s\n", file.getName()); } System.out.println("[INFO] All processinig are finished!"); }
From source file:net.vnt.ussdapp.util.ContextTest.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "/context.xml" }); ContextProperties ctxProp = (ContextProperties) Context.getInstance().getBean("ContextProperties"); TXTParser parser = (TXTParser) Context.getInstance().getBean("TXTParser"); String mainmenu = ctxProp.getProperty("ussdapp.wrong"); try {//w w w .j a va 2s . c o m Vector<String> vs = parser.readFields(mainmenu); Enumeration<String> ens = vs.elements(); StringBuilder sb = new StringBuilder(); while (ens.hasMoreElements()) { sb.append(ens.nextElement()).append("\n"); } System.out.println(sb.toString()); } catch (IOException ex) { Logger.getLogger(ContextTest.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(System.getProperty("os.arch")); }