5
5
import java .io .IOException ;
6
6
import java .io .InputStream ;
7
7
import java .io .Serializable ;
8
- import java .net .URLEncoder ;
9
- import java .nio .charset .StandardCharsets ;
10
8
import java .nio .file .Files ;
11
9
import java .nio .file .Path ;
12
10
import java .util .List ;
@@ -42,7 +40,7 @@ public ArtifactoryClient(@NonNull ArtifactoryConfig config) {
42
40
*/
43
41
public void uploadArtifact (Path file , String targetPath ) throws IOException {
44
42
UploadableArtifact artifact =
45
- artifactory .repository (this .config .repository ).upload (urlEncodeParts (targetPath ), file .toFile ());
43
+ artifactory .repository (this .config .repository ).upload (Utils . urlEncodeParts (targetPath ), file .toFile ());
46
44
artifact .withSize (Files .size (file ));
47
45
artifact .withListener (
48
46
(bytesRead , totalBytes ) -> LOGGER .trace (String .format ("Uploaded %d/%d" , bytesRead , totalBytes )));
@@ -55,7 +53,7 @@ public void uploadArtifact(Path file, String targetPath) throws IOException {
55
53
* @param targetPath the path of the artifact to delete
56
54
*/
57
55
public void deleteArtifact (String targetPath ) {
58
- artifactory .repository (this .config .repository ).delete (urlEncodeParts (targetPath ));
56
+ artifactory .repository (this .config .repository ).delete (Utils . urlEncodeParts (targetPath ));
59
57
}
60
58
61
59
/**
@@ -64,8 +62,8 @@ public void deleteArtifact(String targetPath) {
64
62
* @param targetPath the target path
65
63
*/
66
64
public void move (String sourcePath , String targetPath ) {
67
- ItemHandle sourceItem = artifactory .repository (this .config .repository ).folder (urlEncodeParts (sourcePath ));
68
- sourceItem .move (this .config .repository , urlEncodeParts (targetPath ));
65
+ ItemHandle sourceItem = artifactory .repository (this .config .repository ).folder (Utils . urlEncodeParts (sourcePath ));
66
+ sourceItem .move (this .config .repository , Utils . urlEncodeParts (targetPath ));
69
67
}
70
68
71
69
/**
@@ -74,7 +72,7 @@ public void move(String sourcePath, String targetPath) {
74
72
* @param targetPath the target path
75
73
*/
76
74
public void copy (String sourcePath , String targetPath ) {
77
- ItemHandle sourceItem = artifactory .repository (this .config .repository ).folder (urlEncodeParts (sourcePath ));
75
+ ItemHandle sourceItem = artifactory .repository (this .config .repository ).folder (Utils . urlEncodeParts (sourcePath ));
78
76
sourceItem .copy (this .config .repository , targetPath );
79
77
}
80
78
@@ -86,7 +84,7 @@ public void copy(String sourcePath, String targetPath) {
86
84
*/
87
85
public InputStream downloadArtifact (String targetPath ) throws IOException {
88
86
DownloadableArtifact artifact =
89
- artifactory .repository (this .config .repository ).download (urlEncodeParts (targetPath ));
87
+ artifactory .repository (this .config .repository ).download (Utils . urlEncodeParts (targetPath ));
90
88
return artifact .doDownload ();
91
89
}
92
90
@@ -98,7 +96,7 @@ public InputStream downloadArtifact(String targetPath) throws IOException {
98
96
*/
99
97
public boolean isFolder (String targetPath ) throws IOException {
100
98
try {
101
- return artifactory .repository (this .config .repository ).isFolder (urlEncodeParts (targetPath ));
99
+ return artifactory .repository (this .config .repository ).isFolder (Utils . urlEncodeParts (targetPath ));
102
100
} catch (Exception e ) {
103
101
LOGGER .debug (String .format ("Failed to check if %s is a folder" , targetPath ));
104
102
return false ;
@@ -140,7 +138,7 @@ public boolean isFile(String targetPath) throws IOException {
140
138
try {
141
139
File file = artifactory
142
140
.repository (this .config .repository )
143
- .file (urlEncodeParts (targetPath ))
141
+ .file (Utils . urlEncodeParts (targetPath ))
144
142
.info ();
145
143
return !file .isFolder ();
146
144
} catch (Exception e ) {
@@ -178,7 +176,7 @@ public long size(String targetPath) throws IOException {
178
176
LOGGER .trace (String .format ("Getting size for %s" , targetPath ));
179
177
File file = artifactory
180
178
.repository (this .config .repository )
181
- .file (urlEncodeParts (targetPath ))
179
+ .file (Utils . urlEncodeParts (targetPath ))
182
180
.info ();
183
181
return file .getSize ();
184
182
}
@@ -206,12 +204,6 @@ private Artifactory buildArtifactory() {
206
204
.build ();
207
205
}
208
206
209
- private String urlEncodeParts (String s ) {
210
- return URLEncoder .encode (s , StandardCharsets .UTF_8 )
211
- .replaceAll ("%2F" , "/" )
212
- .replace ("+" , "%20" );
213
- }
214
-
215
207
@ Override
216
208
public void close () throws Exception {
217
209
artifactory .close ();
0 commit comments