ArrayList<ArrayList<String>> data = getData(t);
- if (uploadToYarrg) {
+ if (uploadToYarrg && yarrgts != null) {
pm.setNote("Preparing data for Yarrg");
pm.setProgress(10);
writeBuySellOffers(buys,sells,offerCount,out);
out.finish();
InputStream in = sendInitialData(new ByteArrayInputStream(outStream.toByteArray()));
+ if (in == null) return;
pm.setProgress(80);
if(pm.isCanceled()) {
return;
writeOffers(out,sells);
}
+ private String readstreamstring(InputStream in) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ String str;
+ while((str = br.readLine()) != null) {
+ sb.append(str+"\n");
+ }
+ return sb.toString();
+ }
+
/**
* Sends the data to the server via multipart-formdata POST,
* with the gzipped data as a file upload.
private InputStream sendInitialData(InputStream file) throws IOException {
ClientHttpRequest http = new ClientHttpRequest(PCTB_HOST_URL + "upload.php");
http.setParameter("marketdata","marketdata.gz",file,"application/gzip");
- return http.post();
+ if (!http.post()) {
+ String err = readstreamstring(http.resultstream());
+ error("Error sending initial data:\n"+err);
+ return null;
+ }
+ return http.resultstream();
}
/**
* @param in stream of data from the server to read
*/
private void finishUpload(InputStream in) throws IOException {
- StringBuilder sb = new StringBuilder();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String str;
- while((str = br.readLine()) != null) {
- sb.append(str+"\n");
- }
- String html = sb.toString();
+ String html = readstreamstring(in);
//System.out.println(html);
String topIsland = "0", ocean, islandNum, action, forceReload, filename;
Matcher m;
filename = m.group(3);
URL get = new URL(PCTB_HOST_URL + "upload.php?topisland=" + topIsland + "&ocean=" + ocean + "&island="
+ islandNum + "&action=" + action + "&forcereload=" + forceReload + "&filename=" + filename);
- // System.out.println(get);
- BufferedReader br2 = new BufferedReader(new InputStreamReader(get.openStream()));
- sb = new StringBuilder();
- while((str = br2.readLine()) != null) {
- sb.append(str+"\n");
- }
+ String complete = readstreamstring(get.openStream());
Pattern done = Pattern.compile("Your data has been integrated into the database. Thank you!");
- m = done.matcher(sb.toString());
+ m = done.matcher(complete);
if(m.find()) {
//System.out.println("FILE upload successful!!!");
} else {
- error_html("Something was wrong with the final upload parameters!", html);
+ error_html("Something was wrong with the final upload parameters!", complete);
}
}
+ private InputStream post_for_yarrg(ClientHttpRequest http) throws IOException {
+ if (!http.post()) {
+ String err = readstreamstring(http.resultstream());
+ error("<html><h1>Error reported by YARRG server</h1>\n" + err);
+ return null;
+ }
+ return http.resultstream();
+ }
+
private String getYarrgTimestamp() throws IOException {
ClientHttpRequest http = new ClientHttpRequest (YARRG_URL);
http.setParameter("clientname", YARRG_CLIENTNAME);
http.setParameter("clientversion", YARRG_CLIENTVERSION);
http.setParameter("clientfixes", YARRG_CLIENTFIXES);
http.setParameter("requesttimestamp", "y");
- InputStream in = http.post();
+ InputStream in = post_for_yarrg(http);
+ if (in == null) return null;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String tsresult = br.readLine();
return tsresult.substring(3, tsresult.length()-1);
http.setParameter("ocean", ocean);
http.setParameter("island", island);
http.setParameter("data", "deduped.tsv.gz", file, "application/octet-stream");
- InputStream in = http.post();
+ InputStream in = post_for_yarrg(http);
+ if (in == null) return;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String yarrgresult;
while((yarrgresult = br.readLine()) != null) {