Browse Source

Tidy up downloader code

master
Chris Smith 15 years ago
parent
commit
9db70dddf1

+ 1
- 1
nbproject/coverage.properties View File

@@ -1,5 +1,5 @@
1 1
 #coverage viewer module properties for project
2
-#Tue Jan 06 09:54:06 GMT 2009
2
+#Tue Jan 06 10:02:47 GMT 2009
3 3
 coverage.activity=ON
4 4
 project.type=java
5 5
 coverage.templateFile=coverage/template.emma

+ 1
- 1
nbproject/project.properties View File

@@ -73,7 +73,7 @@ run.jvmargs=
73 73
 run.test.classpath=\
74 74
     ${javac.test.classpath}:\
75 75
     ${build.test.classes.dir}:\
76
-    ${file.reference.emma.jar}
76
+    :${file.reference.emma.jar}
77 77
 source.encoding=UTF-8
78 78
 src.dir=src
79 79
 test.src.dir=test

+ 8
- 19
src/uk/co/md87/evetool/api/io/ApiDownloader.java View File

@@ -69,27 +69,16 @@ public class ApiDownloader {
69 69
 
70 70
         final CacheStatus cacheStatus = cache.getCacheStatus(method, args);
71 71
 
72
-        if (cacheStatus == CacheStatus.HIT) {
73
-            return cache.getCache(method, args);
74
-        }
75
-
76
-        try {
77
-            final StringBuilder builder = new StringBuilder();
78
-            for (String line : Downloader.getPage(getUrl(method), ourArgs)) {
79
-                builder.append(line);
80
-            }
81
-
82
-            cache.setCache(method, args, builder.toString(),
83
-                    System.currentTimeMillis() + 20000); // TODO: Proper time
84
-            return cache.getCache(method, args);
85
-        } catch (IOException ex) {
86
-            LOGGER.log(Level.WARNING, "API request failed", ex);
87
-            if (cacheStatus == CacheStatus.EXPIRED) {
88
-                return cache.getCache(method, args);
89
-            } else {
90
-                return null;
72
+        if (cacheStatus == CacheStatus.MISS || cacheStatus == CacheStatus.EXPIRED) {
73
+            try {
74
+                cache.setCache(method, args, Downloader.getPage(getUrl(method), ourArgs),
75
+                        System.currentTimeMillis() + 20000); // TODO: Proper time
76
+            } catch (IOException ex) {
77
+                LOGGER.log(Level.WARNING, "API request failed", ex);
91 78
             }
92 79
         }
80
+
81
+        return cache.getCache(method, args);
93 82
     }
94 83
 
95 84
     protected static String getUrl(final String method) {

+ 10
- 8
src/uk/co/md87/evetool/api/io/Downloader.java View File

@@ -58,7 +58,7 @@ public final class Downloader {
58 58
      * @throws java.net.MalformedURLException If the URL is malformed
59 59
      * @throws java.io.IOException If there's an I/O error while downloading
60 60
      */
61
-    public static List<String> getPage(final String url)
61
+    public static String getPage(final String url)
62 62
             throws MalformedURLException, IOException {
63 63
         
64 64
         return getPage(url, "");
@@ -66,17 +66,18 @@ public final class Downloader {
66 66
 
67 67
     /**
68 68
      * Retrieves the specified page, sending the specified post data.
69
-     * 
69
+     *
70
+     * TODO: Update
70 71
      * @param url The URL to retrieve
71 72
      * @param postData The raw POST data to send
72 73
      * @return A list of lines received from the server
73 74
      * @throws java.net.MalformedURLException If the URL is malformed
74 75
      * @throws java.io.IOException If there's an I/O error while downloading
75 76
      */    
76
-    public static List<String> getPage(final String url, final String postData)
77
+    public static String getPage(final String url, final String postData)
77 78
             throws MalformedURLException, IOException {
78 79
         
79
-        final List<String> res = new ArrayList<String>();
80
+        final StringBuilder res = new StringBuilder();
80 81
         
81 82
         final URLConnection urlConn = getConnection(url, postData);
82 83
         
@@ -89,25 +90,26 @@ public final class Downloader {
89 90
             line = in.readLine();
90 91
             
91 92
             if (line != null) {
92
-                res.add(line);
93
+                res.append(line);
93 94
             }
94 95
         } while (line != null);
95 96
         
96 97
         in.close();
97 98
         
98
-        return res;
99
+        return res.toString();
99 100
     }
100 101
     
101 102
     /**
102 103
      * Retrieves the specified page, sending the specified post data.
103
-     * 
104
+     *
105
+     * TODO: Update
104 106
      * @param url The URL to retrieve
105 107
      * @param postData A map of post data that should be sent
106 108
      * @return A list of lines received from the server
107 109
      * @throws java.net.MalformedURLException If the URL is malformed
108 110
      * @throws java.io.IOException If there's an I/O error while downloading
109 111
      */    
110
-    public static List<String> getPage(final String url, final Map<String, String> postData)
112
+    public static String getPage(final String url, final Map<String, String> postData)
111 113
             throws MalformedURLException, IOException {        
112 114
         return getPage(url, encodeArguments(postData));
113 115
     }

+ 1
- 0
src/uk/co/md87/evetool/api/parser/ApiParser.java View File

@@ -8,6 +8,7 @@ package uk.co.md87.evetool.api.parser;
8 8
 import java.io.IOException;
9 9
 import java.io.StringReader;
10 10
 import java.util.List;
11
+
11 12
 import org.jdom.Document;
12 13
 import org.jdom.Element;
13 14
 import org.jdom.JDOMException;

Loading…
Cancel
Save