This repository was archived by the owner on Jan 5, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/com/scorpiac/javarant Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ public class DevRant {
4747 static final String API_NOTIFS = API_USERS + "/me/notif-feed" ;
4848
4949 private Auth auth ;
50+ private int timeout = 15000 ;
5051
5152 /**
5253 * Log in to devRant.
@@ -381,11 +382,11 @@ private List<NameValuePair> getParameters(NameValuePair... params) {
381382 * @param request The request to execute.
382383 * @return A {@link JsonObject} containing the response.
383384 */
384- private static JsonObject executeRequest (Request request ) {
385+ private JsonObject executeRequest (Request request ) {
385386 // Make the request and get the returned content as a stream.
386387 InputStream stream ;
387388 try {
388- stream = request .execute ().returnContent ().asStream ();
389+ stream = request .socketTimeout ( timeout ). connectTimeout ( timeout ). execute ().returnContent ().asStream ();
389390 } catch (IOException e ) {
390391 e .printStackTrace ();
391392 return null ;
@@ -399,4 +400,20 @@ private static JsonObject executeRequest(Request request) {
399400 return null ;
400401 }
401402 }
403+
404+ /**
405+ * Set the request timeout. This timeout will be used for the socket and connection timeout.
406+ *
407+ * @param timeout The timeout in milliseconds to set, or -1 to set no timeout.
408+ */
409+ public void setRequestTimeout (int timeout ) {
410+ this .timeout = timeout ;
411+ }
412+
413+ /**
414+ * Get the current request timeout in milliseconds.
415+ */
416+ public int getRequestTimeout () {
417+ return timeout ;
418+ }
402419}
You can’t perform that action at this time.
0 commit comments