@@ -60,7 +60,7 @@ public void tearDown() throws Exception {
60
60
61
61
@ Test
62
62
void connectionToRootUsingAbsoluteUrl () throws Exception {
63
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/" );
63
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/" );
64
64
assertThat (JarURLConnection .get (url , this .jarFile ).getContent ()).isSameAs (this .jarFile );
65
65
}
66
66
@@ -72,7 +72,7 @@ void connectionToRootUsingRelativeUrl() throws Exception {
72
72
73
73
@ Test
74
74
void connectionToEntryUsingAbsoluteUrl () throws Exception {
75
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/1.dat" );
75
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/1.dat" );
76
76
try (InputStream input = JarURLConnection .get (url , this .jarFile ).getInputStream ()) {
77
77
assertThat (input ).hasSameContentAs (new ByteArrayInputStream (new byte [] { 1 }));
78
78
}
@@ -88,15 +88,15 @@ void connectionToEntryUsingRelativeUrl() throws Exception {
88
88
89
89
@ Test
90
90
void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix () throws Exception {
91
- URL url = new URL ("jar:file:/ " + getAbsolutePath () + "!/1.dat" );
91
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/1.dat" );
92
92
try (InputStream input = JarURLConnection .get (url , this .jarFile ).getInputStream ()) {
93
93
assertThat (input ).hasSameContentAs (new ByteArrayInputStream (new byte [] { 1 }));
94
94
}
95
95
}
96
96
97
97
@ Test
98
98
void connectionToEntryUsingAbsoluteUrlForNestedEntry () throws Exception {
99
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/nested.jar!/3.dat" );
99
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/nested.jar!/3.dat" );
100
100
JarURLConnection connection = JarURLConnection .get (url , this .jarFile );
101
101
try (InputStream input = connection .getInputStream ()) {
102
102
assertThat (input ).hasSameContentAs (new ByteArrayInputStream (new byte [] { 3 }));
@@ -116,7 +116,7 @@ void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
116
116
117
117
@ Test
118
118
void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile () throws Exception {
119
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/nested.jar!/3.dat" );
119
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/nested.jar!/3.dat" );
120
120
try (JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ))) {
121
121
try (InputStream input = JarURLConnection .get (url , nested ).getInputStream ()) {
122
122
assertThat (input ).hasSameContentAs (new ByteArrayInputStream (new byte [] { 3 }));
@@ -136,7 +136,7 @@ void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws Excepti
136
136
137
137
@ Test
138
138
void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext () throws Exception {
139
- URL url = new URL (new URL ("jar" , null , -1 , "file:" + getAbsolutePath () + "!/nested.jar!/" , new Handler ()),
139
+ URL url = new URL (new URL ("jar" , null , -1 , this . rootJarFile . toURI (). toURL () + "!/nested.jar!/" , new Handler ()),
140
140
"/3.dat" );
141
141
try (JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ))) {
142
142
try (InputStream input = JarURLConnection .get (url , nested ).getInputStream ()) {
@@ -167,7 +167,7 @@ void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
167
167
168
168
@ Test
169
169
void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile () throws Exception {
170
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/w.jar!/3.dat" );
170
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/w.jar!/3.dat" );
171
171
try (JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ))) {
172
172
assertThatExceptionOfType (FileNotFoundException .class )
173
173
.isThrownBy (JarURLConnection .get (url , nested )::getInputStream );
@@ -176,7 +176,7 @@ void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Ex
176
176
177
177
@ Test
178
178
void getContentLengthReturnsLengthOfUnderlyingEntry () throws Exception {
179
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/nested.jar!/3.dat" );
179
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/nested.jar!/3.dat" );
180
180
try (JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ))) {
181
181
JarURLConnection connection = JarURLConnection .get (url , nested );
182
182
assertThat (connection .getContentLength ()).isEqualTo (1 );
@@ -185,7 +185,7 @@ void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
185
185
186
186
@ Test
187
187
void getContentLengthLongReturnsLengthOfUnderlyingEntry () throws Exception {
188
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/nested.jar!/3.dat" );
188
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/nested.jar!/3.dat" );
189
189
try (JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ))) {
190
190
JarURLConnection connection = JarURLConnection .get (url , nested );
191
191
assertThat (connection .getContentLengthLong ()).isEqualTo (1 );
@@ -194,7 +194,7 @@ void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
194
194
195
195
@ Test
196
196
void getLastModifiedReturnsLastModifiedTimeOfJarEntry () throws Exception {
197
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/1.dat" );
197
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/1.dat" );
198
198
JarURLConnection connection = JarURLConnection .get (url , this .jarFile );
199
199
assertThat (connection .getLastModified ()).isEqualTo (connection .getJarEntry ().getTime ());
200
200
}
@@ -220,10 +220,6 @@ void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
220
220
.isEqualTo ("\u00e1 /b/\u00c7 .class" );
221
221
}
222
222
223
- private String getAbsolutePath () {
224
- return this .rootJarFile .getAbsolutePath ().replace ('\\' , '/' );
225
- }
226
-
227
223
private String getRelativePath () {
228
224
return this .rootJarFile .getPath ().replace ('\\' , '/' );
229
225
}
0 commit comments