diff --git a/src/main/java/org/gaul/s3proxy/Main.java b/src/main/java/org/gaul/s3proxy/Main.java index 078d0461..ab14fe7a 100644 --- a/src/main/java/org/gaul/s3proxy/Main.java +++ b/src/main/java/org/gaul/s3proxy/Main.java @@ -17,13 +17,12 @@ package org.gaul.s3proxy; import java.io.Console; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.PathMatcher; import java.util.ArrayList; import java.util.HashSet; @@ -39,7 +38,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; -import com.google.common.io.Files; +import com.google.common.io.MoreFiles; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.jclouds.Constants; @@ -68,7 +67,7 @@ private Main() { private static final class Options { @Option(name = "--properties", usage = "S3Proxy configuration (required, multiple allowed)") - private List propertiesFiles = new ArrayList<>(); + private List properties = new ArrayList<>(); @Option(name = "--version", usage = "display version") private boolean version; @@ -93,7 +92,7 @@ public static void main(String[] args) throws Exception { System.err.println( Main.class.getPackage().getImplementationVersion()); System.exit(0); - } else if (options.propertiesFiles.isEmpty()) { + } else if (options.properties.isEmpty()) { usage(parser); } @@ -110,9 +109,9 @@ public static void main(String[] args) throws Exception { .>builder(); Set locatorGlobs = new HashSet<>(); Set parsedIdentities = new HashSet<>(); - for (File propertiesFile : options.propertiesFiles) { + for (var path : options.properties) { var properties = new Properties(); - try (InputStream is = new FileInputStream(propertiesFile)) { + try (var is = Files.newInputStream(path)) { properties.load(is); } properties.putAll(System.getProperties()); @@ -350,9 +349,9 @@ private static BlobStore createBlobStore(Properties properties, identity = Strings.nullToEmpty(identity); credential = Strings.nullToEmpty(credential); } else if (provider.equals("google-cloud-storage")) { - var credentialFile = new File(credential); - if (credentialFile.exists()) { - credential = Files.asCharSource(credentialFile, + var path = FileSystems.getDefault().getPath(credential); + if (Files.exists(path)) { + credential = MoreFiles.asCharSource(path, StandardCharsets.UTF_8).read(); } properties.remove(Constants.PROPERTY_CREDENTIAL); diff --git a/src/test/java/org/gaul/s3proxy/TestUtils.java b/src/test/java/org/gaul/s3proxy/TestUtils.java index a92b292c..edd399c5 100644 --- a/src/test/java/org/gaul/s3proxy/TestUtils.java +++ b/src/test/java/org/gaul/s3proxy/TestUtils.java @@ -16,11 +16,12 @@ package org.gaul.s3proxy; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; +import java.nio.file.Files; import java.util.List; import java.util.Properties; import java.util.Random; @@ -29,7 +30,7 @@ import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; import com.google.common.io.ByteSource; -import com.google.common.io.Files; +import com.google.common.io.MoreFiles; import com.google.common.io.Resources; import org.eclipse.jetty.util.component.AbstractLifeCycle; @@ -165,9 +166,9 @@ static S3ProxyLaunchInfo startS3Proxy(String configFile) throws Exception { String credential = info.getProperties().getProperty( Constants.PROPERTY_CREDENTIAL); if (provider.equals("google-cloud-storage")) { - var credentialFile = new File(credential); - if (credentialFile.exists()) { - credential = Files.asCharSource(credentialFile, + var path = FileSystems.getDefault().getPath(credential); + if (Files.exists(path)) { + credential = MoreFiles.asCharSource(path, StandardCharsets.UTF_8).read(); } info.getProperties().remove(Constants.PROPERTY_CREDENTIAL);