Skip to content

Commit f46119f

Browse files
committed
提交删除代码
1 parent e708a59 commit f46119f

13 files changed

Lines changed: 528 additions & 166 deletions

File tree

build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</jar>
4646
</target>
4747

48-
<target name="test" depends="compile,dist">
48+
<!--<target name="test" depends="compile,dist">
4949
<junit printsummary="yes" fork="true" haltonfailure="yes">
5050
<jvmarg value="-Xmx1g"/>
5151
<classpath>
@@ -60,7 +60,7 @@
6060
<formatter type="xml"/>
6161
</test>
6262
</junit>
63-
</target>
63+
</target>-->
6464

6565
<target name="clean" description="clean up">
6666
<delete dir="${build}"/>

java-udfs-api.iml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@
2323
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
2424
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
2525
<orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" level="project" />
26-
<orderEntry type="module-library">
27-
<library name="Maven: io.udfs.api:ulord-java-sdk:0.0.1">
28-
<CLASSES>
29-
<root url="jar://$MODULE_DIR$/lib/ulord-java-sdk-1.0.0.jar!/" />
30-
</CLASSES>
31-
<JAVADOC />
32-
<SOURCES />
33-
</library>
34-
</orderEntry>
26+
<orderEntry type="library" name="Maven: com.github.qiniu:java-sdk:v7.2.27" level="project" />
27+
<orderEntry type="library" scope="RUNTIME" name="Maven: com.squareup.okhttp3:okhttp:3.14.4" level="project" />
28+
<orderEntry type="library" scope="RUNTIME" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
29+
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
3530
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.3" level="project" />
3631
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.6" level="project" />
3732
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@
5454
<version>2.4</version>
5555
<classifier>jdk15</classifier>
5656
</dependency>
57-
<dependency>
57+
<!--<dependency>
5858
<groupId>io.udfs.api</groupId>
5959
<artifactId>ulord-java-sdk</artifactId>
6060
<version>0.0.1</version>
6161
<scope>system</scope>
6262
<systemPath>${project.basedir}/lib/ulord-java-sdk-1.0.0.jar</systemPath>
63+
</dependency>-->
64+
<dependency>
65+
<groupId>com.github.qiniu</groupId>
66+
<artifactId>java-sdk</artifactId>
67+
<version>v7.2.27</version>
6368
</dependency>
6469
<dependency>
6570
<groupId>org.apache.httpcomponents</groupId>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.udfs.api.util;
2+
3+
import org.apache.http.HttpException;
4+
import org.apache.http.HttpRequest;
5+
import org.apache.http.HttpRequestInterceptor;
6+
import org.apache.http.protocol.HTTP;
7+
import org.apache.http.protocol.HttpContext;
8+
9+
import java.io.IOException;
10+
11+
public class ContentLengthHeaderRemover implements HttpRequestInterceptor {
12+
13+
14+
@Override
15+
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
16+
httpRequest.removeHeaders(HTTP.CONTENT_LEN);// fighting org.apache.http.protocol.RequestContent's ProtocolException("Content-Length header already present");
17+
}
18+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package io.udfs.api.util;
2+
3+
import org.apache.http.HttpEntity;
4+
import org.apache.http.HttpResponse;
5+
import org.apache.http.client.methods.HttpUriRequest;
6+
import org.apache.http.client.methods.RequestBuilder;
7+
import org.apache.http.entity.ContentType;
8+
import org.apache.http.entity.mime.HttpMultipartMode;
9+
import org.apache.http.entity.mime.MultipartEntity;
10+
import org.apache.http.entity.mime.MultipartEntityBuilder;
11+
import org.apache.http.entity.mime.content.FileBody;
12+
import org.apache.http.impl.client.CloseableHttpClient;
13+
import org.apache.http.impl.client.HttpClients;
14+
import org.apache.http.impl.client.LaxRedirectStrategy;
15+
import org.apache.http.util.EntityUtils;
16+
17+
import java.io.File;
18+
import java.io.IOException;
19+
import java.io.OutputStream;
20+
import java.net.HttpURLConnection;
21+
import java.net.URL;
22+
23+
public class MultipartUploadExample {
24+
public static void main(String[] args) throws Exception {
25+
//Creating CloseableHttpClient object
26+
//CloseableHttpClient httpclient = HttpClients.createDefault();
27+
CloseableHttpClient httpclient = HttpClients.custom()
28+
.addInterceptorFirst(new ContentLengthHeaderRemover()).setRedirectStrategy(new LaxRedirectStrategy())
29+
.build();
30+
31+
//Creating a file object
32+
//String url="http://114.67.38.19:15001/api/v0/add";
33+
//String url="http://124.232.153.109:15001/api/v0/add";
34+
String url="http://api.udfs.one:15001/api/v0/delete/";
35+
//String filePath = "F:\\分布式存储\\宣传片\\少林寺BD国粤双语中字[电影天堂www.dy2018.com].mkv";
36+
String hash="QmWYJiC3itS1CNr5ys7c4eAr98f2D8q1PndgnRoGtJZpwC";
37+
38+
/*String filePath1 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-0.mp4";
39+
String filePath2 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-1.mp4";
40+
String filePath3 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-2.mp4";
41+
String filePath4 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-3.mp4";
42+
String filePath5 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-4.mp4";
43+
String filePath6 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-5.mp4";
44+
String filePath7 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-6.mp4";
45+
String filePath8 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-7.mp4";
46+
String filePath9 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-8.mp4";
47+
String filePath10 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-9.mp4";
48+
String filePath11 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-10.mp4";
49+
String filePath12 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-11.mp4";
50+
String filePath13 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-12.mp4";
51+
String filePath14 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-13.mp4";
52+
String filePath15 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-14.mp4";
53+
String filePath16 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-15.mp4";
54+
String filePath17 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-16.mp4";
55+
String filePath18 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-17.mp4";
56+
String filePath19 = "F:\\分布式存储\\宣传片\\temp\\Ulord链云生态宣传片中英文字幕200M-18.mp4";*/
57+
//File file = new File(filePath);
58+
//UdfsDevTools tools = new UdfsDevTools(1000000, "76E18tAYEU2WPLww2DwPvM6", "udisk",filePath, "");
59+
//UdfsDevTools tools = new UdfsDevTools(1000000, "76E18tAYEU2WPLww2DwPvM6", "udisk",filePath, "");
60+
61+
UdfsDevTools tools = new UdfsDevTools(1000, "D3BBEBC1E5004F429D301041B3771D9E", "bcdcentercom", "");
62+
63+
//Creating the FileBody object
64+
//FileBody filebody = new FileBody(file, ContentType.DEFAULT_BINARY);
65+
66+
//Creating the MultipartEntityBuilder
67+
MultipartEntityBuilder entitybuilder = MultipartEntityBuilder.create();
68+
69+
//Setting the mode
70+
entitybuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
71+
72+
//Adding text
73+
//entitybuilder.addTextBody("sample_text", "This is the text part of our file");
74+
75+
//Adding a file
76+
//entitybuilder.addBinaryBody("少林", new File(filePath));
77+
/*entitybuilder.addBinaryBody("宣传片2", new File(filePath2));
78+
entitybuilder.addBinaryBody("宣传片3", new File(filePath3));
79+
entitybuilder.addBinaryBody("宣传片4", new File(filePath4));
80+
entitybuilder.addBinaryBody("宣传片5", new File(filePath5));
81+
entitybuilder.addBinaryBody("宣传片6", new File(filePath6));
82+
entitybuilder.addBinaryBody("宣传片7", new File(filePath7));
83+
entitybuilder.addBinaryBody("宣传片8", new File(filePath8));
84+
entitybuilder.addBinaryBody("宣传片9", new File(filePath9));
85+
entitybuilder.addBinaryBody("宣传片10", new File(filePath10));
86+
entitybuilder.addBinaryBody("宣传片11", new File(filePath11));
87+
entitybuilder.addBinaryBody("宣传片12", new File(filePath12));
88+
entitybuilder.addBinaryBody("宣传片13", new File(filePath13));
89+
entitybuilder.addBinaryBody("宣传片14", new File(filePath14));
90+
entitybuilder.addBinaryBody("宣传片15", new File(filePath15));
91+
entitybuilder.addBinaryBody("宣传片16", new File(filePath16));
92+
entitybuilder.addBinaryBody("宣传片17", new File(filePath17));
93+
entitybuilder.addBinaryBody("宣传片18", new File(filePath18));*/
94+
95+
//Building a single entity using the parts
96+
HttpEntity mutiPartHttpEntity = entitybuilder.build();
97+
98+
//System.out.println(url+"?token=" + tools.getToken("add").toString());
99+
100+
//Building the RequestBuilder request object
101+
RequestBuilder reqbuilder = RequestBuilder.post(url+hash+"?token=" + tools.getToken("get").toString());
102+
103+
System.out.println(url+hash+"?token=" + tools.getToken("get").toString());
104+
105+
106+
//Set the entity object to the RequestBuilder
107+
reqbuilder.setEntity(mutiPartHttpEntity);
108+
109+
//Building the request
110+
HttpUriRequest multipartRequest = reqbuilder.build();
111+
112+
//Executing the request
113+
HttpResponse httpresponse = httpclient.execute(multipartRequest);
114+
115+
//Printing the status and the contents of the response
116+
System.out.println(EntityUtils.toString(httpresponse.getEntity()));
117+
System.out.println(httpresponse.getStatusLine());
118+
//MultipartUploadExample.uploadFile();
119+
}
120+
121+
public static int uploadFile() throws Exception {
122+
String url="http://test.api.udfs.one:15001/api/v0/add";
123+
String filePath = "F:\\分布式存储\\宣传片\\Ulord链云生态宣传片中英文字幕200M.mp4";
124+
UdfsDevTools tools = new UdfsDevTools(1000000, "test", "testaccountb",filePath, "");
125+
HttpURLConnection connection =
126+
(HttpURLConnection) (new URL(url+"?token=" + tools.getToken("add").toString())).openConnection();
127+
connection.setDoOutput(true);
128+
connection.setRequestMethod("POST");
129+
130+
FileBody fileBody = new FileBody(new File(filePath));
131+
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT);
132+
multipartEntity.addPart("宣传片", fileBody);
133+
134+
connection.setRequestProperty("Content-Type", multipartEntity.getContentType().getValue());
135+
OutputStream out = connection.getOutputStream();
136+
try {
137+
multipartEntity.writeTo(out);
138+
} catch (IOException e) {
139+
e.printStackTrace();
140+
} finally {
141+
out.close();
142+
}
143+
int status = connection.getResponseCode();
144+
return status;
145+
146+
}
147+
148+
}

0 commit comments

Comments
 (0)