88import java .util .Objects ;
99
1010final class S3FileSystemFactory {
11+
12+ private static final String AWS_REGION_KEY = "aws.region" ;
13+ public static final String DEFAULT_AWS_REGION = "us-east-1" ;
14+
1115 public record S3Fs (FileSystem fileSystem , URI uri ) {}
1216
1317 private static S3FileSystemProvider PROVIDER ;
@@ -23,21 +27,19 @@ public static S3Fs build(S3Configuration cfg) {
2327 final boolean thirdParty = cfg .getEndpointUrl () != null && !cfg .getEndpointUrl ().isBlank ();
2428 try {
2529 final URI uri ;
26- if (!thirdParty ) {
27- // AWS S3 – the provider uses the default region/credentials chain
28- PROVIDER = new S3FileSystemProvider ();
29- System .setProperty ("aws.region" , cfg .getRegion () != null ? cfg .getRegion () : "us-east-1" );
30- uri = URI .create ("s3://" + cfg .getBucketName ());
31- } else {
30+ if (thirdParty ) {
3231 PROVIDER = new S3XFileSystemProvider ();
3332 var url = URI .create (cfg .getEndpointUrl ());
3433 System .setProperty ("s3.spi.endpoint-protocol" , url .toString ().startsWith ("https" ) ? "https" : "http" );
35- System .setProperty ("aws.region" , cfg .getRegion () != null ? cfg .getRegion () : "us-east-1" );
34+ System .setProperty (AWS_REGION_KEY , cfg .getRegion () != null ? cfg .getRegion () : DEFAULT_AWS_REGION );
3635 String userInfo = buildUserInfo (cfg );
3736 uri = new URI ("s3x" , userInfo , url .getHost (), url .getPort (), "/" + cfg .getBucketName (), null , null );
37+ } else {
38+ // AWS S3 – the provider uses the default region/credentials chain
39+ PROVIDER = new S3FileSystemProvider ();
40+ System .setProperty (AWS_REGION_KEY , cfg .getRegion () != null ? cfg .getRegion () : DEFAULT_AWS_REGION );
41+ uri = URI .create ("s3://" + cfg .getBucketName ());
3842 }
39- System .out .println ("Using S3 FileSystem Provider: " + PROVIDER .getClass ().getName ());
40- System .out .println ("Using S3 URI: " + uri );
4143 FileSystem fs = PROVIDER .getFileSystem (uri );
4244 return new S3Fs (fs , uri );
4345 } catch (Exception e ) {
0 commit comments