26
26
package java .net ;
27
27
28
28
import java .io .IOException ;
29
- import java .io .InputStream ;
30
- import java .io .File ;
31
- import java .io .OutputStream ;
32
- import java .util .Hashtable ;
33
29
import java .util .Objects ;
34
30
import sun .net .util .IPAddressUtil ;
35
- import sun .net .www .ParseUtil ;
36
31
37
32
/**
38
33
* The abstract class {@code URLStreamHandler} is the common
@@ -158,13 +153,12 @@ protected void parseURL(URL u, String spec, int start, int limit) {
158
153
queryOnly = queryStart == start ;
159
154
if ((queryStart != -1 ) && (queryStart < limit )) {
160
155
query = spec .substring (queryStart +1 , limit );
161
- if (limit > queryStart )
162
- limit = queryStart ;
156
+ limit = queryStart ;
163
157
spec = spec .substring (0 , queryStart );
164
158
}
165
159
}
166
160
167
- int i = 0 ;
161
+ int i ;
168
162
// Parse the authority part if any
169
163
boolean isUNCName = (start <= limit - 4 ) &&
170
164
(spec .charAt (start ) == '/' ) &&
@@ -249,7 +243,7 @@ protected void parseURL(URL u, String spec, int start, int limit) {
249
243
start = i ;
250
244
// If the authority is defined then the path is defined by the
251
245
// spec only; See RFC 2396 Section 5.2.4.
252
- if (authority != null && !authority .isEmpty ())
246
+ if (!authority .isEmpty ())
253
247
path = "" ;
254
248
}
255
249
@@ -259,26 +253,27 @@ protected void parseURL(URL u, String spec, int start, int limit) {
259
253
260
254
// Parse the file path if any
261
255
if (start < limit ) {
256
+ String specStr = spec .substring (start , limit );
262
257
if (spec .charAt (start ) == '/' ) {
263
- path = spec . substring ( start , limit ) ;
258
+ path = specStr ;
264
259
} else if (path != null && !path .isEmpty ()) {
265
260
isRelPath = true ;
266
261
int ind = path .lastIndexOf ('/' );
267
- String separator = "" ;
268
- if (ind == -1 && authority != null )
269
- separator = "/" ;
270
- path = path .substring (0 , ind + 1 ) + separator +
271
- spec .substring (start , limit );
272
-
262
+ if (ind == -1 && authority != null ) {
263
+ path = "/" .concat (specStr );
264
+ } else {
265
+ path = path .substring (0 , ind + 1 ).concat (specStr );
266
+ }
273
267
} else {
274
- path = spec .substring (start , limit );
275
- path = (authority != null ) ? "/" + path : path ;
268
+ path = (authority != null ) ? "/" .concat (specStr ) : specStr ;
276
269
}
277
270
} else if (queryOnly && path != null ) {
278
271
int ind = path .lastIndexOf ('/' );
279
- if (ind < 0 )
280
- ind = 0 ;
281
- path = path .substring (0 , ind ) + "/" ;
272
+ if (ind < 0 ) {
273
+ path = "/" ;
274
+ } else {
275
+ path = path .substring (0 , ind + 1 );
276
+ }
282
277
}
283
278
if (path == null )
284
279
path = "" ;
@@ -299,7 +294,7 @@ protected void parseURL(URL u, String spec, int start, int limit) {
299
294
*/
300
295
if (i > 0 && (limit = path .lastIndexOf ('/' , i - 1 )) >= 0 &&
301
296
(path .indexOf ("/../" , limit ) != 0 )) {
302
- path = path .substring (0 , limit ) + path .substring (i + 3 );
297
+ path = path .substring (0 , limit ). concat ( path .substring (i + 3 ) );
303
298
i = 0 ;
304
299
} else {
305
300
i = i + 3 ;
0 commit comments