Compare commits

..

3 Commits

Author SHA1 Message Date
f3623d03a2 support deploy nexus 2025-10-13 10:53:17 +08:00
e63d1103d8 add ProgressRequestTest 2025-10-13 10:53:00 +08:00
016c0b7e2f rename FormMap to ArgMap then support url arg 2025-10-13 10:52:48 +08:00
4 changed files with 119 additions and 2 deletions

58
pom.xml
View File

@ -16,6 +16,64 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>timi_nexus</id>
<url>https://nexus.imyeyu.com/repository/maven-releases/</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>timi_nexus</id>
<url>https://nexus.imyeyu.com/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.imyeyu.io</groupId>

View File

@ -1,5 +1,6 @@
package com.imyeyu.network;
import com.imyeyu.utils.Encoder;
import org.apache.hc.client5.http.fluent.Form;
import org.apache.hc.core5.http.NameValuePair;
@ -13,13 +14,27 @@ import java.util.Map;
* @author 夜雨
* @since 2025-06-26 15:41
*/
public class FormMap<K, V> extends HashMap<K, V> {
public class ArgMap<K, V> extends HashMap<K, V> {
public List<NameValuePair> build() {
public List<NameValuePair> toNameValuePair() {
Form form = Form.form();
for (Map.Entry<K, V> item : entrySet()) {
form.add(item.getKey().toString(), item.getValue().toString());
}
return form.build();
}
public String toURL() {
StringBuilder sb = new StringBuilder();
for (Map.Entry<K, V> item : entrySet()) {
sb.append(item.getKey().toString()).append('=').append(Encoder.urlArg(item.getValue().toString()));
sb.append('&');
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
public String toURL(String url) {
return url + "?" + toURL();
}
}

View File

@ -42,10 +42,12 @@ public class ProgressiveRequest extends FileRequest {
return new ProgressiveRequest(Request.post(url), callback);
}
@Override
public void toFile(Path outputPath) throws IOException, NoPermissionException {
processResponse(request.execute(), IO.getOutputStream(outputPath.toFile()));
}
@Override
public void toFile(File file) throws IOException, NoPermissionException {
processResponse(request.execute(), IO.getOutputStream(file));
}
@ -55,6 +57,7 @@ public class ProgressiveRequest extends FileRequest {
return new String(asBytes());
}
@Override
public byte[] asBytes() throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
processResponse(request.execute(), os);

View File

@ -0,0 +1,41 @@
package com.imyeyu.network.test;
import com.imyeyu.io.IOSize;
import com.imyeyu.network.FileRequest;
import com.imyeyu.network.ProgressiveRequest;
import org.apache.hc.client5.http.fluent.Request;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpResponse;
import org.junit.Test;
/**
* @author 夜雨
* @since 2025-07-14 15:30
*/
public class ProgressRequestTest {
private static final String URL1 = "http://localhost:8091/system/file/download/video/test92MB.mp4?key=GS60MF78GbPhImiCN4fsi3T2E5tDfP1scxufVhbuccaxldba0okpQPgKq4ntyr0J";
private static final String URL2 = "https://git.imyeyu.com/test92MB.mp4";
private static final String URL3 = "http://localhost:8092/test/download";
@Test
public void testGet() throws Exception {
ProgressiveRequest.get(URL1, (total, read, now) -> {
System.out.println(1D * read / total);
return true;
}).asBytes();
}
@Test
public void testLength() throws Exception {
long length = FileRequest.wrap(Request.head(URL2)).length();
System.out.println(IOSize.format(length));
}
@Test
public void testLength2() throws Exception {
HttpResponse response = Request.head(URL3).execute().returnResponse();
final Header contentLengthHeader = response.getHeader("Content-Length");
System.out.println(contentLengthHeader.getValue());
}
}