From 78b744361843cb27643a4099636ac07a1ac9f127 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 28 Feb 2024 00:40:02 +0900 Subject: [PATCH] follow ide advices --- .../acd/AcdBasicFileAttributesProvider.java | 2 +- .../java/vavi/nio/file/acd/AcdFileStore.java | 2 +- .../nio/file/acd/AcdFileSystemDriver.java | 4 +- .../nio/file/acd/AcdFileSystemRepository.java | 4 +- .../vavi/nio/file/acd/AcdOutputStream.java | 2 +- .../ArchiveBasicFileAttributesProvider.java | 2 +- .../nio/file/archive/ArchiveFileStore.java | 2 +- .../file/archive/ArchiveFileSystemDriver.java | 5 +- .../vavi/nio/file/flickr/FlickrFileStore.java | 6 +- .../flickr/FlickrFileSystemRepository.java | 4 +- .../nio/file/flickr/FlickrInputStream.java | 5 +- .../nio/file/flickr/FlickrOutputStream.java | 4 +- .../GatheredBasicFileAttributesProvider.java | 30 +- .../nio/file/gathered/GatheredFileStore.java | 7 +- .../gathered/GatheredFileSystemDriver.java | 4 +- .../GatheredFileSystemRepository.java | 3 +- .../java/vavi/nio/file/gathered/NameMap.java | 7 +- .../GatheredFileSystemProviderTest.java | 8 +- .../googledrive/GoogleDriveCopyOption.java | 4 +- .../googledrive/GoogleDriveOpenOption.java | 4 +- ...riveUserDefinedFileAttributesProvider.java | 12 +- .../googledrive/GoogleDriveWatchService.java | 2 +- .../GoogleWebSocketNotification.java | 2 +- .../nio/file/googledrive/SearcherTest.java | 3 +- .../file/googledrive/WatchDirectoryTest.java | 4 +- .../file/googledrive/WatchServiceTest.java | 14 +- .../nio/file/googledrive/WebHookTest.java | 5 +- .../nio/file/googledrive/WebHookTest3.java | 14 +- .../hfs/HfsBasicFileAttributesProvider.java | 6 +- .../java/vavi/nio/file/hfs/HfsFileStore.java | 1 - .../nio/file/hfs/HfsFileSystemRepository.java | 42 +-- .../file/hfs/HfsFileSystemProviderTest.java | 1 - .../onedrive/OneDriveFileSystemDriver.java | 6 +- .../OneDriveFileSystemRepository.java | 6 +- .../file/onedrive/OneDriveUploadOption.java | 9 +- .../OneDriveWebSocketNotification.java | 2 +- .../test/java/vavi/nio/file/onedrive/App.java | 10 +- .../java/vavi/nio/file/onedrive/Rename.java | 2 +- .../onedrive3/OneDriveFileSystemDriver.java | 17 +- .../OneDriveFileSystemRepository.java | 2 +- .../file/onedrive3/OneDriveUploadOption.java | 2 + .../MicrosoftWebSocketNotification.java | 2 +- .../nio/file/onedrive3/WebHookApiTest.java | 2 +- .../nio/file/onedrive4/OneDriveFileStore.java | 3 +- .../onedrive4/OneDriveFileSystemDriver.java | 75 ++-- .../OneDriveFileSystemRepository.java | 1 - .../file/onedrive4/OneDriveUploadOption.java | 9 +- ...riveUserDefinedFileAttributesProvider.java | 4 +- .../onedrive4/graph/LraMonitorProvider.java | 4 +- .../onedrive4/graph/LraMonitorRequest.java | 12 +- .../file/onedrive4/graph/MonitorObject.java | 2 +- .../graph/ThumbnailUploadProvider.java | 24 +- .../MicrosoftWebSocketNotification.java | 2 +- .../nio/file/onedrive4/OneDriveEasyFS.java | 4 +- .../vavi/nio/file/onedrive4/TestGraph.java | 74 ++-- .../nio/file/onedrive4/WebHookApiTest.java | 8 +- .../src/test/java/Classification2.java | 4 +- .../src/test/java/Classification3.java | 2 +- .../src/test/java/CloserFinder.java | 30 +- .../src/test/java/Descriptor.java | 29 +- .../test/java/GoogleDriveDeletedChecker.java | 8 +- .../src/test/java/GoogleDriveFilename.java | 1 - .../src/test/java/GoogleDriveThumbnail.java | 2 +- .../src/test/java/GoogleDriveUploader.java | 2 +- .../src/test/java/OneDriveThumbnail.java | 8 +- .../src/test/java/ShowEmptyFolder.java | 2 +- .../src/test/java/Synchronizer.java | 2 +- .../src/test/java/Test1.java | 4 +- .../src/test/java/TestAozora.java | 2 +- .../vavi/nio/file/watch/WatchServiceTest.java | 320 +++++++----------- .../proprietary/vfs/SftpVfsAuthenticator.java | 2 +- .../proprietary/vfs/SmbVfsAuthenticator.java | 2 +- .../proprietary/vfs/VfsAuthenticator.java | 13 +- .../auth/proprietary/vfs/VfsCredential.java | 43 ++- .../src/test/java/vavi/nio/file/vfs/Main.java | 9 +- .../test/java/vavi/nio/file/vfs/Main2.java | 3 +- .../test/java/vavi/nio/file/vfs/Main3.java | 3 +- .../test/java/vavi/nio/file/vfs/Main4.java | 7 +- .../java/vavi/nio/file/vfs/TestVfsWebdav.java | 3 +- 79 files changed, 443 insertions(+), 555 deletions(-) diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java index 04566d5a..21322810 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java @@ -86,7 +86,7 @@ public boolean isDirectory() { */ @Override public long size() { - return FileInfo.class.isInstance(entry) ? FileInfo.class.cast(entry).getContentProperties().getSize() : 0; + return entry instanceof FileInfo ? ((FileInfo) entry).getContentProperties().getSize() : 0; } /* @see java.nio.file.attribute.PosixFileAttributes#owner() */ diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java index fcb2958d..e21ca509 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java @@ -20,7 +20,7 @@ * A simple Amazon Cloud Drive {@link FileStore} * *

- * This makes use of information available in {@link StorageQuota}. + * This makes use of information available in {@link AccountQuota}. * Information is computed in "real time". *

*/ diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java index a0868c6f..bbe7a791 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java @@ -83,7 +83,7 @@ protected InputStream downloadEntryImpl(NodeInfo entry, Path path, Set options) throws IOException { File temp = File.createTempFile("vavi-apps-fuse-", ".upload"); - return new AcdOutputStream(drive, temp, toFilenameString(path), FolderInfo.class.cast(parentEntry), file -> { + return new AcdOutputStream(drive, temp, toFilenameString(path), (FolderInfo) parentEntry, file -> { System.out.println("file: " + file.getName() + ", " + file.getCreationDate() + ", " + file.getContentProperties().getSize()); updateEntry(path, file); }); @@ -102,7 +102,7 @@ protected NodeInfo createDirectoryEntry(NodeInfo parentEntry, Path dir) throws I @Override protected boolean hasChildren(NodeInfo dirEntry, Path dir) throws IOException { - return drive.getList(dirEntry.getId()).size() > 0; + return !drive.getList(dirEntry.getId()).isEmpty(); } @Override diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java index 718e010a..7289289f 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java @@ -47,7 +47,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th UserCredential userCredential = null; if (env.containsKey(AcdFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = UserCredential.class.cast(env.get(AcdFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (UserCredential) env.get(AcdFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); @@ -65,7 +65,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th OAuth2AppCredential appCredential = null; if (env.containsKey(AcdFileSystemProvider.ENV_APP_CREDENTIAL)) { - appCredential = OAuth2AppCredential.class.cast(env.get(AcdFileSystemProvider.ENV_APP_CREDENTIAL)); + appCredential = (OAuth2AppCredential) env.get(AcdFileSystemProvider.ENV_APP_CREDENTIAL); } if (appCredential == null) { diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java index b59f7e07..39a5f90a 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java @@ -35,7 +35,7 @@ * throw an exception; which means it may throw none, or it may throw an * unchecked exception. As such, the {@link #close()} method of this * class captures all {@link RuntimeException}s which {@link - * java.io.File#close()} may throw and wrap it into a {@link + * java.io.OutputStream#close()} may throw and wrap it into a {@link * IOException}. If the underlying output stream did throw an * exception, however, then such an exception is {@link * Throwable#addSuppressed(Throwable) suppressed}. diff --git a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java index 6cde844d..f8e15a00 100644 --- a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java +++ b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java @@ -34,7 +34,7 @@ public final class ArchiveBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes { /** null means root */ - private Entry entry; + private final Entry entry; public ArchiveBasicFileAttributesProvider(final Entry entry) throws IOException { this.entry = entry; diff --git a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java index a605fa0e..97dc13b7 100644 --- a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java +++ b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java @@ -17,7 +17,7 @@ * A simple archive {@link FileStore} * *

- * This makes use of information available in {@link StorageQuota}. + * This makes use of information available in {@link vavi.util.archive.Archive}. * Information is computed in "real time". *

*/ diff --git a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java index dcee6625..b94a886f 100644 --- a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java +++ b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java @@ -14,7 +14,6 @@ import java.nio.file.CopyOption; import java.nio.file.DirectoryStream; import java.nio.file.FileStore; -import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.OpenOption; import java.nio.file.Path; @@ -66,7 +65,7 @@ static String toArchiveString(Path path) { } /** for the case archive#entries() does not return dirs */ - private Map> directories = new HashMap<>(); + private final Map> directories = new HashMap<>(); /** */ private Entry getEntry(Path path) throws FileNotFoundException{ @@ -170,7 +169,7 @@ private List getDirectoryEntries(final Path dir) throws IOException { if (entry.getName().startsWith(dirString)) { String entryName = entry.getName().substring(dirString.length()); String[] names = entryName.split("/"); - if (names[0].length() > 0) { // exclude self? + if (!names[0].isEmpty()) { // exclude self? Path childPath = dir.resolve(names[0]); if (!list.contains(childPath)) list.add(childPath); diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java index 24ef9d39..f6c52122 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java @@ -20,7 +20,7 @@ * A simple Flickr {@link FileStore} * *

- * This makes use of information available in {@link StorageQuota}. + * This makes use of information available in {@link User}. * Information is computed in "real time". *

*/ @@ -33,9 +33,9 @@ public final class FlickrFileStore extends FileStoreBase { * * @param flickr the (valid) Flickr flickr to use */ - public FlickrFileStore(final Flickr drive, final FileAttributesFactory factory) { + public FlickrFileStore(final Flickr flickr, final FileAttributesFactory factory) { super("flickr", factory, false); - this.flickr = drive; + this.flickr = flickr; } /** diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java index ab5b41a9..4e1f6ea2 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java @@ -45,7 +45,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th UserCredential userCredential = null; if (env.containsKey(FlickrFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = UserCredential.class.cast(env.get(FlickrFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (UserCredential) env.get(FlickrFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); @@ -63,7 +63,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th OAuth2AppCredential appCredential = null; if (env.containsKey(FlickrFileSystemProvider.ENV_APP_CREDENTIAL)) { - appCredential = OAuth2AppCredential.class.cast(env.get(FlickrFileSystemProvider.ENV_APP_CREDENTIAL)); + appCredential = (OAuth2AppCredential) env.get(FlickrFileSystemProvider.ENV_APP_CREDENTIAL); } if (appCredential == null) { diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java index 0c52932e..75508c70 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java @@ -19,7 +19,6 @@ import com.flickr4java.flickr.Flickr; import com.flickr4java.flickr.FlickrException; import com.flickr4java.flickr.photos.Photo; -import com.github.fge.filesystem.driver.FileSystemDriver; /** @@ -39,12 +38,12 @@ * unchecked exception. As such, the {@link #close()} method of this * class captures all {@link RuntimeException}s which {@link * #close()} may throw and wrap it into a {@link - * FlickrIOException}. If the underlying input stream did throw an + * IOException}. If the underlying input stream did throw an * exception, however, then such an exception is {@link * Throwable#addSuppressed(Throwable) suppressed}. *

* - * @see FileSystemDriver#newInputStream(Path, OpenOption...) + * @see java.nio.file.Files#newInputStream(Path, OpenOption...) */ @ParametersAreNonnullByDefault public final class FlickrInputStream extends InputStream { diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java index e0dbb14b..0e5e6e16 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java @@ -38,8 +38,8 @@ * throw an exception; which means it may throw none, or it may throw an * unchecked exception. As such, the {@link #close()} method of this * class captures all {@link RuntimeException}s which {@link - * java.io.File#close()} may throw and wrap it into a {@link - * FlickrIOException}. If the underlying output stream did throw an + * java.io.OutputStream#close()} may throw and wrap it into a {@link + * IOException}. If the underlying output stream did throw an * exception, however, then such an exception is {@link * Throwable#addSuppressed(Throwable) suppressed}. *

diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java index 2464a4cd..5461ae43 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java @@ -32,7 +32,7 @@ */ public final class GatheredBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes { - private Object entry; + private final Object entry; public GatheredBasicFileAttributesProvider(@Nonnull final Object entry) throws IOException { this.entry = entry; @@ -52,16 +52,14 @@ public GatheredBasicFileAttributesProvider(@Nonnull final Object entry) throws I @Override public FileTime lastModifiedTime() { try { - if (FileSystem.class.isInstance(entry)) { - FileSystem fs = FileSystem.class.cast(entry); - if (GatheredFileSystemProvider.class.isInstance(fs.provider())) { + if (entry instanceof FileSystem fs) { + if (fs.provider() instanceof GatheredFileSystemProvider) { return FileTime.fromMillis(System.currentTimeMillis()); } else { return Files.getLastModifiedTime(fs.getRootDirectories().iterator().next()); } - } else if (Path.class.isInstance(entry)) { - Path path = Path.class.cast(entry); -//System.err.println("@@@: " + entry + ", " + path.getFileSystem().provider()); + } else if (entry instanceof Path path) { + //System.err.println("@@@: " + entry + ", " + path.getFileSystem().provider()); return Files.getLastModifiedTime(path); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); @@ -82,10 +80,9 @@ public FileTime lastModifiedTime() { */ @Override public boolean isRegularFile() { - if (FileSystem.class.isInstance(entry)) { + if (entry instanceof FileSystem) { return false; - } else if (Path.class.isInstance(entry)) { - Path path = Path.class.cast(entry); + } else if (entry instanceof Path path) { return Files.isRegularFile(path); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); @@ -97,10 +94,9 @@ public boolean isRegularFile() { */ @Override public boolean isDirectory() { - if (FileSystem.class.isInstance(entry)) { + if (entry instanceof FileSystem) { return true; - } else if (Path.class.isInstance(entry)) { - Path path = Path.class.cast(entry); + } else if (entry instanceof Path path) { return Files.isDirectory(path); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); @@ -119,10 +115,10 @@ public boolean isDirectory() { @Override public long size() { try { - if (FileSystem.class.isInstance(entry)) { - return FileSystem.class.cast(entry).getFileStores().iterator().next().getTotalSpace(); - } else if (Path.class.isInstance(entry)) { - return Files.size(Path.class.cast(entry)); + if (entry instanceof FileSystem) { + return ((FileSystem) entry).getFileStores().iterator().next().getTotalSpace(); + } else if (entry instanceof Path) { + return Files.size((Path) entry); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); } diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java index 80ce4c68..41793116 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java @@ -14,12 +14,7 @@ /** - * A simple Commons VFS2 {@link FileStore} - * - *

- * This makes use of information available in {@link StorageQuota}. - * Information is computed in "real time". - *

+ * A simple Commons VFS2 {@link FileStore}. */ public final class GatheredFileStore extends FileStoreBase { diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java index e60013f4..be40f6e3 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java @@ -57,7 +57,7 @@ public GatheredFileSystemDriver(final FileStore fileStore, super(fileStore, provider); this.fileSystems = fileSystems; if (env.containsKey(GatheredFileSystemProvider.ENV_NAME_MAP)) { - this.nameMap = NameMap.class.cast(env.get(GatheredFileSystemProvider.ENV_NAME_MAP)); + this.nameMap = (NameMap) env.get(GatheredFileSystemProvider.ENV_NAME_MAP); } } @@ -70,7 +70,7 @@ public InputStream newInputStream(final Path path, final Set env) throws IOException { if (!env.containsKey(GatheredFileSystemProvider.ENV_FILESYSTEMS)) { throw new NoSuchElementException(GatheredFileSystemProvider.ENV_FILESYSTEMS); } - Map fileSystems = Map.class.cast(env.get(GatheredFileSystemProvider.ENV_FILESYSTEMS)); + Map fileSystems = (Map) env.get(GatheredFileSystemProvider.ENV_FILESYSTEMS); GatheredFileStore fileStore = new GatheredFileStore(factoryProvider.getAttributesFactory()); return new GatheredFileSystemDriver(fileStore, factoryProvider, fileSystems, env); diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java index 9e40650d..d9202c46 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URLDecoder; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Map; import com.google.common.collect.BiMap; @@ -23,14 +24,14 @@ */ public class NameMap { - private BiMap nameMap = HashBiMap.create(); + private final BiMap nameMap = HashBiMap.create(); /** id -> display name */ public String encodeFsName(String id) throws IOException { if (!nameMap.isEmpty()) { return nameMap.get(id); } else { - return URLEncoder.encode(id, "utf-8"); + return URLEncoder.encode(id, StandardCharsets.UTF_8); } } @@ -39,7 +40,7 @@ public String decodeFsName(String path) throws IOException { if (!nameMap.isEmpty()) { return nameMap.inverse().get(path); } else { - return URLDecoder.decode(path, "utf-8"); + return URLDecoder.decode(path, StandardCharsets.UTF_8); } } diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java index 23b39652..2925bc02 100644 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java +++ b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java @@ -84,13 +84,13 @@ public static void main(String[] args) throws Exception { } /** */ - private OAuth2AppCredential microsoftAppCredential = new MicrosoftGraphLocalAppCredential(); + private final OAuth2AppCredential microsoftAppCredential = new MicrosoftGraphLocalAppCredential(); /** */ - private OAuth2AppCredential googleAppCredential = new GoogleLocalOAuth2AppCredential("googledrive"); + private final OAuth2AppCredential googleAppCredential = new GoogleLocalOAuth2AppCredential("googledrive"); /** */ - private OAuth2AppCredential boxAppCredential = new BoxLocalAppCredential(); + private final OAuth2AppCredential boxAppCredential = new BoxLocalAppCredential(); /** */ - private OAuth2AppCredential dropboxAppCredential = new DropBoxLocalAppCredential(); + private final OAuth2AppCredential dropboxAppCredential = new DropBoxLocalAppCredential(); private FileSystem getFileSystem(String id) throws IOException { String[] part1s = id.split(":"); diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java index ea41bbe2..c323add3 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java @@ -23,10 +23,10 @@ public enum GoogleDriveCopyOption implements CopyOption { EXPORT_AS_GDOCS("application/vnd.google-apps.document"); /** */ - private String value; + private final String value; /** */ - private GoogleDriveCopyOption(String value) { + GoogleDriveCopyOption(String value) { this.value = value; } diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java index c6c7c47e..f7d51882 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java @@ -33,10 +33,10 @@ public enum GoogleDriveOpenOption implements OpenOption { IMPORT_AS_NEW_REVISION(null); /** depends on enum stuff */ - private String value; + private final String value; /** */ - private GoogleDriveOpenOption(String value) { + GoogleDriveOpenOption(String value) { this.value = value; } diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java index 1098ed9d..f4a253bb 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java @@ -168,9 +168,7 @@ public int read(Metadata entry, ByteBuffer dst) throws IOException { @Override public int write(Metadata entry, ByteBuffer src) throws IOException { String[] revisions = RevisionsUtil.split(src.array()); -Arrays.stream(revisions).forEach(r -> { - Debug.println(Level.FINE, "write " + name() + ": " + r); -}); +Arrays.stream(revisions).forEach(r -> Debug.println(Level.FINE, "write " + name() + ": " + r)); // to be deleted List toDeleted = new ArrayList<>(); Arrays.stream(revisions) @@ -180,7 +178,7 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { toDeleted.addAll(getRevisions(entry).stream() .map(x -> (String) gson.fromJson(x, Map.class).get("id")) .filter(a -> !a.equals(b)) - .collect(Collectors.toList())); + .toList()); } catch (IOException e) { Debug.printStackTrace(Level.WARNING, e); } @@ -272,11 +270,11 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { entry.driver.setThumbnail(entry.file, thumbnail); return thumbnail.length; } - }; + } } /** */ - private static Gson gson = new GsonBuilder().create(); + private static final Gson gson = new GsonBuilder().create(); /** utility */ public static class RevisionsUtil { @@ -291,7 +289,7 @@ public static byte[] getLatestOnly(byte[] revisions) { OffsetDateTime odt2 = OffsetDateTime.parse(o2.get("modifiedTime")); return odt2.compareTo(odt1); }) - .collect(Collectors.toList()); + .toList(); //revisionList.forEach(System.err::println); return gson.toJson(revisionList.get(0)).getBytes(); } diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java index 3e7a8c5d..2358e806 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java @@ -52,7 +52,7 @@ public class GoogleDriveWatchService extends WebHookBaseWatchService callback; + private final Consumer callback; /** * @param args 0: uuid for channel id diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java index 0939cd0a..657dcceb 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java @@ -16,7 +16,6 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; @@ -55,7 +54,7 @@ void test1() throws Exception { if (results.size() > 1) { Debug.println(Level.WARNING, "ambiguous: " + query); results.forEach(System.err::println); - } else if (results.size() == 0) { + } else if (results.isEmpty()) { Debug.println(Level.WARNING, "none: " + query); } else { Debug.println(Level.INFO, "found: " + query); diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java index 8e40b3dd..141ad156 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java @@ -104,7 +104,7 @@ public void testEventForDirectory() throws Exception { public void testEventForDirectoryWatchKey() throws Exception { generateFile(basePath.resolve("newTextFile.txt"), 10); List> eventList = basePathWatchKey.pollEvents(); - while (eventList.size() == 0 ){ + while (eventList.isEmpty()){ eventList = basePathWatchKey.pollEvents(); Thread.sleep(10000); } @@ -115,7 +115,7 @@ public void testEventForDirectoryWatchKey() throws Exception { basePathWatchKey.reset(); generateFile(basePath.resolve("newTextFileII.txt"), 10); generateFile(basePath.resolve("newTextFileIII.txt"), 10); - while (eventList.size() == 0 ){ + while (eventList.isEmpty()){ eventList = basePathWatchKey.pollEvents(); Thread.sleep(10000); } diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java index 96d120dd..a035954f 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java @@ -21,7 +21,6 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.NoSuchFileException; -import java.nio.file.NotDirectoryException; import java.nio.file.Path; import java.nio.file.WatchEvent; import java.nio.file.WatchEvent.Kind; @@ -49,7 +48,6 @@ import static org.junit.jupiter.api.Assertions.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** @@ -98,18 +96,14 @@ public void testRegister() throws IOException { @Test public void testRegister_fileDoesNotExist() throws IOException { - assertThrows(NoSuchFileException.class, () -> { - watcher.register(fs.getPath("/a/b/c"), ImmutableList.of(ENTRY_CREATE)); - }); + assertThrows(NoSuchFileException.class, () -> watcher.register(fs.getPath("/a/b/c"), ImmutableList.of(ENTRY_CREATE))); } @Test public void testRegister_fileIsNotDirectory() throws IOException { Path path = fs.getPath("/a.txt"); Files.createFile(path); - assertThrows(NoSuchFileException.class, () -> { - watcher.register(path, ImmutableList.of(ENTRY_CREATE)); - }); + assertThrows(NoSuchFileException.class, () -> watcher.register(path, ImmutableList.of(ENTRY_CREATE))); } @Test @@ -219,7 +213,7 @@ public void testWatchForMultipleEventTypes() throws IOException, InterruptedExce } private void assertWatcherHasEvents(WatchEvent... events) throws InterruptedException { - assertWatcherHasEvents(Arrays.asList(events), ImmutableList.> of()); + assertWatcherHasEvents(Arrays.asList(events), ImmutableList.of()); } private void assertWatcherHasEvents(List> expected, @@ -241,7 +235,7 @@ private static void ensureTimeToPoll() { } private Path createDirectory() throws IOException { - Path path = fs.getPath("/" + UUID.randomUUID().toString()); + Path path = fs.getPath("/" + UUID.randomUUID()); Files.createDirectory(path); return path; } diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java index 4f9defc7..1b6bb2c7 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java @@ -13,7 +13,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Base64; import java.util.Collections; import java.util.List; @@ -33,8 +32,6 @@ import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.googleapis.notifications.UnparsedNotification; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.Change; import com.google.api.services.drive.model.ChangeList; @@ -106,7 +103,7 @@ public static class AuthorizationConfigurator extends ClientEndpointConfig.Confi public void beforeRequest(Map> headers) { headers.put("Authorization", Collections.singletonList("Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()))); } - }; + } static class Service { Drive driveService; diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java index ef06fe25..62e8da83 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java @@ -6,7 +6,6 @@ package vavi.nio.file.googledrive; -import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; @@ -16,8 +15,6 @@ import java.util.Collections; import com.google.api.client.auth.oauth2.Credential; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; import com.google.api.services.drive.Drive; import vavi.net.auth.WithTotpUserCredential; @@ -58,13 +55,10 @@ void test() throws Exception { Credential credential = new GoogleOAuth2(appCredential).authorize(userCredential); Drive driveService = new Drive.Builder(GoogleOAuth2.getHttpTransport(), GoogleOAuth2.getJsonFactory(), credential) - .setHttpRequestInitializer(new HttpRequestInitializer() { - @Override - public void initialize(HttpRequest httpRequest) throws IOException { - credential.initialize(httpRequest); - httpRequest.setConnectTimeout(30 * 1000); - httpRequest.setReadTimeout(30 * 1000); - } + .setHttpRequestInitializer(httpRequest -> { + credential.initialize(httpRequest); + httpRequest.setConnectTimeout(30 * 1000); + httpRequest.setReadTimeout(30 * 1000); }) .setApplicationName(appCredential.getClientId()) .build(); diff --git a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java index 0f5cf295..063289ac 100644 --- a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java +++ b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java @@ -38,7 +38,7 @@ */ public final class HfsBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes { - private FSEntry entry; // TODO + private final FSEntry entry; // TODO public HfsBasicFileAttributesProvider(@Nonnull final FSEntry entry) throws IOException { this.entry = entry; @@ -65,7 +65,7 @@ public FileTime lastModifiedTime() { */ @Override public boolean isRegularFile() { - return FSFile.class.isInstance(entry); + return entry instanceof FSFile; } /** @@ -73,7 +73,7 @@ public boolean isRegularFile() { */ @Override public boolean isDirectory() { - return FSFolder.class.isInstance(entry); + return entry instanceof FSFolder; } /** diff --git a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java index 3809958b..d01f50bf 100644 --- a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java +++ b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java @@ -11,7 +11,6 @@ import java.util.logging.Level; import org.catacombae.storage.fs.FSFolder; -import org.catacombae.storage.fs.FSForkType; import org.catacombae.storage.fs.hfscommon.HFSCommonFileSystemHandler; import com.github.fge.filesystem.attributes.FileAttributesFactory; diff --git a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java index 2ed0e06e..b0f6007d 100644 --- a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java +++ b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java @@ -126,13 +126,12 @@ private HFSCommonFileSystemHandler loadFSWithUDIFAutodetect(String filename) { throw e; } -Debug.println( - "Unsupported AES key size: " + - "If you were trying to load an AES-256 encrypted image and\n" + - "are using Sun/Oracle's Java Runtime Environment, then \n" + - "please check if you have installed the Java Cryptography\n" + - "Extension (JCE) Unlimited Strength Jurisdiction Policy\n" + - "Files, which are required for AES-256 support in Java."); +Debug.println(""" + Unsupported AES key size: If you were trying to load an AES-256 encrypted image and + are using Sun/Oracle's Java Runtime Environment, then\s + please check if you have installed the Java Cryptography + Extension (JCE) Unlimited Strength Jurisdiction Policy + Files, which are required for AES-256 support in Java."""); } } catch (Exception e) { throw new IllegalArgumentException("Reading encrypted disk image...: " + "Incorrect password."); @@ -210,11 +209,11 @@ private HFSCommonFileSystemHandler loadFS(SynchronizedReadableRandomAccessStream PartitionSystemType[] matchingTypes = PartitionSystemDetector.detectPartitionSystem(syncStream, false); if (matchingTypes.length > 1) { - String message = "Multiple partition system types detected:"; + StringBuilder message = new StringBuilder("Multiple partition system types detected:"); for (PartitionSystemType type : matchingTypes) { - message += "\n" + type; + message.append("\n").append(type); } - throw new IllegalArgumentException(message); + throw new IllegalArgumentException(message.toString()); } else if (matchingTypes.length == 1) { PartitionSystemType psType = matchingTypes[0]; @@ -289,23 +288,14 @@ private HFSCommonFileSystemHandler loadFS(SynchronizedReadableRandomAccessStream case HFS_PLUS: case HFSX: - final FileSystemMajorType fsMajorType; - switch (fsType) { - case HFS: - fsMajorType = FileSystemMajorType.APPLE_HFS; - break; - case HFS_PLUS: - case HFS_WRAPPED_HFS_PLUS: - fsMajorType = FileSystemMajorType.APPLE_HFS_PLUS; - break; - case HFSX: - fsMajorType = FileSystemMajorType.APPLE_HFSX; - break; - default: - throw new IllegalArgumentException("Unhandled type: " + fsType); - } + final FileSystemMajorType fsMajorType = switch (fsType) { + case HFS -> FileSystemMajorType.APPLE_HFS; + case HFS_PLUS, HFS_WRAPPED_HFS_PLUS -> FileSystemMajorType.APPLE_HFS_PLUS; + case HFSX -> FileSystemMajorType.APPLE_HFSX; + default -> throw new IllegalArgumentException("Unhandled type: " + fsType); + }; -boolean cachingEnabled = true; // TODO env + boolean cachingEnabled = true; // TODO env FileSystemHandlerFactory factory = fsMajorType.createDefaultHandlerFactory(); if (factory.isSupported(StandardAttribute.CACHING_ENABLED)) { factory.getCreateAttributes().setBooleanAttribute( diff --git a/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java b/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java index 6ce50b38..77c36151 100644 --- a/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java +++ b/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIf; import vavi.util.Debug; import vavi.util.properties.annotation.Property; diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java index 00c2cf71..31f0808b 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java @@ -169,9 +169,7 @@ protected void onClosed() throws IOException { /** OneDriveUploadOption */ private OutputStream uploadEntry(OneItem parentEntry, Path path, int size) throws IOException { - OneUpload uploader = asFolder(parentEntry).upload(toFilenameString(path), size, newEntry -> { - updateEntry(path, newEntry); - }); + OneUpload uploader = asFolder(parentEntry).upload(toFilenameString(path), size, newEntry -> updateEntry(path, newEntry)); return new BufferedOutputStream(uploader.upload(), Util.BUFFER_SIZE); } @@ -187,7 +185,7 @@ protected OneItem createDirectoryEntry(OneItem parentEntry, Path dir) throws IOE @Override protected boolean hasChildren(OneItem dirEntry, Path dir) throws IOException { - return client.getFolderByPath(toPathString(dir)).getChildren().size() > 0; + return !client.getFolderByPath(toPathString(dir)).getChildren().isEmpty(); } @Override diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java index 084db41c..26e1161e 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java @@ -58,7 +58,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th WithTotpUserCredential userCredential = null; if (env.containsKey(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = WithTotpUserCredential.class.cast(env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (WithTotpUserCredential) env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); @@ -76,7 +76,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th OAuth2AppCredential appCredential = null; if (env.containsKey(OneDriveFileSystemProvider.ENV_APP_CREDENTIAL)) { - appCredential = OAuth2AppCredential.class.cast(env.get(OneDriveFileSystemProvider.ENV_APP_CREDENTIAL)); + appCredential = (OAuth2AppCredential) env.get(OneDriveFileSystemProvider.ENV_APP_CREDENTIAL); } if (appCredential == null) { @@ -117,7 +117,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th } }; oauth2.writeRefreshToken(callback); - client.startSessionAutoRefresh(() -> { oauth2.writeRefreshToken(callback); }); + client.startSessionAutoRefresh(() -> oauth2.writeRefreshToken(callback)); final OneDriveFileStore fileStore = new OneDriveFileStore(client, factoryProvider.getAttributesFactory()); return new OneDriveFileSystemDriver(fileStore, factoryProvider, client, env); diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java index b832f58d..0cb43c88 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java @@ -6,6 +6,8 @@ package vavi.nio.file.onedrive; +import java.io.Serial; +import java.io.Serializable; import java.nio.file.CopyOption; import java.nio.file.OpenOption; import java.nio.file.Path; @@ -23,13 +25,14 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/31 umjammer initial version
*/ -public class OneDriveUploadOption implements OpenOption, CopyOption { +public class OneDriveUploadOption implements OpenOption, CopyOption, Serializable { /** */ + @Serial private static final long serialVersionUID = -3760090552182064957L; /** */ - private Path source; + private final Path source; /** */ public OneDriveUploadOption(Path source) { @@ -43,7 +46,7 @@ public Path getSource() { @Override public boolean equals(Object other) { - return other != null && OneDriveUploadOption.class.isInstance(other); // TODO ad-hoc + return other instanceof OneDriveUploadOption; // TODO ad-hoc } @Override diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java index ac7d9d42..cf238e2c 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java @@ -37,7 +37,7 @@ public class OneDriveWebSocketNotification extends StringWebSocketNotification { private static final URI uri = URI.create(websocketBaseUrl + websocketPath); - private Consumer callback; + private final Consumer callback; /** * @param args diff --git a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java index 763d707b..5419ad34 100644 --- a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java +++ b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java @@ -50,7 +50,7 @@ public class App { private static OneFolder currentFolder; - ExecutorService executor = Executors.newFixedThreadPool(5); + final ExecutorService executor = Executors.newFixedThreadPool(5); private OneDriveSDK api; private Map currentFolderFiles = Maps.newHashMap(); private Map currentFolderFolders = Maps.newHashMap(); @@ -177,7 +177,7 @@ public void deleteItem(@Param(name = "index", description = "Index of file you w item = (OneItem) this.currentFolderFolders.get(index); if (item != null) { - System.out.println(String.format("Deleting %s", item.getName())); + System.out.printf("Deleting %s%n", item.getName()); item.delete(); } else { System.out.println("Can not find item with index '" + index + "'"); @@ -187,14 +187,14 @@ public void deleteItem(@Param(name = "index", description = "Index of file you w @Command(description = "Creates a subfolder in the currentFolder") public void createFolder(@Param(name = "folderName", description = "The name of the new Folder that should be created") String folderName) throws IOException, OneDriveException { - System.out.println(String.format("Creating %s in %s", folderName, currentFolder.getName())); + System.out.printf("Creating %s in %s%n", folderName, currentFolder.getName()); currentFolder.createFolder(folderName); } @Command public void downloadItem(@Param(name = "index", description = "Index of the file you want to download") String index, @Param(name = "targetFileName", description = "path where to download to") String pathToDownload) throws IOException { - System.out.println(String.format("Downloading %s to %s", currentFolderFiles.get(index).getName(), pathToDownload)); + System.out.printf("Downloading %s to %s%n", currentFolderFiles.get(index).getName(), pathToDownload); OneFile tmpFile = currentFolderFiles.get(index); try { tmpFile.download(new File(pathToDownload)).startDownload(); @@ -221,7 +221,7 @@ private void printItemList(Map map) { List itemKeys = new ArrayList<>(map.keySet()); Collections.sort(itemKeys); for (String key : itemKeys) { - System.out.println(String.format("Item %s = %s", key, map.get(key))); + System.out.printf("Item %s = %s%n", key, map.get(key)); } } } diff --git a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java index f9bb7f29..62ea8b04 100644 --- a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java +++ b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java @@ -98,7 +98,7 @@ interface Replacer { this.replacer = replacer; } - class Pair { + static class Pair { Pair(Path source, Path target) { this.source = source; this.target = target; diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java index 740b9f89..03f6311c 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java @@ -12,6 +12,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.FileStore; import java.nio.file.OpenOption; @@ -174,14 +175,12 @@ protected void onClosed() throws IOException { private OutputStream uploadEntry(DriveItem.Metadata parentEntry, Path path, int size) throws IOException { DriveItem file = new DriveItem(asDriveItem(parentEntry), toItemPathString(toFilenameString(path))); final UploadSession uploadSession = Files.createUploadSession(file); - return new BufferedOutputStream(new OneDriveOutputStream(uploadSession, path, size, newEntry -> { - updateEntry(path, newEntry); - }), Util.BUFFER_SIZE); + return new BufferedOutputStream(new OneDriveOutputStream(uploadSession, path, size, newEntry -> updateEntry(path, newEntry)), Util.BUFFER_SIZE); } /** ms-graph doesn't accept '+' in a path string */ private String toItemPathString(String pathString) throws IOException { - return URLEncoder.encode(pathString, "utf-8").replace("+", "%20"); + return URLEncoder.encode(pathString, StandardCharsets.UTF_8).replace("+", "%20"); } @Override @@ -213,12 +212,10 @@ protected DriveItem.Metadata copyEntry(DriveItem.Metadata sourceEntry, DriveItem Debug.println(Level.FINE, "target: " + targetParentEntry.getName()); operation.copy(asDriveItem(targetParentEntry)); OneDriveLongRunningAction action = Files.copy(asDriveItem(sourceEntry), operation); - action.await(statusObject -> { -Debug.printf(Level.FINE, "Copy Progress Operation %s progress %.0f %%, status %s", - statusObject.getOperation(), - statusObject.getPercentage(), - statusObject.getStatus()); - }); + action.await(statusObject -> Debug.printf(Level.FINE, "Copy Progress Operation %s progress %.0f %%, status %s", + statusObject.getOperation(), + statusObject.getPercentage(), + statusObject.getStatus())); return getEntry(null, target); } diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java index ebc8e99a..f8f416f7 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java @@ -59,7 +59,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th WithTotpUserCredential userCredential = null; if (env.containsKey(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = WithTotpUserCredential.class.cast(env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (WithTotpUserCredential) env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java index 6bd08a82..de7c2b6f 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java @@ -6,6 +6,7 @@ package vavi.nio.file.onedrive3; +import java.io.Serial; import java.io.Serializable; import java.nio.file.CopyOption; import java.nio.file.OpenOption; @@ -29,6 +30,7 @@ public class OneDriveUploadOption implements OpenOption, CopyOption, Serializable { /** */ + @Serial private static final long serialVersionUID = 5575546140441990410L; /** */ diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java index f4c09b11..09e404e4 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java @@ -37,7 +37,7 @@ public class MicrosoftWebSocketNotification extends StringWebSocketNotification private static final URI uri = URI.create(websocketBaseUrl + websocketPath); - private Consumer callback; + private final Consumer callback; /** * @param args diff --git a/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java b/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java index 90ae7e71..aa395bae 100644 --- a/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java +++ b/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java @@ -107,7 +107,7 @@ public String getEmailURL() { DriveItem.Metadata child = i.next(); if (child.getName().equals("TEST_WEBHOOK")) { System.out.println("rmdir " + child.getName()); - Files.delete(DriveItem.class.cast(child.getItem())); + Files.delete((DriveItem) child.getItem()); } } System.out.println("mkdir " + "TEST_WEBHOOK"); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java index 0db4ba7d..49f2bdd2 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java @@ -111,11 +111,12 @@ private Quota getQuota() throws IOException { if (cache != null) { return cache; } else { - client.drive().buildRequest().get(new ICallback() { + client.drive().buildRequest().get(new ICallback<>() { @Override public void success(final Drive result) { cache = result.quota; } + @Override public void failure(ClientException ex) { } diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java index ef41647c..d3eb5aec 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.FileStore; import java.nio.file.Files; @@ -196,21 +197,23 @@ private OutputStream uploadEntry(Path path, int size) throws IOException { UploadSession uploadSession = client.drive().root().itemWithPath(toItemPathString(toPathString(path))).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); vavi.nio.file.onedrive4.graph.ChunkedUploadProvider chunkedUploadProvider = new vavi.nio.file.onedrive4.graph.ChunkedUploadProvider<>(uploadSession, client, size, DriveItem.class); - return new BufferedOutputStream(chunkedUploadProvider.upload(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { -Debug.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - updateEntry(path, result); -Debug.println("upload done: " + result.name); - } - @Override - public void failure(final ClientException ex) { - // never called - } - }), threshold); + return new BufferedOutputStream(chunkedUploadProvider.upload(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + Debug.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + updateEntry(path, result); + Debug.println("upload done: " + result.name); + } + + @Override + public void failure(final ClientException ex) { + // never called + } + }), threshold); } else { return new Util.OutputStreamForUploading() { @Override @@ -229,21 +232,23 @@ private void uploadEntry(Path path, InputStream is, int size) throws IOException UploadSession uploadSession = client.drive().root().itemWithPath(toItemPathString(toPathString(path))).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); ChunkedUploadProvider chunkedUploadProvider = new ChunkedUploadProvider<>(uploadSession, client, is, size, DriveItem.class); - chunkedUploadProvider.upload(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { -Debug.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - updateEntry(path, result); -Debug.println("upload done: " + result.name); - } - @Override - public void failure(final ClientException ex) { - throw ex; - } - }); + chunkedUploadProvider.upload(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + Debug.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + updateEntry(path, result); + Debug.println("upload done: " + result.name); + } + + @Override + public void failure(final ClientException ex) { + throw ex; + } + }); } else { DriveItem newEntry = client.drive().root().itemWithPath(toItemPathString(toPathString(path))).content().buildRequest().put(ByteStreams.toByteArray(is)); // TODO depends on guava updateEntry(path, newEntry); @@ -252,7 +257,7 @@ public void failure(final ClientException ex) { /** ms-graph doesn't accept '+' in a path string */ private String toItemPathString(String pathString) throws IOException { - return URLEncoder.encode(pathString.replaceFirst("^\\/", ""), "utf-8").replace("+", "%20"); + return URLEncoder.encode(pathString.replaceFirst("^\\/", ""), StandardCharsets.UTF_8).replace("+", "%20"); } @Override @@ -303,16 +308,18 @@ protected DriveItem copyEntry(DriveItem sourceEntry, DriveItem targetParentEntry @SuppressWarnings({ "unchecked", "rawtypes" }) // TODO LraSession copySession = client.getHttpProvider().send((IHttpRequest) request, LraMonitorResult.class, body, (IStatefulResponseHandler) handler).getSession(); LraMonitorProvider copyMonitorProvider = new LraMonitorProvider<>(copySession, client, DriveItem.class); - copyMonitorProvider.monitor(new IProgressCallback() { + copyMonitorProvider.monitor(new IProgressCallback<>() { @Override public void progress(final long current, final long max) { -Debug.println("copy progress: " + current + "/" + max); + Debug.println("copy progress: " + current + "/" + max); } + @Override public void success(final DriveItem result) { -Debug.println("copy done: " + result.id); + Debug.println("copy done: " + result.id); updateEntry(target, result); } + @Override public void failure(final ClientException ex) { throw new IllegalStateException(ex); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java index e5250430..07c836da 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java @@ -17,7 +17,6 @@ import com.github.fge.filesystem.driver.FileSystemDriver; import com.github.fge.filesystem.provider.FileSystemRepositoryBase; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.IGraphServiceClient; import com.microsoft.graph.requests.extensions.GraphServiceClient; diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java index 83f38eb3..803f02ac 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java @@ -6,6 +6,8 @@ package vavi.nio.file.onedrive4; +import java.io.Serial; +import java.io.Serializable; import java.nio.file.CopyOption; import java.nio.file.OpenOption; import java.nio.file.Path; @@ -23,13 +25,14 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/31 umjammer initial version
*/ -public class OneDriveUploadOption implements OpenOption, CopyOption { +public class OneDriveUploadOption implements OpenOption, CopyOption, Serializable { /** */ + @Serial private static final long serialVersionUID = -3760090552182064957L; /** */ - private Path source; + private final Path source; /** */ public OneDriveUploadOption(Path source) { @@ -43,7 +46,7 @@ public Path getSource() { @Override public boolean equals(Object other) { - return other != null && OneDriveUploadOption.class.isInstance(other); // TODO ad-hoc + return other instanceof OneDriveUploadOption; // TODO ad-hoc } @Override diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java index fe1e2443..38af5541 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java @@ -95,7 +95,7 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { /** whole image file */ thumbnail { /** */ - Map thumbnailCache = new ConcurrentHashMap<>(); // TODO LRU + final Map thumbnailCache = new ConcurrentHashMap<>(); // TODO LRU /** */ private String getUrl(Metadata entry) throws IOException { @@ -155,7 +155,7 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { entry.driver.setThumbnail(entry.driveItem, thumbnail); return thumbnail.length; } - }; + } } } diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java index 137f7d9b..19cf7be8 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java @@ -96,8 +96,8 @@ public void monitor(final IProgressCallback callback, final int... while (!finished) { try { - Thread.sleep(1 << timeout); - } catch (InterruptedException e) { + Thread.sleep(1L << timeout); + } catch (InterruptedException ignored) { } LraMonitorRequest request = new LraMonitorRequest(this.monitorUrl, this.client); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java index 779db189..d10fb60e 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java @@ -6,11 +6,8 @@ package vavi.nio.file.onedrive4.graph; -import com.microsoft.graph.authentication.IAuthenticationProvider; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; -import com.microsoft.graph.http.IHttpRequest; -import com.microsoft.graph.http.IStatefulResponseHandler; import com.microsoft.graph.models.extensions.IGraphServiceClient; import com.microsoft.graph.requests.extensions.GraphServiceClient; @@ -33,10 +30,7 @@ public class LraMonitorRequest { */ public LraMonitorRequest(final String requestUrl, IGraphServiceClient client) { IGraphServiceClient clientWithoutAuth = GraphServiceClient.builder() - .authenticationProvider(new IAuthenticationProvider() { - @Override - public void authenticateRequest(IHttpRequest request) { - } + .authenticationProvider(request -> { }) .logger(client.getLogger()) .buildClient(); @@ -55,9 +49,9 @@ public void authenticateRequest(IHttpRequest request) { public LraMonitorResult monitor(final LraMonitorResponseHandler responseHandler) { return this.baseRequest.getClient() .getHttpProvider() - .send((IHttpRequest) baseRequest, + .send(baseRequest, LraMonitorResult.class, null, - (IStatefulResponseHandler) responseHandler); + responseHandler); } } diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java index 671cb754..27e20378 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java @@ -40,7 +40,7 @@ public void setRawObject(ISerializer serializer, JsonObject json) { Debug.println(json); } - private transient AdditionalDataManager additionalDataManager = new AdditionalDataManager(this); + private final transient AdditionalDataManager additionalDataManager = new AdditionalDataManager(this); @Override public final AdditionalDataManager additionalDataManager() { diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java index e2b6943c..11829e2c 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java @@ -6,14 +6,12 @@ package vavi.nio.file.onedrive4.graph; - import java.io.IOException; import java.security.InvalidParameterException; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; import com.microsoft.graph.http.HttpResponseCode; -import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.DriveItem; import com.microsoft.graph.models.extensions.IGraphServiceClient; @@ -22,8 +20,6 @@ /** * ThumbnailUpload service provider - * - * @param the upload item type */ public class ThumbnailUploadProvider { @@ -40,13 +36,10 @@ public class ThumbnailUploadProvider { /** * Creates the ChunkedUploadProvider * - * @param uploadSession the initial upload session - * @param client the Graph client - * @param streamSize the stream size - * @param uploadTypeClass the upload type class + * @param item the upload item + * @param client the Graph client */ - public ThumbnailUploadProvider(final DriveItem item, - final IGraphServiceClient client) { + public ThumbnailUploadProvider(DriveItem item, IGraphServiceClient client) { if (item == null) { throw new InvalidParameterException("item is null."); } @@ -66,17 +59,16 @@ public ThumbnailUploadProvider(final DriveItem item, * @param image the thumbnail bytes * @throws IOException the IO exception that occurred during upload */ - public void upload(byte[] image) - throws IOException { + public void upload(byte[] image) throws IOException { BaseRequest request = new BaseRequest(uploadUrl, client, null, Integer.class) {{ setHttpMethod(HttpMethod.PUT); }}; int result = client.getHttpProvider().send( - (IHttpRequest) request, - Integer.class, - image, - new ThumbnailUploadResponseHandler()); + request, + Integer.class, + image, + new ThumbnailUploadResponseHandler()); if (result != HttpResponseCode.HTTP_OK) { throw new IOException(String.valueOf(result)); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java index d12f3bde..0245392c 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java @@ -37,7 +37,7 @@ public class MicrosoftWebSocketNotification extends StringWebSocketNotification private static final URI uri = URI.create(websocketBaseUrl + websocketPath); - private Consumer callback; + private final Consumer callback; /** * @param args diff --git a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java index edb633bf..279749dc 100644 --- a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java +++ b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java @@ -33,9 +33,9 @@ public class OneDriveEasyFS implements EasyFS { /** */ - private MicrosoftGraphOAuth2 auth2; + private final MicrosoftGraphOAuth2 auth2; /** */ - private IGraphServiceClient client; + private final IGraphServiceClient client; /** */ public OneDriveEasyFS(String email) throws IOException { diff --git a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java index ff428156..79652552 100644 --- a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java +++ b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java @@ -10,13 +10,13 @@ import java.io.InputStream; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Collections; -import com.microsoft.graph.authentication.IAuthenticationProvider; import com.microsoft.graph.concurrency.ChunkedUploadProvider; import com.microsoft.graph.concurrency.IProgressCallback; import com.microsoft.graph.core.ClientException; @@ -109,9 +109,9 @@ void auth(String email) throws IOException { void testList() throws IOException { client.me().drive().root().children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); - client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels", "utf-8")).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); + client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels", StandardCharsets.UTF_8)).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); - client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels/あ", "utf-8")).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); + client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels/あ", StandardCharsets.UTF_8)).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); } /** */ @@ -120,29 +120,31 @@ void testUpload() throws IOException { Path path = Paths.get(System.getenv("HOME"), "Music/0/rc.wav"); InputStream is = Files.newInputStream(path.toFile().toPath()); - UploadSession uploadSession = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", "utf-8")).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); + UploadSession uploadSession = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", StandardCharsets.UTF_8)).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); ChunkedUploadProvider chunkedUploadProvider = new ChunkedUploadProvider<>(uploadSession, client, is, is.available(), DriveItem.class); - chunkedUploadProvider.upload(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { - System.err.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - System.err.println("done"); - } - @Override - public void failure(final ClientException ex) { - throw new IllegalStateException(ex); - } - }); + chunkedUploadProvider.upload(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + System.err.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + System.err.println("done"); + } + + @Override + public void failure(final ClientException ex) { + throw new IllegalStateException(ex); + } + }); } /** */ void testDelete(String name) throws IOException { try { - client.drive().root().itemWithPath(URLEncoder.encode(name, "utf-8")).buildRequest().delete(); + client.drive().root().itemWithPath(URLEncoder.encode(name, StandardCharsets.UTF_8)).buildRequest().delete(); } catch (GraphServiceException e) { if (!e.getMessage().startsWith("Error code: itemNotFound")) { throw e; @@ -156,8 +158,8 @@ void testDelete(String name) throws IOException { void testCopy() throws IOException { testDelete("test/フォルダー/コピー.wav"); - DriveItem src = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", "utf-8")).buildRequest().get(); - DriveItem dst = client.drive().root().itemWithPath(URLEncoder.encode("test/フォルダー", "utf-8")).buildRequest().get(); + DriveItem src = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", StandardCharsets.UTF_8)).buildRequest().get(); + DriveItem dst = client.drive().root().itemWithPath(URLEncoder.encode("test/フォルダー", StandardCharsets.UTF_8)).buildRequest().get(); ItemReference ir = new ItemReference(); @@ -171,20 +173,22 @@ void testCopy() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) // TODO LraSession copySession = client.getHttpProvider().send((IHttpRequest) request, LraMonitorResult.class, body, (IStatefulResponseHandler) handler).getSession(); LraMonitorProvider copyMonitorProvider = new LraMonitorProvider<>(copySession, client, DriveItem.class); - copyMonitorProvider.monitor(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { - System.err.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - System.err.println("done: " + result.getRawObject()); - } - @Override - public void failure(final ClientException ex) { - ex.printStackTrace(); - } - }); + copyMonitorProvider.monitor(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + System.err.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + System.err.println("done: " + result.getRawObject()); + } + + @Override + public void failure(final ClientException ex) { + ex.printStackTrace(); + } + }); } /** */ diff --git a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java index 4be798cd..c300b873 100644 --- a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java +++ b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java @@ -10,7 +10,6 @@ import java.util.Calendar; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.DriveItem; import com.microsoft.graph.models.extensions.Folder; import com.microsoft.graph.models.extensions.IGraphServiceClient; @@ -60,12 +59,7 @@ public static void main(String[] args) throws Exception { String accessToken = new MicrosoftGraphOAuth2(appCredential, true).authorize(userCredential); //Debug.println("accessToken: " + accessToken); - IAuthenticationProvider authenticationProvider = new IAuthenticationProvider() { - @Override - public void authenticateRequest(IHttpRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken); - } - }; + IAuthenticationProvider authenticationProvider = request -> request.addHeader("Authorization", "Bearer " + accessToken); IGraphServiceClient graphClient = GraphServiceClient.builder() .authenticationProvider(authenticationProvider) .logger(new MyLogger()) diff --git a/vavi-nio-file-sandbox/src/test/java/Classification2.java b/vavi-nio-file-sandbox/src/test/java/Classification2.java index 8ccf7d07..cbb99165 100644 --- a/vavi-nio-file-sandbox/src/test/java/Classification2.java +++ b/vavi-nio-file-sandbox/src/test/java/Classification2.java @@ -121,12 +121,12 @@ private static String toKana(String text) throws IOException{ } } //System.err.println(sb); - return sb.length() == 0 ? text : sb.toString(); + return sb.isEmpty() ? text : sb.toString(); } static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); Path root; diff --git a/vavi-nio-file-sandbox/src/test/java/Classification3.java b/vavi-nio-file-sandbox/src/test/java/Classification3.java index e72f29a4..8c6dd70a 100644 --- a/vavi-nio-file-sandbox/src/test/java/Classification3.java +++ b/vavi-nio-file-sandbox/src/test/java/Classification3.java @@ -86,7 +86,7 @@ void classify(Path root) throws IOException { /** */ static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); Pattern pattern = Pattern.compile("[あかさたなはまやらわ]"); diff --git a/vavi-nio-file-sandbox/src/test/java/CloserFinder.java b/vavi-nio-file-sandbox/src/test/java/CloserFinder.java index 5b75b45f..52587bda 100644 --- a/vavi-nio-file-sandbox/src/test/java/CloserFinder.java +++ b/vavi-nio-file-sandbox/src/test/java/CloserFinder.java @@ -46,30 +46,28 @@ public static void main(String[] args) throws IOException { MyFileVisitor fileSearcher = new MyFileVisitor(); Files.walkFileTree(root, fileSearcher); fileSearcher.result().parallelStream() - .forEach(path1 -> { - fileSearcher.result().parallelStream() - .forEach(path2 -> { - try { - if (!path1.equals(path2)) { - String filename1 = Util.toFilenameString(path1); - String filename2 = Util.toFilenameString(path2); - int d = LevenshteinDistance.calculate(filename1, filename2); - if (d > 1 && d < 5) { - System.err.println(path1 + ": " + path2); - } + .forEach(path1 -> fileSearcher.result().parallelStream() + .forEach(path2 -> { + try { + if (!path1.equals(path2)) { + String filename1 = Util.toFilenameString(path1); + String filename2 = Util.toFilenameString(path2); + int d = LevenshteinDistance.calculate(filename1, filename2); + if (d > 1 && d < 5) { + System.err.println(path1 + ": " + path2); } - } catch (IOException e) { - throw new IllegalStateException(e); } - }); - }); + } catch (IOException e) { + throw new IllegalStateException(e); + } + })); fs.close(); } static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { diff --git a/vavi-nio-file-sandbox/src/test/java/Descriptor.java b/vavi-nio-file-sandbox/src/test/java/Descriptor.java index 721ac474..d5f74d20 100644 --- a/vavi-nio-file-sandbox/src/test/java/Descriptor.java +++ b/vavi-nio-file-sandbox/src/test/java/Descriptor.java @@ -79,21 +79,20 @@ public static class Result { String isbn13; @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Result [title="); - builder.append(title); - builder.append(", authors="); - builder.append(authors); - builder.append(", publishedDate="); - builder.append(publishedDate); - builder.append(", description="); - builder.append(description); - builder.append(", isbn10="); - builder.append(isbn10); - builder.append(", isbn13="); - builder.append(isbn13); - builder.append("]"); - return builder.toString(); + String builder = "Result [title=" + + title + + ", authors=" + + authors + + ", publishedDate=" + + publishedDate + + ", description=" + + description + + ", isbn10=" + + isbn10 + + ", isbn13=" + + isbn13 + + "]"; + return builder; } public String toFormatedString() { StringBuilder builder = new StringBuilder(); diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java index daa8d996..57b0ba64 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java @@ -5,23 +5,17 @@ */ import java.io.IOException; -import java.io.OutputStream; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.stream.Stream; import vavi.nio.file.Util; import vavi.nio.file.googledrive.GoogleDriveFileSystemProvider; -import vavi.nio.file.googledrive.GoogleDriveOpenOption; -import vavi.nio.file.googledrive.GoogleDriveUserDefinedFileAttributesProvider; import vavi.util.Debug; import static vavi.nio.file.googledrive.GoogleDriveFileSystemDriver.fileSearcher; @@ -77,7 +71,7 @@ void func1(Path file) { if (results.size() > 1) { Debug.println(Level.WARNING, "ambiguous: " + normalized); results.forEach(System.err::println); - } else if (results.size() == 0) { + } else if (results.isEmpty()) { Debug.println(Level.WARNING, "none: " + normalized); } else { count++; diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java index 75b5d37a..6ac7ffae 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java @@ -20,7 +20,6 @@ import vavi.nio.file.Util; import vavi.nio.file.googledrive.GoogleDriveFileSystemProvider; -import vavi.util.Debug; import static java.nio.file.FileVisitResult.CONTINUE; diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java index ec7e8634..5bf8c50c 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java @@ -198,7 +198,7 @@ void func2(Path file) throws IOException { return a.compareTo(b); } }); - if (names.size() == 0) { + if (names.isEmpty()) { zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(file))); while ((entry = zis.getNextEntry()) != null) { System.err.println(entry.getName()); diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java index 5be3d136..755632eb 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java @@ -84,7 +84,7 @@ void func1(Path file) { Debug.println(Level.WARNING, "ambiguous: " + query); results.forEach(System.err::println); return; - } else if (results.size() == 0) { + } else if (results.isEmpty()) { Debug.println(Level.WARNING, "none: " + query); return; } else { diff --git a/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java b/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java index 31ba6b3f..872ee12e 100644 --- a/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java +++ b/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java @@ -190,7 +190,7 @@ static void func2(Path file) throws IOException { } // determine cover - Collections.sort(names, (a, b) -> { + names.sort((a, b) -> { if (a.contains("表紙") && !b.contains("表紙")) { return -1; } else if (!a.contains("表紙") && b.contains("表紙")) { @@ -203,7 +203,7 @@ static void func2(Path file) throws IOException { return a.compareTo(b); } }); - if (names.size() == 0) { + if (names.isEmpty()) { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(file)), Charset.forName(sjis ? "MS932" : "UTF-8")); while ((entry = zis.getNextEntry()) != null) { System.err.println(entry.getName()); @@ -257,9 +257,9 @@ static void func3(Path file) throws Exception { // exec // convert path from google drive fs to default fs - // because "zipfs" dosn't accept googledrive as sub scheme + // because "zipfs" doesn't accept googledrive as sub scheme Path gd = Paths.get("/Volumes/GoogleDrive/My Drive", file.toString()); - URI uri = URI.create("jar:" + gd.toUri().toString()); + URI uri = URI.create("jar:" + gd.toUri()); Debug.println("uri: " + uri); FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap()); diff --git a/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java b/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java index 7ded0c0b..2859f717 100644 --- a/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java +++ b/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java @@ -75,7 +75,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) { } boolean filter1(Path path) throws IOException { - return Files.list(path).count() == 0; + return Files.list(path).findAny().isEmpty(); } boolean filter2(Path path) throws IOException { diff --git a/vavi-nio-file-sandbox/src/test/java/Synchronizer.java b/vavi-nio-file-sandbox/src/test/java/Synchronizer.java index 39d9a9a5..d250b672 100644 --- a/vavi-nio-file-sandbox/src/test/java/Synchronizer.java +++ b/vavi-nio-file-sandbox/src/test/java/Synchronizer.java @@ -76,7 +76,7 @@ public static void main(String[] args) throws IOException { static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { diff --git a/vavi-nio-file-sandbox/src/test/java/Test1.java b/vavi-nio-file-sandbox/src/test/java/Test1.java index 52d00712..3f0c90f8 100644 --- a/vavi-nio-file-sandbox/src/test/java/Test1.java +++ b/vavi-nio-file-sandbox/src/test/java/Test1.java @@ -61,11 +61,11 @@ void setup() throws Exception { public void test() { String location = "https://login.live.com/oauth20_authorize.srf?client_id=0000000040184284&scope=wl.offline_access&response_type=code&redirect_uri=https%3A%2F%2Fvast-plateau-97564.herokuapp.com%2Fonedrive_set"; String url = "https://login.live.com/oauth20_authorize.srf"; - assertTrue(location.indexOf(url) == 0); + assertEquals(0, location.indexOf(url)); String location2 = "https://vast-plateau-97564.herokuapp.com/onedrive_set?code=M2739c1c0-460c-2ac5-8e94-f9b8fdf3dd5c"; String redirectUrl = "https://vast-plateau-97564.herokuapp.com/onedrive_set"; - assertTrue(location2.indexOf(redirectUrl) == 0); + assertEquals(0, location2.indexOf(redirectUrl)); } @Test diff --git a/vavi-nio-file-sandbox/src/test/java/TestAozora.java b/vavi-nio-file-sandbox/src/test/java/TestAozora.java index 921ea63e..4211d469 100644 --- a/vavi-nio-file-sandbox/src/test/java/TestAozora.java +++ b/vavi-nio-file-sandbox/src/test/java/TestAozora.java @@ -77,7 +77,7 @@ public String getAuthor() { static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { diff --git a/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java b/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java index 39db84d9..ea19b27f 100644 --- a/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java +++ b/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java @@ -1,4 +1,3 @@ -package vavi.nio.file.watch; /* * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -22,24 +21,17 @@ * questions. */ -/* @test - * @bug 4313887 6838333 7017446 8011537 8042470 - * @summary Unit test for java.nio.file.WatchService - * @library .. - * @run main Basic - */ - - +package vavi.nio.file.watch; import java.io.IOException; import java.io.OutputStream; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.nio.file.ClosedWatchServiceException; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; @@ -50,18 +42,21 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - import vavi.nio.file.googledrive.GoogleDriveFileSystemProvider; +import vavi.util.Debug; import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; import static java.nio.file.StandardWatchEventKinds.OVERFLOW; +import static org.junit.jupiter.api.Assertions.assertThrows; import static vavi.nio.file.Base.removeTree; /** * Unit test for WatchService that exercises all methods in various scenarios. + * + * @bug 4313887 6838333 7017446 8011537 8042470 */ @Disabled public class WatchServiceTest { @@ -74,7 +69,7 @@ void checkKey(WatchKey key, Path dir) { } void takeExpectedKey(WatchService watcher, WatchKey expected) { - System.out.println("take events..."); + Debug.println("take events..."); WatchKey key; try { key = watcher.take(); @@ -88,10 +83,9 @@ void takeExpectedKey(WatchService watcher, WatchKey expected) { void checkExpectedEvent(Iterable> events, WatchEvent.Kind expectedKind, - Object expectedContext) - { + Object expectedContext) { WatchEvent event = events.iterator().next(); - System.out.format("got event: type=%s, count=%d, context=%s\n", + Debug.printf("got event: type=%s, count=%d, context=%s\n", event.kind(), event.count(), event.context()); if (event.kind() != expectedKind) throw new RuntimeException("unexpected event"); @@ -106,7 +100,7 @@ void checkExpectedEvent(Iterable> events, */ @Test void testEvents() throws IOException { - System.out.println("-- Standard Events --"); + Debug.println("-- Standard Events --"); Path name = fs.getPath("foo"); @@ -114,70 +108,64 @@ void testEvents() throws IOException { // --- ENTRY_CREATE --- // register for event - System.out.format("register %s for ENTRY_CREATE\n", dir); - WatchKey myKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE }); + Debug.printf("register %s for ENTRY_CREATE\n", dir); + WatchKey myKey = dir.register(watcher, ENTRY_CREATE); checkKey(myKey, dir); // create file Path file = dir.resolve("foo"); - System.out.format("create %s\n", file); + Debug.printf("create %s\n", file); Files.createFile(file); // remove key and check that we got the ENTRY_CREATE event takeExpectedKey(watcher, myKey); - checkExpectedEvent(myKey.pollEvents(), - StandardWatchEventKinds.ENTRY_CREATE, name); + checkExpectedEvent(myKey.pollEvents(), ENTRY_CREATE, name); - System.out.println("reset key"); + Debug.println("reset key"); if (!myKey.reset()) throw new RuntimeException("key has been cancalled"); - System.out.println("OKAY"); + Debug.println("OKAY"); // --- ENTRY_DELETE --- - System.out.format("register %s for ENTRY_DELETE\n", dir); - WatchKey deleteKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_DELETE }); + Debug.printf("register %s for ENTRY_DELETE\n", dir); + WatchKey deleteKey = dir.register(watcher, ENTRY_DELETE); if (deleteKey != myKey) throw new RuntimeException("register did not return existing key"); checkKey(deleteKey, dir); - System.out.format("delete %s\n", file); + Debug.printf("delete %s\n", file); Files.delete(file); takeExpectedKey(watcher, myKey); - checkExpectedEvent(myKey.pollEvents(), - StandardWatchEventKinds.ENTRY_DELETE, name); + checkExpectedEvent(myKey.pollEvents(), ENTRY_DELETE, name); - System.out.println("reset key"); + Debug.println("reset key"); if (!myKey.reset()) throw new RuntimeException("key has been cancalled"); - System.out.println("OKAY"); + Debug.println("OKAY"); // create the file for the next test Files.createFile(file); // --- ENTRY_MODIFY --- - System.out.format("register %s for ENTRY_MODIFY\n", dir); - WatchKey newKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_MODIFY }); + Debug.printf("register %s for ENTRY_MODIFY\n", dir); + WatchKey newKey = dir.register(watcher, ENTRY_MODIFY); if (newKey != myKey) throw new RuntimeException("register did not return existing key"); checkKey(newKey, dir); - System.out.format("update: %s\n", file); + Debug.printf("update: %s\n", file); try (OutputStream out = Files.newOutputStream(file, StandardOpenOption.APPEND)) { - out.write("I am a small file".getBytes("UTF-8")); + out.write("I am a small file".getBytes(StandardCharsets.UTF_8)); } // remove key and check that we got the ENTRY_MODIFY event takeExpectedKey(watcher, myKey); - checkExpectedEvent(myKey.pollEvents(), - StandardWatchEventKinds.ENTRY_MODIFY, name); - System.out.println("OKAY"); + checkExpectedEvent(myKey.pollEvents(), ENTRY_MODIFY, name); + Debug.println("OKAY"); // done Files.delete(file); @@ -189,25 +177,24 @@ void testEvents() throws IOException { */ @Test void testCancel() throws IOException { - System.out.println("-- Cancel --"); + Debug.println("-- Cancel --"); try (WatchService watcher = fs.newWatchService()) { - System.out.format("register %s for events\n", dir); - WatchKey myKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE }); + Debug.printf("register %s for events\n", dir); + WatchKey myKey = dir.register(watcher, ENTRY_CREATE); checkKey(myKey, dir); - System.out.println("cancel key"); + Debug.println("cancel key"); myKey.cancel(); // create a file in the directory Path file = dir.resolve("mars"); - System.out.format("create: %s\n", file); + Debug.printf("create: %s\n", file); Files.createFile(file); // poll for keys - there will be none - System.out.println("poll..."); + Debug.println("poll..."); try { WatchKey key = watcher.poll(3000, TimeUnit.MILLISECONDS); if (key != null) @@ -219,7 +206,7 @@ void testCancel() throws IOException { // done Files.delete(file); - System.out.println("OKAY"); + Debug.println("OKAY"); } } @@ -229,28 +216,26 @@ void testCancel() throws IOException { */ @Test void testAutomaticCancel() throws IOException { - System.out.println("-- Automatic Cancel --"); + Debug.println("-- Automatic Cancel --"); Path subdir = Files.createDirectory(dir.resolve("bar")); try (WatchService watcher = fs.newWatchService()) { - System.out.format("register %s for events\n", subdir); - WatchKey myKey = subdir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY }); + Debug.printf("register %s for events\n", subdir); + WatchKey myKey = subdir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); - System.out.format("delete: %s\n", subdir); + Debug.printf("delete: %s\n", subdir); Files.delete(subdir); takeExpectedKey(watcher, myKey); - System.out.println("reset key"); + Debug.println("reset key"); if (myKey.reset()) throw new RuntimeException("Key was not cancelled"); if (myKey.isValid()) throw new RuntimeException("Key is still valid"); - System.out.println("OKAY"); - + Debug.println("OKAY"); } } @@ -259,19 +244,15 @@ void testAutomaticCancel() throws IOException { */ @Test void testWakeup() throws IOException { - System.out.println("-- Wakeup Tests --"); + Debug.println("-- Wakeup Tests --"); final WatchService watcher = fs.newWatchService(); - Runnable r = new Runnable() { - public void run() { - try { - Thread.sleep(5000); - System.out.println("close WatchService..."); - watcher.close(); - } catch (InterruptedException x) { - x.printStackTrace(); - } catch (IOException x) { - x.printStackTrace(); - } + Runnable r = () -> { + try { + Thread.sleep(5000); + Debug.println("close WatchService..."); + watcher.close(); + } catch (InterruptedException | IOException x) { + Debug.printStackTrace(x); } }; @@ -279,16 +260,16 @@ public void run() { new Thread(r).start(); try { - System.out.println("take..."); + Debug.println("take..."); watcher.take(); throw new RuntimeException("ClosedWatchServiceException not thrown"); } catch (InterruptedException x) { throw new RuntimeException(x); } catch (ClosedWatchServiceException x) { - System.out.println("ClosedWatchServiceException thrown"); + Debug.println("ClosedWatchServiceException thrown"); } - System.out.println("OKAY"); + Debug.println("OKAY"); } /** @@ -296,20 +277,21 @@ public void run() { */ @Test void testExceptions() throws IOException { - System.out.println("-- Exceptions and other simple tests --"); + Debug.println("-- Exceptions and other simple tests --"); WatchService watcher = fs.newWatchService(); - try { + + try (watcher) { // Poll tests WatchKey key; - System.out.println("poll..."); + Debug.println("poll..."); key = watcher.poll(); if (key != null) throw new RuntimeException("no keys registered"); - System.out.println("poll with timeout..."); + Debug.println("poll with timeout..."); try { long start = System.nanoTime(); key = watcher.poll(3000, TimeUnit.MILLISECONDS); @@ -323,105 +305,74 @@ void testExceptions() throws IOException { } // IllegalArgumentException - System.out.println("IllegalArgumentException tests..."); - try { - dir.register(watcher /*empty event list*/); - throw new RuntimeException("IllegalArgumentException not thrown"); - } catch (IllegalArgumentException x) { - } - try { - // OVERFLOW is ignored so this is equivalent to the empty set - dir.register(watcher, OVERFLOW); - throw new RuntimeException("IllegalArgumentException not thrown"); - } catch (IllegalArgumentException x) { - } - try { - // OVERFLOW is ignored even if specified multiple times - dir.register(watcher, OVERFLOW, OVERFLOW); - throw new RuntimeException("IllegalArgumentException not thrown"); - } catch (IllegalArgumentException x) { - } + Debug.println("IllegalArgumentException tests..."); + assertThrows(IllegalArgumentException.class, + () -> dir.register(watcher /*empty event list*/), + "IllegalArgumentException not thrown"); + assertThrows(IllegalArgumentException.class, + // OVERFLOW is ignored so this is equivalent to the empty set + () -> dir.register(watcher, OVERFLOW), + "IllegalArgumentException not thrown"); + assertThrows(IllegalArgumentException.class, + // OVERFLOW is ignored even if specified multiple times + () -> dir.register(watcher, OVERFLOW, OVERFLOW), + "IllegalArgumentException not thrown"); // UnsupportedOperationException - try { - dir.register(watcher, - new WatchEvent.Kind() { - @Override public String name() { return "custom"; } - @Override public Class type() { return Object.class; } - }); - throw new RuntimeException("UnsupportedOperationException not thrown"); - } catch (UnsupportedOperationException x) { - } - try { - dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE }, - new WatchEvent.Modifier() { - @Override public String name() { return "custom"; } - }); - throw new RuntimeException("UnsupportedOperationException not thrown"); - } catch (UnsupportedOperationException x) { - } + assertThrows(UnsupportedOperationException.class, + () -> dir.register(watcher, new WatchEvent.Kind<>() { + @Override public String name() { return "custom"; } + @Override public Class type() { return Object.class; } + }), + "UnsupportedOperationException not thrown"); + assertThrows(UnsupportedOperationException.class, + () -> dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }, () -> "custom"), + "UnsupportedOperationException not thrown"); // NullPointerException - System.out.println("NullPointerException tests..."); - try { - dir.register(null, ENTRY_CREATE); - throw new RuntimeException("NullPointerException not thrown"); - } catch (NullPointerException x) { - } - try { - dir.register(watcher, new WatchEvent.Kind[]{ null }); - throw new RuntimeException("NullPointerException not thrown"); - } catch (NullPointerException x) { - } - try { - dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }, - (WatchEvent.Modifier)null); - throw new RuntimeException("NullPointerException not thrown"); - } catch (NullPointerException x) { - } - } finally { - watcher.close(); + Debug.println("NullPointerException tests..."); + assertThrows(NullPointerException.class, + () -> dir.register(null, ENTRY_CREATE), + "NullPointerException not thrown"); + assertThrows(NullPointerException.class, + () -> dir.register(watcher, new WatchEvent.Kind[]{ null }), + "NullPointerException not thrown"); + assertThrows(NullPointerException.class, + () -> dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }, (WatchEvent.Modifier) null), + "NullPointerException not thrown"); } // -- ClosedWatchServiceException -- - System.out.println("ClosedWatchServiceException tests..."); + Debug.println("ClosedWatchServiceException tests..."); - try { - watcher.poll(); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (ClosedWatchServiceException x) { - } + assertThrows(ClosedWatchServiceException.class, watcher::poll, + "ClosedWatchServiceException not thrown"); // assume that poll throws exception immediately long start = System.nanoTime(); - try { - watcher.poll(10000, TimeUnit.MILLISECONDS); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (InterruptedException x) { - throw new RuntimeException(x); - } catch (ClosedWatchServiceException x) { - long waited = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); - if (waited > 5000) - throw new RuntimeException("poll was too long"); - } + assertThrows(ClosedWatchServiceException.class, () -> { + try { + watcher.poll(10000, TimeUnit.MILLISECONDS); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + }, "ClosedWatchServiceException not thrown"); + long waited = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); + if (waited > 5000) + throw new RuntimeException("poll was too long"); - try { - watcher.take(); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (InterruptedException x) { - throw new RuntimeException(x); - } catch (ClosedWatchServiceException x) { - } + assertThrows(ClosedWatchServiceException.class, () -> { + try { + watcher.take(); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + }, "ClosedWatchServiceException not thrown"); - try { - dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (ClosedWatchServiceException x) { - } + assertThrows(ClosedWatchServiceException.class, () -> dir.register(watcher, ENTRY_CREATE), "ClosedWatchServiceException not thrown"); - System.out.println("OKAY"); + Debug.println("OKAY"); } /** @@ -430,38 +381,35 @@ void testExceptions() throws IOException { */ @Test void testTwoWatchers() throws IOException { - System.out.println("-- Two watchers test --"); + Debug.println("-- Two watchers test --"); + + try (WatchService watcher1 = fs.newWatchService(); + WatchService watcher2 = fs.newWatchService()) { - WatchService watcher1 = fs.newWatchService(); - WatchService watcher2 = fs.newWatchService(); - try { Path name1 = fs.getPath("gus1"); Path name2 = fs.getPath("gus2"); // create gus1 Path file1 = dir.resolve(name1); - System.out.format("create %s\n", file1); + Debug.printf("create %s\n", file1); Files.createFile(file1); // register with both watch services (different events) - System.out.println("register for different events"); - WatchKey key1 = dir.register(watcher1, - new WatchEvent.Kind[]{ ENTRY_CREATE }); - WatchKey key2 = dir.register(watcher2, - new WatchEvent.Kind[]{ ENTRY_DELETE }); + Debug.println("register for different events"); + WatchKey key1 = dir.register(watcher1, ENTRY_CREATE); + WatchKey key2 = dir.register(watcher2, ENTRY_DELETE); if (key1 == key2) throw new RuntimeException("keys should be different"); // create gus2 Path file2 = dir.resolve(name2); - System.out.format("create %s\n", file2); + Debug.printf("create %s\n", file2); Files.createFile(file2); // check that key1 got ENTRY_CREATE takeExpectedKey(watcher1, key1); - checkExpectedEvent(key1.pollEvents(), - StandardWatchEventKinds.ENTRY_CREATE, name2); + checkExpectedEvent(key1.pollEvents(), ENTRY_CREATE, name2); // check that key2 got zero events WatchKey key = watcher2.poll(); @@ -473,8 +421,7 @@ void testTwoWatchers() throws IOException { // check that key2 got ENTRY_DELETE takeExpectedKey(watcher2, key2); - checkExpectedEvent(key2.pollEvents(), - StandardWatchEventKinds.ENTRY_DELETE, name1); + checkExpectedEvent(key2.pollEvents(), ENTRY_DELETE, name1); // check that key1 got zero events key = watcher1.poll(); @@ -487,21 +434,16 @@ void testTwoWatchers() throws IOException { // change registration with watcher2 so that they are both // registered for the same event - System.out.println("register for same event"); - key2 = dir.register(watcher2, new WatchEvent.Kind[]{ ENTRY_CREATE }); + Debug.println("register for same event"); + key2 = dir.register(watcher2, ENTRY_CREATE); // create file and key2 should be queued - System.out.format("create %s\n", file1); + Debug.printf("create %s\n", file1); Files.createFile(file1); takeExpectedKey(watcher2, key2); - checkExpectedEvent(key2.pollEvents(), - StandardWatchEventKinds.ENTRY_CREATE, name1); - - System.out.println("OKAY"); + checkExpectedEvent(key2.pollEvents(), ENTRY_CREATE, name1); - } finally { - watcher2.close(); - watcher1.close(); + Debug.println("OKAY"); } } @@ -511,17 +453,17 @@ void testTwoWatchers() throws IOException { */ @Test void testThreadInterrupt() throws IOException { - System.out.println("-- Thread interrupted status test --"); + Debug.println("-- Thread interrupted status test --"); Thread curr = Thread.currentThread(); try (WatchService watcher = fs.newWatchService()) { - System.out.println("interrupting current thread"); + Debug.println("interrupting current thread"); curr.interrupt(); dir.register(watcher, ENTRY_CREATE); if (!curr.isInterrupted()) throw new RuntimeException("thread should remain interrupted"); - System.out.println("current thread is still interrupted"); - System.out.println("OKAY"); + Debug.println("current thread is still interrupted"); + Debug.println("OKAY"); } finally { Thread.interrupted(); } @@ -534,7 +476,7 @@ static void before() throws IOException { String email = System.getenv("GOOGLE_TEST_ACCOUNT"); URI uri = URI.create("googledrive:///?id=" + email); - fs = new GoogleDriveFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); + fs = new GoogleDriveFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); dir = Files.createTempDirectory(fs.getRootDirectories().iterator().next(), "VAVIFUSE-TEST-WATCHSERVICE"); } diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java index aae32272..09c6f39e 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java @@ -140,7 +140,7 @@ public boolean promptYesNo(String str) { @Override public FileSystemOptions authorize(VfsCredential credential) throws IOException { - SftpVfsCredential c = SftpVfsCredential.class.cast(credential); + SftpVfsCredential c = (SftpVfsCredential) credential; boolean pkc = c.passphrase != null; FileSystemOptions options = new FileSystemOptions(); diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java index b6fd93be..03f5cd9a 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java @@ -106,7 +106,7 @@ public VfsCredential getCredential(String alias, URI uri) { @Override public FileSystemOptions authorize(VfsCredential credential) throws IOException { - SmbVfsCredential c = SmbVfsCredential.class.cast(credential); + SmbVfsCredential c = (SmbVfsCredential) credential; FileSystemOptions options = new FileSystemOptions(); StaticUserAuthenticator auth = new StaticUserAuthenticator(c.domain, c.username, c.password); diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java index 4bc44f17..63551590 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java @@ -27,13 +27,12 @@ public interface VfsAuthenticator extends Authenticator new SmbVfsAuthenticator(); + case "sftp" -> new SftpVfsAuthenticator(); + case "webdav4s" -> new WebdavVfsAuthenticator(); + default -> throw new IllegalArgumentException(scheme); + }; } } diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java index c000f766..1285fc35 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import vavi.net.auth.AppCredential; import vavi.net.auth.UserCredential; @@ -113,31 +114,27 @@ public int getPort() { /** */ public String buildBaseUrl() { - try { - StringBuilder sb = new StringBuilder(); - sb.append(getClientId()); - sb.append("://"); - if (username != null) { - sb.append(URLEncoder.encode(username, "utf-8")); - } - if (password != null) { - sb.append(":"); - sb.append(password); - } - if (host != null) { - if (username != null || password != null) { - sb.append("@"); - } - sb.append(host); - } - if (port != -1) { - sb.append(":"); - sb.append(port); + StringBuilder sb = new StringBuilder(); + sb.append(getClientId()); + sb.append("://"); + if (username != null) { + sb.append(URLEncoder.encode(username, StandardCharsets.UTF_8)); + } + if (password != null) { + sb.append(":"); + sb.append(password); + } + if (host != null) { + if (username != null || password != null) { + sb.append("@"); } - return sb.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); + sb.append(host); + } + if (port != -1) { + sb.append(":"); + sb.append(port); } + return sb.toString(); } } diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java index f16f1207..5cbe383f 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java @@ -8,6 +8,7 @@ import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.LocalDateTime; import java.util.Collections; @@ -76,10 +77,10 @@ public class Main { @EnabledIfEnvironmentVariable(named = "TEST_SFTP_PATH", matches = ".+"), }) void test01() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), "utf-8"); - String passPhrase = URLEncoder.encode(System.getenv("TEST_SFTP_PASSPHRASE"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), StandardCharsets.UTF_8); + String passPhrase = URLEncoder.encode(System.getenv("TEST_SFTP_PASSPHRASE"), StandardCharsets.UTF_8); String host = System.getenv("TEST_SFTP_HOST"); - String keyPath = URLEncoder.encode(System.getenv("TEST_SFTP_KEYPATH"), "utf-8"); + String keyPath = URLEncoder.encode(System.getenv("TEST_SFTP_KEYPATH"), StandardCharsets.UTF_8); String path = System.getenv("TEST_SFTP_PATH"); URI uri = URI.create(String.format("vfs:sftp://%s@%s%s?keyPath=%s&passphrase=%s", username, host, path, keyPath, passPhrase)); @@ -110,7 +111,7 @@ void test01() throws Exception { @EnabledIfEnvironmentVariable(named = "TEST_WEBDAV_PATH", matches = ".+"), }) void test02() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_WEBDAV_ACCOUNT"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_WEBDAV_ACCOUNT"), StandardCharsets.UTF_8); String password = System.getenv("TEST_WEBDAV_PASSWORD"); String host = System.getenv("TEST_WEBDAV_HOST"); String port = System.getenv("TEST_WEBDAV_PORT"); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java index 0ae6b02e..79f32202 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java @@ -8,6 +8,7 @@ import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.util.Collections; @@ -36,7 +37,7 @@ public class Main2 { */ @Test void test01() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), StandardCharsets.UTF_8); String passPhrase = System.getenv("TEST_SFTP_PASSPHRASE"); String host = System.getenv("TEST_SFTP_HOST"); String keyPath = System.getenv("TEST_SFTP_KEYPATH"); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java index 63840ba5..d25bfa1d 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java @@ -8,6 +8,7 @@ import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.util.Collections; @@ -36,7 +37,7 @@ public class Main3 { */ @Test void test01() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), StandardCharsets.UTF_8); String passPhrase = System.getenv("TEST_SFTP_PASSPHRASE"); String host = System.getenv("TEST_SFTP_HOST"); String keyPath = System.getenv("TEST_SFTP_KEYPATH"); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java index a6d1f725..8fe50b45 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.util.HashMap; @@ -47,10 +48,10 @@ public class Main4 { @BeforeEach public void before() throws Exception { mountPoint = System.getenv("TEST4_MOUNT_POINT"); - String username = URLEncoder.encode(System.getenv("TEST4_SFTP_ACCOUNT"), "utf-8"); - String passPhrase = URLEncoder.encode(System.getenv("TEST4_SFTP_PASSPHRASE"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST4_SFTP_ACCOUNT"), StandardCharsets.UTF_8); + String passPhrase = URLEncoder.encode(System.getenv("TEST4_SFTP_PASSPHRASE"), StandardCharsets.UTF_8); String host = System.getenv("TEST4_SFTP_HOST"); - String keyPath = URLEncoder.encode(System.getenv("TEST4_SFTP_KEYPATH"), "utf-8"); + String keyPath = URLEncoder.encode(System.getenv("TEST4_SFTP_KEYPATH"), StandardCharsets.UTF_8); String path = System.getenv("TEST4_SFTP_PATH"); URI uri = URI.create(String.format("vfs:sftp://%s@%s%s?keyPath=%s&passphrase=%s", username, host, path, keyPath, passPhrase)); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java index 76cce34f..7c30ca61 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; @@ -61,7 +62,7 @@ void proceed() throws IOException { FileSystemManager fs = VFS.getManager(); if (!fs.hasProvider("webdav")) throw new RuntimeException("Provider missing: webdav"); - String baseUrl = String.format(this.baseUrl, username, password, host, port, URLEncoder.encode(component, "utf-8")); + String baseUrl = String.format(this.baseUrl, username, password, host, port, URLEncoder.encode(component, StandardCharsets.UTF_8)); System.err.println("Connecting \"" + baseUrl + "\" with " + options); FileObject davFile = fs.resolveFile(baseUrl, options); // added opts! //System.err.println(smbFile.exists() + " " + smbFile.getContent().getLastModifiedTime());