Java StringBuilder.capacity Examples

Java StringBuilder.capacity - 19 examples found. These are the top rated real world Java examples of StringBuilder.capacity extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 /**
  * Bietet der hoster eine Möglichkeit mehrere links gleichzeitig zu prüfen, kann das über diese
  * Funktion gemacht werden.
  */
 @Override
 public boolean checkLinks(final DownloadLink[] urls) {
   if (urls == null || urls.length == 0) {
     return false;
   }
   try {
     if (Rapidshare.RS_API_WAIT > System.currentTimeMillis()) {
       for (final DownloadLink u : urls) {
         u.setAvailable(true);
         u.getLinkStatus()
             .setStatusText(
                 JDL.L("plugin.host.rapidshare.status.apiflood", "unchecked (API Flood)"));
       }
       return true;
     }
     logger.finest("OnlineCheck: " + urls.length + " links");
     final StringBuilder idlist = new StringBuilder();
     final StringBuilder namelist = new StringBuilder();
     final ArrayList<DownloadLink> links = new ArrayList<DownloadLink>();
     int size = 0;
     for (final DownloadLink u : urls) {
       if (size > 3000) {
         logger.finest("OnlineCheck: SplitCheck " + links.size() + "/" + urls.length + " links");
         /* do not stop here because we are not finished yet */
         this.checkLinksIntern2(links);
         links.clear();
         idlist.delete(0, idlist.capacity());
         namelist.delete(0, namelist.capacity());
       }
       /* workaround reset */
       u.setProperty("htmlworkaround", null);
       idlist.append(",").append(Rapidshare.getID(u.getDownloadURL()));
       namelist.append(",").append(this.getName(u));
       links.add(u);
       size =
           ("https://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles&files="
                   + idlist.toString().substring(1)
                   + "&filenames="
                   + namelist.toString().substring(1)
                   + "&incmd5=1")
               .length();
     }
     if (links.size() != 0) {
       if (links.size() != urls.length) {
         logger.finest("OnlineCheck: SplitCheck " + links.size() + "/" + urls.length + " links");
       } else {
         logger.finest("OnlineCheck: Check " + urls.length + " links");
       }
       if (!this.checkLinksIntern2(links)) {
         return false;
       }
     }
   } catch (final Exception e) {
     e.printStackTrace();
     return false;
   }
   return true;
 }
  /** Prints 36. */
  private static void testStrinBuilderCapacity() {
    String str = "DataDataDataDataData"; // 20 chars

    StringBuilder sb = new StringBuilder();
    System.out.println(sb.capacity()); // 16

    sb = new StringBuilder(str);
    sb.delete(0, sb.length());
    System.out.println(sb.capacity()); // 20 + 16 = 36
  }
  @Override
  public ArrayList<String> getIdentifiers(Context context, T dso) {
    ArrayList<String> identifiers = new ArrayList<>();

    IdentifierService identifierService = new DSpace().getSingletonService(IdentifierService.class);

    if (identifierService != null) {
      identifiers.addAll(identifierService.lookup(context, dso));
    } else {
      log.warn("No IdentifierService found, will return an list containing " + "the Handle only.");
      if (dso.getHandle() != null) {
        identifiers.add(handleService.getCanonicalForm(dso.getHandle()));
      }
    }

    if (log.isDebugEnabled()) {
      StringBuilder dbgMsg = new StringBuilder();
      for (String id : identifiers) {
        if (dbgMsg.capacity() == 0) {
          dbgMsg.append("This DSO's Identifiers are: ");
        } else {
          dbgMsg.append(", ");
        }
        dbgMsg.append(id);
      }
      dbgMsg.append(".");
      log.debug(dbgMsg.toString());
    }

    return identifiers;
  }
 @Test
 public void test18() throws Exception {
   HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("stringBuilder");
   StringBuilder b = (StringBuilder) installedBenchmarkCode.executeVarargs();
   Assert.assertTrue(b.capacity() == 16);
   Assert.assertTrue(b.length() == 0);
 }
Example #5
0
 @Override
 public boolean checkLinks(final DownloadLink[] urls) {
   if (urls == null || urls.length == 0) {
     return false;
   }
   try {
     final Browser br = new Browser();
     prepBrowser(br);
     br.setCookiesExclusive(true);
     final StringBuilder sb = new StringBuilder();
     final ArrayList<DownloadLink> links = new ArrayList<DownloadLink>();
     int index = 0;
     while (true) {
       links.clear();
       while (true) {
         /* we test 50 links at once */
         if (index == urls.length || links.size() > 50) {
           break;
         }
         links.add(urls[index]);
         index++;
       }
       sb.delete(0, sb.capacity());
       sb.append("op=checkfiles&process=Check+URLs&list=");
       for (final DownloadLink dl : links) {
         sb.append(dl.getDownloadURL());
         sb.append("%0A");
       }
       br.postPage("http://qtyfiles.com/?op=checkfiles", sb.toString());
       for (final DownloadLink dllink : links) {
         if (br.containsHTML(
             ">" + dllink.getDownloadURL() + "</td><td style=\"color:red;\">Not found\\!</td>")) {
           dllink.setAvailable(false);
         } else {
           final String[][] linkInformation =
               br.getRegex(
                       ">"
                           + dllink.getDownloadURL()
                           + "</td><td style=\"color:green;\">Found</td><td>([^<>\"]*?)</td>")
                   .getMatches();
           if (linkInformation == null) {
             logger.warning("Linkchecker broken for qtyfiles.com");
             return false;
           }
           String name = extractFileNameFromURL(dllink.getDownloadURL());
           final String size = linkInformation[0][0];
           dllink.setAvailable(true);
           dllink.setName(Encoding.htmlDecode(name).replace(".html", ""));
           dllink.setDownloadSize(SizeFormatter.getSize(size));
         }
       }
       if (index == urls.length) {
         break;
       }
     }
   } catch (final Exception e) {
     return false;
   }
   return true;
 }
  static void printStringBuilder(StringBuilder sb) {
    String str = sb.toString();
    // 버퍼의 문자열을 String 객체로 만들어서 리턴하는 메소오오드

    int len = sb.length();
    // 버퍼의 문자열 길이를 리턴하는 메소드

    int bufsize = sb.capacity();
    System.out.printf("%s(%d): %d %n", str, len, bufsize);
  }