Java StringBuilder.toString Examples

Java StringBuilder.toString - 30 examples found. These are the top rated real world Java examples of StringBuilder.toString extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  public WorkerSumm(WorkerSummary workerSummary) {
    this.port = String.valueOf(workerSummary.get_port());
    this.topology = workerSummary.get_topology();

    StringBuilder taskSB = new StringBuilder();
    StringBuilder componentSB = new StringBuilder();
    boolean isFirst = true;

    int minUptime = 0;
    taskSummList = workerSummary.get_tasks();
    for (TaskSummary taskSummary : taskSummList) {
      if (isFirst == false) {
        taskSB.append(',');
        componentSB.append(',');
      } else {
        minUptime = taskSummary.get_uptime_secs();
      }

      taskSB.append(taskSummary.get_task_id());
      componentSB.append(taskSummary.get_component_id());

      if (minUptime < taskSummary.get_uptime_secs()) {
        minUptime = taskSummary.get_uptime_secs();
      }

      isFirst = false;
    }

    this.uptime = StatBuckets.prettyUptimeStr(minUptime);
    this.tasks = taskSB.toString();
    this.components = componentSB.toString();
  }
Example #2
0
  /**
   * Break on commas, except those inside quotes, e.g.: size(300, 200, PDF, "output,weirdname.pdf");
   * No special handling implemented for escaped (\") quotes.
   */
  private static StringList breakCommas(String contents) {
    StringList outgoing = new StringList();

    boolean insideQuote = false;
    // The current word being read
    StringBuilder current = new StringBuilder();
    char[] chars = contents.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      char c = chars[i];
      if (insideQuote) {
        current.append(c);
        if (c == '\"') {
          insideQuote = false;
        }
      } else {
        if (c == ',') {
          if (current.length() != 0) {
            outgoing.append(current.toString());
            current.setLength(0);
          }
        } else {
          current.append(c);
          if (c == '\"') {
            insideQuote = true;
          }
        }
      }
    }
    if (current.length() != 0) {
      outgoing.append(current.toString());
    }
    return outgoing;
  }
  @MediumTest
  public void testLargeField() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");

    StringBuilder sql = new StringBuilder(2100);
    sql.append("INSERT INTO test (data) VALUES ('");
    Random random = new Random(System.currentTimeMillis());
    StringBuilder randomString = new StringBuilder(1979);
    for (int i = 0; i < 1979; i++) {
      randomString.append((random.nextInt() & 0xf) % 10);
    }
    sql.append(randomString);
    sql.append("');");
    mDatabase.execSQL(sql.toString());

    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    assertNotNull(c);
    assertEquals(1, c.getCount());

    assertTrue(c.moveToFirst());
    assertEquals(0, c.getPosition());
    String largeString = c.getString(c.getColumnIndexOrThrow("data"));
    assertNotNull(largeString);
    assertEquals(randomString.toString(), largeString);
    c.close();
  }
  @Override
  public void endElement(String namespaceURI, String localName, String qName) throws SAXException {

    if (qName.equalsIgnoreCase("title") && sect) {
      section.setTitle(ch_str.toString());
      ch_str = new StringBuilder(64);
    } else if (qName.equalsIgnoreCase("section")) {
      section.setDescription(ch_str.toString());
      book.add(new Chapter(section.getTitle(), section.getDescription()));
      ch_str = new StringBuilder(64);

    } else if (descript) {

      if (qName.equalsIgnoreCase("annotation")) {
        book.setAnnotation(ch_str.toString() + "");
        ch_str = new StringBuilder(64);
      }

      if (qName.equalsIgnoreCase("author")) {
        book.authors.add(authors);
        authors = new Author();
      }
    }

    ElementName = "";
  }
  public void addGetterComment(Method method, FullyQualifiedTable table, String columnName) {
    StringBuilder sb = new StringBuilder();

    method.addJavaDocLine("/**"); // $NON-NLS-1$
    method.addJavaDocLine(" * This method was generated by Apache iBATIS ibator."); // $NON-NLS-1$

    sb.append(" * This method returns the value of the database column "); // $NON-NLS-1$
    sb.append(table);
    sb.append('.');
    sb.append(columnName);
    method.addJavaDocLine(sb.toString());

    method.addJavaDocLine(" *"); // $NON-NLS-1$

    sb.setLength(0);
    sb.append(" * @return the value of "); // $NON-NLS-1$
    sb.append(table);
    sb.append('.');
    sb.append(columnName);
    method.addJavaDocLine(sb.toString());

    addIbatorJavadocTag(method);

    method.addJavaDocLine(" */"); // $NON-NLS-1$
  }
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  public Response addUpdateListItem(InputStream incomingData) {
    StringBuilder listBuilder = new StringBuilder();
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(incomingData));
      String line = null;
      while ((line = in.readLine()) != null) {
        listBuilder.append(line);
      }
    } catch (Exception e) {
      System.out.println("Error Parsing :- ");
    }

    try {
      JSONObject json = new JSONObject(listBuilder.toString());
      Iterator<String> iterator = json.keys();
      ListItem item =
          new ListItem(
              (String) json.get(iterator.next()),
              (String) json.get(iterator.next()),
              Boolean.parseBoolean((String) json.get(iterator.next())));
      int index = list.indexOf(item);
      item = list.get(index);
      list.remove(index);
      item.setTitle((String) json.get(iterator.next()));
      item.setBody((String) json.get(iterator.next()));
      list.add(index, item);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    // return HTTP response 200 in case of success
    return Response.status(200).entity(listBuilder.toString()).build();
  }