import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;
import java.util.zip.GZIPOutputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;
import java.util.zip.GZIPOutputStream;
private JFrame frame = null;
private Window window = null;
private JButton findMarket = null;
private JFrame frame = null;
private Window window = null;
private JButton findMarket = null;
private final static String PCTB_LIVE_HOST_URL = "http://pctb.crabdance.com/";
private final static String PCTB_TEST_HOST_URL = "http://pctb.ilk.org/";
private final static String PCTB_LIVE_HOST_URL = "http://pctb.crabdance.com/";
private final static String PCTB_TEST_HOST_URL = "http://pctb.ilk.org/";
//frame.setPreferredSize(new Dimension(200, 60));
findMarket = new JButton("Upload Market Data");
//frame.setPreferredSize(new Dimension(200, 60));
findMarket = new JButton("Upload Market Data");
ProgressMonitor pm = new ProgressMonitor(frame,"Processing Market Data","Getting table data",0,100);
pm.setMillisToDecideToPopup(0);
pm.setMillisToPopup(0);
ProgressMonitor pm = new ProgressMonitor(frame,"Processing Market Data","Getting table data",0,100);
pm.setMillisToDecideToPopup(0);
pm.setMillisToPopup(0);
- runYarrg(yarrgts, oceanName, islandName, yarrgdata);
+ doneyarrg = runYarrg(yarrgts, oceanName, islandName, yarrgdata);
writeBuySellOffers(buys,sells,offerCount,out);
out.finish();
InputStream in = sendInitialData(new ByteArrayInputStream(outStream.toByteArray()));
writeBuySellOffers(buys,sells,offerCount,out);
out.finish();
InputStream in = sendInitialData(new ByteArrayInputStream(outStream.toByteArray()));
+
+ if ((uploadToPCTB && !donepctb) ||
+ (uploadToYarrg && !doneyarrg)) {
+ resultSummary.setText("trouble");
+ } else if (donepctb || doneyarrg) {
+ resultSummary.setText("Done " + islandName);
+ } else {
+ resultSummary.setText("uploaded nowhere!");
+ }
+ 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.
/**
* 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");
private InputStream sendInitialData(InputStream file) throws IOException {
ClientHttpRequest http = new ClientHttpRequest(PCTB_HOST_URL + "upload.php");
http.setParameter("marketdata","marketdata.gz",file,"application/gzip");
- 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();
+ private boolean finishUpload(InputStream in) throws IOException {
+ String html = readstreamstring(in);
//System.out.println(html);
String topIsland = "0", ocean, islandNum, action, forceReload, filename;
Matcher m;
//System.out.println(html);
String topIsland = "0", ocean, islandNum, action, forceReload, filename;
Matcher m;
JOptionPane.QUESTION_MESSAGE, null, myOceansList, null);
if(option == null) {
error_html("Unable to determine the current island!", html);
JOptionPane.QUESTION_MESSAGE, null, myOceansList, null);
if(option == null) {
error_html("Unable to determine the current island!", html);
m = oceanIslandNum.matcher(html);
if(!m.find()) {
error_html("This does not seem to be a valid island! Unable to upload.", html);
m = oceanIslandNum.matcher(html);
if(!m.find()) {
error_html("This does not seem to be a valid island! Unable to upload.", html);
}
action = m.group(1);
forceReload = m.group(2);
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);
}
action = m.group(1);
forceReload = m.group(2);
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());
+ 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");
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");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String tsresult = br.readLine();
return tsresult.substring(3, tsresult.length()-1);
}
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String tsresult = br.readLine();
return tsresult.substring(3, tsresult.length()-1);
}
- private void runYarrg(String timestamp, String ocean, String island, String yarrgdata) throws IOException {
+ private boolean runYarrg(String timestamp, String ocean, String island, String yarrgdata) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedOutputStream bufos = new BufferedOutputStream(new GZIPOutputStream(bos));
bufos.write(yarrgdata.getBytes() );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedOutputStream bufos = new BufferedOutputStream(new GZIPOutputStream(bos));
bufos.write(yarrgdata.getBytes() );
http.setParameter("ocean", ocean);
http.setParameter("island", island);
http.setParameter("data", "deduped.tsv.gz", file, "application/octet-stream");
http.setParameter("ocean", ocean);
http.setParameter("island", island);
http.setParameter("data", "deduped.tsv.gz", file, "application/octet-stream");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String yarrgresult;
while((yarrgresult = br.readLine()) != null) {
System.out.println(yarrgresult);
}
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String yarrgresult;
while((yarrgresult = br.readLine()) != null) {
System.out.println(yarrgresult);
}