Skip to content

Commit

Permalink
fix for issue awslabs#237
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanofornari committed Nov 7, 2023
1 parent 59e08ad commit aec6203
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/software/amazon/nio/spi/s3/S3Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ public URI toUri() {
Iterator<Path> elements = path.iterator();

StringBuilder uri = new StringBuilder(fileSystem.provider().getScheme() + "://");
String endpoint = fileSystem.configuration().getEndpoint();
if (!endpoint.isEmpty()) {
uri.append(fileSystem.configuration().getEndpoint()).append(PATH_SEPARATOR);
}
uri.append(bucketName());
elements.forEachRemaining(
(e) -> {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/software/amazon/nio/spi/s3/S3PathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,13 @@ public void stripCredentialsAndEndpointNIO() {
then(Paths.get(URI.create("s3x://key:[email protected]:1010/bucket/afile.txt")).toString()).isEqualTo("/afile.txt");
}

@Test
public void toUriProvidesFullUri() {
URI uri = URI.create("s3://bucket/subfolder/afile.txt");
then(Paths.get(uri).toUri()).isEqualTo(uri);

uri = URI.create("s3x://somewhere.com:1010/bucket/subfolder/afile.txt");
then(Paths.get(uri).toUri()).isEqualTo(uri);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.BDDAssertions.then;
import org.junit.jupiter.api.Test;
import software.amazon.nio.spi.s3.util.S3XFileSystemInfo;

/**
*
Expand Down

0 comments on commit aec6203

Please sign in to comment.