Java StringBuilder.setLength Examples

Java StringBuilder.setLength - 30 examples found. These are the top rated real world Java examples of StringBuilder.setLength extracted from open source projects. You can rate examples to help us improve the quality of examples.
  public String siguienteInstruccion() throws IOException {
    String instruccion = null;

    if (buffer.length() > 0) {
      int pos = buscaChar(buffer, 0, buffer.length(), ';');
      if (pos > 0) {
        instruccion = buffer.substring(0, pos);
        buffer = new StringBuilder(buffer.substring(pos + 1, buffer.length()));
      }
    } else {
      char[] cbuf = new char[4 * 1024];
      int leidos = 0;
      while ((instruccion == null) && ((leidos = reader.read(cbuf)) != -1)) {
        leidos = reemplazaSeparadorDeLinea(' ', cbuf, 0, leidos);
        int pos = buscaChar(cbuf, 0, leidos, ';');
        if (pos > 0) {
          buffer.append(cbuf, 0, pos);
          instruccion = buffer.toString();
          buffer.setLength(0);
          buffer.append(cbuf, pos + 1, leidos);
        } else {
          buffer.append(cbuf, 0, leidos);
        }
      }
      if (leidos == -1 && buffer.length() > 0) {
        instruccion = buffer.toString();
        buffer.setLength(0);
      }
    }
    return instruccion;
  }
Example #2
0
  @Override
  protected void processFile(BufferedReader inFile, BufferedWriter outFile, FilterContext fc)
      throws IOException, TranslationException {
    out = outFile;
    READ_STATE state = READ_STATE.WAIT_TIME;
    key = null;
    text.setLength(0);

    String s;
    while ((s = inFile.readLine()) != null) {
      switch (state) {
        case WAIT_TIME:
          if (PATTERN_TIME_INTERVAL.matcher(s).matches()) {
            state = READ_STATE.WAIT_TEXT;
          }
          key = s;
          text.setLength(0);
          outFile.write(s);
          outFile.write(EOL);
          break;
        case WAIT_TEXT:
          if (s.trim().isEmpty()) {
            flush();
            outFile.write(EOL);
            state = READ_STATE.WAIT_TIME;
          }
          if (text.length() > 0) {
            text.append('\n');
          }
          text.append(s);
          break;
      }
    }
    flush();
  }
  @Override
  public String toString() {

    StringBuilder sb = new StringBuilder();
    sb.append(arg1);
    sb.append("\t");
    sb.append(arg2);
    sb.append("\t");
    for (Integer rel : Y) {
      sb.append(rel);
      sb.append("|");
    }
    sb.setLength(sb.length() - 1);
    sb.append("\n");
    for (int i = 0; i < numMentions; i++) {
      sb.append("Mention " + i + " ");
      for (int feat : features[i].ids) {
        sb.append(feat);
        sb.append(" ");
      }
      sb.append("\n");
    }
    sb.setLength(sb.length() - 1);

    return sb.toString().trim();
  }
 @NotNull
 public static String getLibraryName(@NotNull Library library) {
   final String result = library.getName();
   if (result != null) {
     return result;
   }
   String[] endingsToStrip = {"/", "!", ".jar"};
   StringBuilder buffer = new StringBuilder();
   for (OrderRootType type : OrderRootType.getAllTypes()) {
     for (String url : library.getUrls(type)) {
       buffer.setLength(0);
       buffer.append(url);
       for (String ending : endingsToStrip) {
         if (buffer.lastIndexOf(ending) == buffer.length() - ending.length()) {
           buffer.setLength(buffer.length() - ending.length());
         }
       }
       final int i = buffer.lastIndexOf(PATH_SEPARATOR);
       if (i < 0 || i >= buffer.length() - 1) {
         continue;
       }
       String candidate = buffer.substring(i + 1);
       if (!StringUtil.isEmpty(candidate)) {
         return candidate;
       }
     }
   }
   assert false;
   return "unknown-lib";
 }
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();

    sb.append(name);

    if (getNameQualifiers() != null && getNameQualifiers().size() > 0) {
      sb.append('<');

      for (Qualifier q : getNameQualifiers())
        sb.append(q.getName()).append('=').append(q.getValue()).append(';');

      sb.setLength(sb.length() - 1);

      sb.append('>');
    }

    sb.append('=').append(value);

    if (getValueQualifiers() != null && getValueQualifiers().size() > 0) {
      sb.append('[');

      for (Qualifier q : getValueQualifiers())
        sb.append(q.getName()).append('=').append(q.getValue()).append(';');

      sb.setLength(sb.length() - 1);

      sb.append(']');
    }

    return sb.toString();
  }
  protected void calculateJavaClientAttributes() {
    if (context.getJavaClientGeneratorConfiguration() == null) {
      return;
    }

    StringBuilder sb = new StringBuilder();
    sb.append(calculateJavaClientImplementationPackage());
    sb.append('.');
    sb.append(fullyQualifiedTable.getDomainObjectName());
    sb.append("DAOImpl"); // $NON-NLS-1$
    setDAOImplementationType(sb.toString());

    sb.setLength(0);
    sb.append(calculateJavaClientInterfacePackage());
    sb.append('.');
    sb.append(fullyQualifiedTable.getDomainObjectName());
    sb.append("DAO"); // $NON-NLS-1$
    setDAOInterfaceType(sb.toString());

    sb.setLength(0);
    sb.append(calculateJavaClientInterfacePackage());
    sb.append('.');
    sb.append(fullyQualifiedTable.getDomainObjectName());
    sb.append("Mapper"); // $NON-NLS-1$
    setMyBatis3JavaMapperType(sb.toString());

    sb.setLength(0);
    sb.append(calculateJavaClientInterfacePackage());
    sb.append('.');
    sb.append(fullyQualifiedTable.getDomainObjectName());
    sb.append("SqlProvider"); // $NON-NLS-1$
    setMyBatis3SqlProviderType(sb.toString());
  }