add CommonRequest.timeout
This commit is contained in:
@ -29,6 +29,11 @@ public class CommonRequest {
|
||||
return new CommonRequest(Request.post(url));
|
||||
}
|
||||
|
||||
public CommonRequest timeout(long ms) {
|
||||
request.connectTimeout(Timeout.ofMilliseconds(ms)).responseTimeout(Timeout.ofMilliseconds(ms));
|
||||
return this;
|
||||
}
|
||||
|
||||
public String asString() throws IOException {
|
||||
return request.execute().returnContent().asString();
|
||||
}
|
||||
|
||||
@ -34,6 +34,12 @@ public class FileRequest extends CommonRequest {
|
||||
return new FileRequest(Request.post(url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileRequest timeout(long ms) {
|
||||
super.timeout(ms);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void toFile(String path, String fileName) throws IOException, NoPermissionException {
|
||||
toFile(new File(IO.fitPath(path) + fileName));
|
||||
}
|
||||
|
||||
@ -46,6 +46,12 @@ public class GsonRequest extends CommonRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GsonRequest timeout(long ms) {
|
||||
super.timeout(ms);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GsonRequest body(Object object) {
|
||||
request.bodyString(getGson().toJson(object), ContentType.APPLICATION_JSON);
|
||||
return this;
|
||||
|
||||
@ -42,6 +42,12 @@ public class ProgressiveRequest extends FileRequest {
|
||||
return new ProgressiveRequest(Request.post(url), callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressiveRequest timeout(long ms) {
|
||||
super.timeout(ms);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toFile(Path outputPath) throws IOException, NoPermissionException {
|
||||
processResponse(request.execute(), IO.getOutputStream(outputPath.toFile()));
|
||||
|
||||
@ -28,6 +28,12 @@ public class TimiRequest extends GsonRequest {
|
||||
return new TimiRequest(Request.post(url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiRequest timeout(long ms) {
|
||||
super.timeout(ms);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiRequest body(Object object) {
|
||||
super.body(object);
|
||||
|
||||
Reference in New Issue
Block a user