Java StringBuilder.delete Examples

Java StringBuilder.delete - 30 examples found. These are the top rated real world Java examples of StringBuilder.delete extracted from open source projects. You can rate examples to help us improve the quality of examples.
 public static URL container(String resource, ClassLoader cl) {
   final URL resUrl = cl.getResource(resource);
   if (resUrl == null) {
     throw new IllegalArgumentException("Resource not found: " + resource);
   }
   final StringBuilder url = new StringBuilder(resUrl.toExternalForm());
   try {
     if ("jar".equalsIgnoreCase(resUrl.getProtocol())) {
       url.delete(0, 4).delete(url.indexOf(resource) - 2, url.length());
     } else if ("file".equalsIgnoreCase(resUrl.getProtocol())) {
       url.delete(url.indexOf(resource), url.length());
     } else {
       throw new UnsupportedOperationException(
           "Cannot get container for resource ["
               + resource
               + "]. Unsupported URL protocol ["
               + resUrl.getProtocol()
               + "].");
     }
     return new URL(url.toString());
   } catch (MalformedURLException e) {
     throw new UnsupportedOperationException(
         "Cannot get container for resource [" + resource + "]. Malformed URL [" + url + "].");
   }
 }
 /**
  * Method to create/get ignoring players file
  *
  * @param filename
  */
 public void initIgnoreLog(String filename) {
   StringBuilder sb = new StringBuilder();
   File existing = new File(filename);
   CivChat2.debugmessage("Initializing IgnoreLog...");
   try {
     if (existing.exists()) {
       // ignore file exists load it
       CivChat2.infoMessage(
           sb.append("Existing Ignore file: ").append(existing.getAbsolutePath()).toString());
       sb.delete(0, sb.length());
       FileWriter fw = new FileWriter(existing, true);
       writer = new BufferedWriter(fw);
       ignoredPlayers = existing;
       chatMan.loadIgnoredPlayers(ignoredPlayers);
     } else {
       // create new ignore file
       CivChat2.infoMessage(
           sb.append("Creating new Ignore file: ").append(existing.getAbsolutePath()).toString());
       sb.delete(0, sb.length());
       existing.createNewFile();
       PrintWriter pw = new PrintWriter(existing);
       writer = new BufferedWriter(pw);
       ignoredPlayers = existing;
       addIgnoreHeader();
     }
   } catch (IOException ex) {
     CivChat2.warningMessage("File Failed: " + ex);
   }
 }
  /**
   * Method to create/get chat log text file
   *
   * @return true if file was created successfully, false if failed
   */
  public void initchatLog(String filename) {
    StringBuilder sb = new StringBuilder();
    File existing = new File(filename);
    CivChat2.debugmessage(
        sb.append("Initializing chatlog... filename=[")
            .append(filename.toString())
            .append("]")
            .toString());
    sb.delete(0, sb.length());
    // first create chatlog file
    try {
      if (existing.exists()) {
        // directory already exists
        CivChat2.infoMessage(
            sb.append("Existing Chat File: ").append(existing.getAbsolutePath()).toString());
        sb.delete(0, sb.length());
        FileWriter fw = new FileWriter(existing.getAbsolutePath(), true);
        fileWriter = new BufferedWriter(fw);
      } else {
        CivChat2.infoMessage(
            sb.append("Creating new File").append(existing.getAbsolutePath()).toString());
        sb.delete(0, sb.length());
        existing.createNewFile();
        PrintWriter fStream = new PrintWriter(existing);
        fileWriter = new BufferedWriter(fStream);
        addHeader();
      }

    } catch (IOException ex) {
      CivChat2.warningMessage("File Failed" + ex);
    }
  }
 /**
  * Create result values from observation according to ResultEncoding and ResultStructure
  *
  * @param observations Observation to create result values from
  * @param sosResultEncoding The ResultEncoding
  * @param sosResultStructure The ResultStructure
  * @return Result values String from observation according to ResultEncoding and ResultStructure
  * @throws OwsExceptionReport If creation fails
  */
 public static String createResultValuesFromObservations(
     final List<AbstractObservation> observations,
     final SosResultEncoding sosResultEncoding,
     final SosResultStructure sosResultStructure)
     throws OwsExceptionReport {
   final StringBuilder builder = new StringBuilder();
   if (CollectionHelper.isNotEmpty(observations)) {
     final String tokenSeparator = getTokenSeparator(sosResultEncoding.getEncoding());
     final String blockSeparator = getBlockSeparator(sosResultEncoding.getEncoding());
     final Map<Integer, String> valueOrder =
         getValueOrderMap(sosResultStructure.getResultStructure());
     addElementCount(builder, observations.size(), blockSeparator);
     for (final AbstractObservation observation : observations) {
       for (final Integer intger : valueOrder.keySet()) {
         final String definition = valueOrder.get(intger);
         if (definition.equals(PHENOMENON_TIME)) {
           builder.append(
               getTimeStringForPhenomenonTime(
                   observation.getPhenomenonTimeStart(), observation.getPhenomenonTimeEnd()));
         } else if (definition.equals(RESULT_TIME)) {
           builder.append(getTimeStringForResultTime(observation.getResultTime()));
         } else {
           builder.append(getValueAsStringForObservedProperty(observation, definition));
         }
         builder.append(tokenSeparator);
       }
       builder.delete(builder.lastIndexOf(tokenSeparator), builder.length());
       builder.append(blockSeparator);
     }
     if (builder.length() > 0) {
       builder.delete(builder.lastIndexOf(blockSeparator), builder.length());
     }
   }
   return builder.toString();
 }
