mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
ignore leading / for files on Windows (fixes #452)
This commit is contained in:
parent
9f70aa753e
commit
e2f2ed68f0
@ -34,7 +34,7 @@ public class Handler extends URLStreamHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
return new FileInputStream(url.getFile());
|
return new FileInputStream(new File(url.getFile()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() {
|
public void connect() {
|
||||||
|
@ -14,6 +14,9 @@ public class File implements Serializable {
|
|||||||
private static final String FileSeparator
|
private static final String FileSeparator
|
||||||
= System.getProperty("file.separator");
|
= System.getProperty("file.separator");
|
||||||
|
|
||||||
|
private static final boolean IsWindows
|
||||||
|
= System.getProperty("os.name").equals("Windows");
|
||||||
|
|
||||||
public static final String separator = FileSeparator;
|
public static final String separator = FileSeparator;
|
||||||
|
|
||||||
public static final char separatorChar = FileSeparator.charAt(0);
|
public static final char separatorChar = FileSeparator.charAt(0);
|
||||||
@ -89,6 +92,14 @@ public class File implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String normalize(String path) {
|
private static String normalize(String path) {
|
||||||
|
if(IsWindows
|
||||||
|
&& path.length() > 2
|
||||||
|
&& path.charAt(0) == '/'
|
||||||
|
&& path.charAt(2) == ':')
|
||||||
|
{
|
||||||
|
// remove a leading slash on Windows
|
||||||
|
path = path.substring(1);
|
||||||
|
}
|
||||||
return stripSeparators
|
return stripSeparators
|
||||||
("\\".equals(FileSeparator) ? path.replace('/', '\\') : path);
|
("\\".equals(FileSeparator) ? path.replace('/', '\\') : path);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
public class Files {
|
public class Files {
|
||||||
|
private static final boolean IsWindows
|
||||||
|
= System.getProperty("os.name").equals("Windows");
|
||||||
|
|
||||||
private static void expect(boolean v) {
|
private static void expect(boolean v) {
|
||||||
if (! v) throw new RuntimeException();
|
if (! v) throw new RuntimeException();
|
||||||
}
|
}
|
||||||
@ -81,6 +84,12 @@ public class Files {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(IsWindows) {
|
||||||
|
expect(new File("/c:\\test").getPath().equals("c:\\test"));
|
||||||
|
} else {
|
||||||
|
expect(new File("/c:\\test").getPath().equals("/c:\\test"));
|
||||||
|
}
|
||||||
|
|
||||||
expect(new File("foo/bar").getParent().equals("foo"));
|
expect(new File("foo/bar").getParent().equals("foo"));
|
||||||
expect(new File("foo/bar/").getParent().equals("foo"));
|
expect(new File("foo/bar/").getParent().equals("foo"));
|
||||||
expect(new File("foo/bar//").getParent().equals("foo"));
|
expect(new File("foo/bar//").getParent().equals("foo"));
|
||||||
|
Loading…
Reference in New Issue
Block a user