[apache-rat-pd] r59 committed - Function for generating URLs with maximum length(but not longer then c...

0 views
Skip to first unread message

codesite...@google.com

unread,
Sep 6, 2009, 7:07:00 PM9/6/09
to apache-rat...@googlegroups.com
Revision: 59
Author: maka82
Date: Sun Sep 6 16:06:18 2009
Log: Function for generating URLs with maximum length(but not longer then
current limitation of 1024) is rewritten. It is much simpler now.
http://code.google.com/p/apache-rat-pd/source/detail?r=59

Modified:

/trunk/src/main/java/org/apache/rat/pd/engines/google/GoogleCodeSearchParser.java

=======================================
---
/trunk/src/main/java/org/apache/rat/pd/engines/google/GoogleCodeSearchParser.java
Sun Sep 6 14:59:36 2009
+++
/trunk/src/main/java/org/apache/rat/pd/engines/google/GoogleCodeSearchParser.java
Sun Sep 6 16:06:18 2009
@@ -59,7 +59,7 @@
// numberOfRetry maximum number of retry before give up
public static final int NUMBER_OF_RETRY = 5;
// 2324 is too long
- public static final int CODESEARCH_QUERY_MAX_LENGTH = 1024;
+ public static final int CODESEARCH_QUERY_MAX_LENGTH = 2000;

private static final String CODESEARCH_FEEDS_URL
= "http://www.google.com/codesearch/feeds/search?";

@@ -253,32 +253,31 @@
*/
List<URL> fitCodeLinesIntoUrls(List<String> lines, int maxLength)
throws IOException {
List<URL> toRet = new ArrayList<URL>();
- URL url = null;
-
- int i = 0;
- int j = 0;
-
- while (i < lines.size()) {
- while (j < lines.size()) {
- StringBuffer currenCodePart = combineLines(lines, i, j);
- URL currentUrl = createUrl(currenCodePart.toString());
-
- if (currentUrl.toString().length() <= maxLength) {
- url = currentUrl;
- j++;
- } else {
- i = j;
- break;
+ URL current = null;
+ URL temp = null;
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < lines.size(); i++) {
+ sb.append(lines.get(i));
+ // carriage return must be inserted between each two lines
+ if (i != lines.size() - 1) {
+ sb.append("\n");
+ }
+ temp = createUrl(sb.toString());
+
+ if (temp.toString().length() <= maxLength) {
+ current = temp;
+ } else {
+ toRet.add(current);
+ sb.setLength(0);
+ sb.append(lines.get(i));
+ // carriage return must be inserted between each two lines
+ if (i != lines.size() - 1) {
+ sb.append("\n");
}
}
- if (url != null) {
- toRet.add(url);
- url = null;
- }
- if (j == lines.size()) {
- break;
- }
- }
+ }
+ toRet.add(createUrl(sb.toString()));
return toRet;
}

Reply all
Reply to author
Forward
0 new messages