diff --git a/Base/src/main/java/io/deephaven/base/FileUtils.java b/Base/src/main/java/io/deephaven/base/FileUtils.java index 98355cf2dc4..818b652862a 100644 --- a/Base/src/main/java/io/deephaven/base/FileUtils.java +++ b/Base/src/main/java/io/deephaven/base/FileUtils.java @@ -82,7 +82,7 @@ public static void deleteRecursively(File file) { /** * Move files accepted by a filter from their relative path under source to the same relative path under * destination. Creates missing destination subdirectories as needed. - * + * * @param source Must be a directory. * @param destination Must be a directory if it exists. * @param filter Applied to normal files, only. We recurse on directories automatically. @@ -129,7 +129,7 @@ private static void moveRecursivelyInternal(File source, File destination, FileF /** * Recursive delete method that copes with .nfs files. Uses the file's parent as the trash directory. - * + * * @param file */ public static void deleteRecursivelyOnNFS(File file) { @@ -138,7 +138,7 @@ public static void deleteRecursivelyOnNFS(File file) { /** * Recursive delete method that copes with .nfs files. - * + * * @param trashFile Filename to move regular files to before deletion. .nfs files may be created in its parent * directory. * @param fileToBeDeleted File or directory at which to begin recursive deletion. @@ -169,7 +169,7 @@ public static void deleteRecursivelyOnNFS(final File trashFile, final File fileT /** * Scan directory recursively to find all files - * + * * @param dir * @return */ @@ -282,30 +282,21 @@ public static URI convertToURI(final String source, final boolean isDirectory) { URI uri; try { uri = new URI(source); - if (uri.getScheme() == null) { - // Convert to a "file" URI - return convertToURI(new File(source), isDirectory); - } - String path = uri.getPath(); - boolean isUpdated = false; - // Directory URIs should end with a slash - if (isDirectory && path.charAt(path.length() - 1) != URI_SEPARATOR_CHAR) { - path = path + URI_SEPARATOR_CHAR; - isUpdated = true; - } // Replace two or more consecutive slashes in the path with a single slash + final String path = uri.getPath(); if (path.contains(REPEATED_URI_SEPARATOR)) { - path = REPEATED_URI_SEPARATOR_PATTERN.matcher(path).replaceAll(URI_SEPARATOR); - isUpdated = true; - } - if (isUpdated) { - uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), - uri.getFragment()); + final String canonicalizedPath = REPEATED_URI_SEPARATOR_PATTERN.matcher(path).replaceAll(URI_SEPARATOR); + uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), canonicalizedPath, + uri.getQuery(), uri.getFragment()); } } catch (final URISyntaxException e) { // If the URI is invalid, assume it's a file path return convertToURI(new File(source), isDirectory); } + if (uri.getScheme() == null) { + // Convert to a "file" URI + return convertToURI(new File(source), isDirectory); + } return uri; }