1 package net.sf.openrocket.communication;
3 import java.io.UnsupportedEncodingException;
4 import java.net.HttpURLConnection;
5 import java.net.URLEncoder;
7 import net.sf.openrocket.util.BugException;
9 public abstract class Communicator {
11 protected static final String BUG_REPORT_URL;
13 protected static final String UPDATE_INFO_URL;
17 url = System.getProperty("openrocket.debug.bugurl");
19 url = "http://openrocket.sourceforge.net/actions/reportbug";
22 url = System.getProperty("openrocket.debug.updateurl");
24 url = "http://openrocket.sourceforge.net/actions/updates";
25 UPDATE_INFO_URL = url;
29 protected static final String VERSION_PARAM = "version";
32 protected static final String BUG_REPORT_PARAM = "content";
33 protected static final int BUG_REPORT_RESPONSE_CODE = HttpURLConnection.HTTP_ACCEPTED;
34 protected static final int CONNECTION_TIMEOUT = 10000; // in milliseconds
36 protected static final int UPDATE_INFO_UPDATE_AVAILABLE = HttpURLConnection.HTTP_OK;
37 protected static final int UPDATE_INFO_NO_UPDATE_CODE = HttpURLConnection.HTTP_NO_CONTENT;
38 protected static final String UPDATE_INFO_CONTENT_TYPE = "text/plain";
40 // Limit the number of bytes that can be read from the server
41 protected static final int MAX_INPUT_BYTES = 20000;
44 protected static ConnectionSource connectionSource = new DefaultConnectionSource();
48 * Set the source of the network connections. This can be used for unit testing.
49 * By default the source is a DefaultConnectionSource.
51 * @param source the source of the connections.
53 public static void setConnectionSource(ConnectionSource source) {
54 connectionSource = source;
59 * URL-encode the specified string in UTF-8 encoding.
61 * @param str the string to encode (null ok)
62 * @return the encoded string or "null"
64 public static String encode(String str) {
68 return URLEncoder.encode(str, "UTF-8");
69 } catch (UnsupportedEncodingException e) {
70 throw new BugException("Unsupported encoding UTF-8", e);