1 package net.sf.openrocket.communication;
3 import java.io.UnsupportedEncodingException;
4 import java.net.HttpURLConnection;
5 import java.net.URLEncoder;
7 public abstract class Communicator {
9 protected static final String BUG_REPORT_URL;
11 protected static final String UPDATE_INFO_URL;
15 url = System.getProperty("openrocket.debug.bugurl");
17 url = "http://openrocket.sourceforge.net/actions/reportbug";
20 url = System.getProperty("openrocket.debug.updateurl");
22 url = "http://openrocket.sourceforge.net/actions/updates";
23 UPDATE_INFO_URL = url;
27 protected static final String VERSION_PARAM = "version";
30 protected static final String BUG_REPORT_PARAM = "content";
31 protected static final int BUG_REPORT_RESPONSE_CODE = HttpURLConnection.HTTP_ACCEPTED;
32 protected static final int CONNECTION_TIMEOUT = 10000; // in milliseconds
34 protected static final int UPDATE_INFO_UPDATE_AVAILABLE = HttpURLConnection.HTTP_OK;
35 protected static final int UPDATE_INFO_NO_UPDATE_CODE = HttpURLConnection.HTTP_NO_CONTENT;
36 protected static final String UPDATE_INFO_CONTENT_TYPE = "text/plain";
38 // Limit the number of bytes that can be read from the server
39 protected static final int MAX_INPUT_BYTES = 20000;
42 protected static ConnectionSource connectionSource = new DefaultConnectionSource();
46 * Set the source of the network connections. This can be used for unit testing.
47 * By default the source is a DefaultConnectionSource.
49 * @param source the source of the connections.
51 public static void setConnectionSource(ConnectionSource source) {
52 connectionSource = source;
57 * URL-encode the specified string in UTF-8 encoding.
59 * @param str the string to encode (null ok)
60 * @return the encoded string or "null"
62 public static String encode(String str) {
66 return URLEncoder.encode(str, "UTF-8");
67 } catch (UnsupportedEncodingException e) {
68 throw new RuntimeException("Unsupported encoding UTF-8", e);