项目作者: Ushiosan23

项目描述 :
Network utilities for JVM platform
高级语言: Java
项目地址: git://github.com/Ushiosan23/JVM_NetworkUtils.git
创建时间: 2020-10-19T14:31:16Z
项目社区:https://github.com/Ushiosan23/JVM_NetworkUtils

开源协议:MIT License

下载


JVM Network Utils

Utilities used to manage network actions in JVM (Java Virtual Machine).

Feature status

  • :ballot_box_with_check: Complete
  • :white_square_button: Partial complete
  • :black_square_button: Incomplete

Features

  • Make Http request
    • :ballot_box_with_check: GET
      • :ballot_box_with_check: Sync
      • :ballot_box_with_check: Async
      • :ballot_box_with_check: Coroutines
    • :ballot_box_with_check: POST
      • :ballot_box_with_check: Sync
      • :ballot_box_with_check: Async
      • :ballot_box_with_check: Coroutines
    • :ballot_box_with_check: PUT
      • :ballot_box_with_check: Sync
      • :ballot_box_with_check: Async
      • :ballot_box_with_check: Coroutines
    • PATCH
      • Sync
      • Async
      • Coroutines
    • :ballot_box_with_check: DELETE
      • :ballot_box_with_check: Sync
      • :ballot_box_with_check: Async
      • :ballot_box_with_check: Coroutines
  • Download resources from server
    • :ballot_box_with_check: Get percentage of download
    • :ballot_box_with_check: Calculate file size
    • :ballot_box_with_check: Real time download status
    • :ballot_box_with_check: Cancel download
    • :white_square_button: Pause download (Partial)
      • Resume download
  • :white_square_button: Upload files to server
    • Get percentage of upload
    • Calculate time
    • Real time download status

Problems

It’s not possible to upload large files. I’m working to fix this problem. If you know how to upload large files by
chunks you can fork this repo and make a pull request.

Any help is good. 👌😁

Download

You can download jar file from Release section or put in your gradle project the next code:

Groovy DSL

  1. repositories {
  2. mavenCentral()
  3. }
  4. dependencies {
  5. implementation "com.github.ushiosan23:networkutils:0.0.4"
  6. }

Kotlin DSL

  1. repositories {
  2. mavenCentral()
  3. }
  4. dependencies {
  5. implementation("com.github.ushiosan23:networkutils:0.0.4")
  6. }

Maven POM File

  1. <dependencies>
  2. <dependency>
  3. <groupId>com.github.ushiosan23</groupId>
  4. <artifactId>networkutils</artifactId>
  5. <version>0.0.4</version>
  6. </dependency>
  7. </dependencies>

How to use

Simple http request

  • Java
  1. import com.github.ushiosan23.networkutils.http.HttpRequestAction;
  2. class SimpleHttpRequest {
  3. HttpRequestAction action = new HttpRequestAction("https://api.github.com/users/Ushiosan23");
  4. // Create asynchronous request
  5. public void makeSyncRequest() throws Exception {
  6. System.out.println(action.get().body());
  7. }
  8. // Create asynchronous request
  9. public void makeAsyncRequest() {
  10. // Action always return the same action
  11. action.getAsync(action -> {
  12. System.out.println(action.body());
  13. return action;
  14. });
  15. }
  16. public static void main(String[] args) throws Exception {
  17. SimpleHttpRequest request = new SimpleHttpRequest();
  18. request.makeAsyncRequest();
  19. request.makeSyncRequest();
  20. Thread.sleep(5000);
  21. }
  22. }
  • Kotlin
  1. import com.github.ushiosan23.networkutils.http.HttpRequestAction
  2. fun main() {
  3. val request = HttpRequestAction("https://api.github.com/users/Ushiosan23")
  4. // Asynchronous request
  5. request.getAsync { action ->
  6. println(action.body())
  7. return@getAsync action
  8. }
  9. // Synchronous request
  10. println(request.get().body())
  11. Thread.sleep(5000)
  12. }
  • Kotlin Coroutines
  1. import com.github.ushiosan23.networkutils.http.HttpRequestAction
  2. import com.github.ushiosan23.networkutils.http.getAsyncC
  3. suspend fun main() {
  4. val request = HttpRequestAction("https://api.github.com/users/Ushiosan23")
  5. // Asynchronous request with coroutines
  6. println(request.getAsyncC().body())
  7. // Synchronous request
  8. println(request.get().body())
  9. }