Skip to content

Commit

Permalink
Prefer Path over File
Browse files Browse the repository at this point in the history
Found via modernizer-maven-plugin 3.0.0.
  • Loading branch information
gaul committed Dec 28, 2024
1 parent c2ec948 commit 26dd4a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/main/java/org/gaul/s3proxy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -68,7 +67,7 @@ private Main() {
private static final class Options {
@Option(name = "--properties",
usage = "S3Proxy configuration (required, multiple allowed)")
private List<File> propertiesFiles = new ArrayList<>();
private List<Path> properties = new ArrayList<>();

@Option(name = "--version", usage = "display version")
private boolean version;
Expand All @@ -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);
}

Expand All @@ -110,9 +109,9 @@ public static void main(String[] args) throws Exception {
.<PathMatcher, Map.Entry<String, BlobStore>>builder();
Set<String> locatorGlobs = new HashSet<>();
Set<String> 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());
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/gaul/s3proxy/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 26dd4a4

Please sign in to comment.