Example #5
0
  @SuppressLint("NewApi")
  @Override
  public void run() {
    ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    MemoryInfo mi = new MemoryInfo();
    am.getMemoryInfo(mi);
    StringBuilder buf = new StringBuilder();
    buf.append("mi.availMem=").append(mi.availMem / MB).append(", ");
    buf.append("mi.threshold=").append(mi.threshold / MB).append(", ");
    buf.append("mi.totalMem=").append(mi.totalMem / MB).append(", ");
    buf.append("mi.lowMemory=").append(mi.lowMemory);
    Log.d(TAG, "MemoryInfo=" + buf.toString());

    buf.delete(0, buf.length());
    buf.append("TotalMemory=" + TotalMemory()).append(", ");
    buf.append("FreeMemory=" + FreeMemory()).append(", ");
    buf.append("BusyMemory=" + BusyMemory());
    Log.d(TAG, "RootDirectory= " + buf.toString());

    buf.delete(0, buf.length());
    buf.append("TotalMemory=" + DeviceMemory.getInternalStorageSpace()).append(", ");
    buf.append("FreeMemory=" + DeviceMemory.getInternalFreeSpace()).append(", ");
    buf.append("BusyMemory=" + DeviceMemory.getInternalUsedSpace());
    Log.d(TAG, "DeviceMemory= " + buf.toString());
  }
Example #6
0
  /**
   * @param querymap 封装sql的where语句 key value 相当于 where key=value
   * @param _sql 查出列表的sql
   * @param _csql 查出列表总数的sql
   * @param args 参数列表(不包括wheremap里的)
   * @return
   */
  private Object[] initPreSql(
      Map<String, Object> querymap, String _sql, String _csql, Object... args) {
    Object[] parms = null;
    psql.delete(0, psql.length());
    psql.append(_sql);
    csql.delete(0, csql.length());
    csql.append(_csql);
    int i = 0;
    if (MyUtil.isEmpty(args) && MyUtil.isEmpty(querymap)) return null;
    if (!MyUtil.isEmpty(args) && MyUtil.isEmpty(querymap)) return args;

    if (MyUtil.isEmpty(args)) {
      parms = new Object[querymap.size()];
    } else {
      parms = new Object[querymap.size() + args.length];
      for (Object arg : args) {
        parms[i++] = arg;
      }
    }
    for (String key : querymap.keySet()) {
      psql.append(" and ");
      psql.append(key);
      psql.append(" like ? ");

      csql.append(" and ");
      csql.append(key);
      csql.append(" like ? ");

      parms[i++] = "%" + String.valueOf(querymap.get(key)) + "%";
    }
    return parms;
  }