|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
22 | 22 | import java.io.InputStream;
|
23 | 23 | import java.io.OutputStream;
|
24 | 24 | import java.net.URI;
|
| 25 | +import java.net.URISyntaxException; |
25 | 26 | import java.net.URL;
|
26 | 27 | import java.nio.channels.FileChannel;
|
27 | 28 | import java.nio.channels.ReadableByteChannel;
|
|
34 | 35 |
|
35 | 36 | import org.springframework.lang.Nullable;
|
36 | 37 | import org.springframework.util.Assert;
|
| 38 | +import org.springframework.util.ResourceUtils; |
37 | 39 | import org.springframework.util.StringUtils;
|
38 | 40 |
|
39 | 41 | /**
|
|
48 | 50 | * interactions via NIO.2, only resorting to {@link File} on {@link #getFile()}.
|
49 | 51 | *
|
50 | 52 | * @author Juergen Hoeller
|
| 53 | + * @author Sam Brannen |
51 | 54 | * @since 28.12.2003
|
52 | 55 | * @see #FileSystemResource(String)
|
53 | 56 | * @see #FileSystemResource(File)
|
@@ -226,7 +229,23 @@ public URL getURL() throws IOException {
|
226 | 229 | */
|
227 | 230 | @Override
|
228 | 231 | public URI getURI() throws IOException {
|
229 |
| - return (this.file != null ? this.file.toURI() : this.filePath.toUri()); |
| 232 | + if (this.file != null) { |
| 233 | + return this.file.toURI(); |
| 234 | + } |
| 235 | + else { |
| 236 | + URI uri = this.filePath.toUri(); |
| 237 | + // Normalize URI? See https://github.com/spring-projects/spring-framework/issues/29275 |
| 238 | + String scheme = uri.getScheme(); |
| 239 | + if (ResourceUtils.URL_PROTOCOL_FILE.equals(scheme)) { |
| 240 | + try { |
| 241 | + uri = new URI(scheme, uri.getPath(), null); |
| 242 | + } |
| 243 | + catch (URISyntaxException ex) { |
| 244 | + throw new IllegalStateException("Failed to normalize URI: " + uri, ex); |
| 245 | + } |
| 246 | + } |
| 247 | + return uri; |
| 248 | + } |
230 | 249 | }
|
231 | 250 |
|
232 | 251 | /**
|
|
0 commit comments