Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 927f24a

Browse files
committed
Merge branch 'hotfix/1.0.2' into develop
2 parents 6bcae5d + e86b529 commit 927f24a

File tree

6 files changed

+43
-20
lines changed

6 files changed

+43
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This project provides a first API implementation, little optimized, but "complet
1414
<dependency>
1515
<groupId>com.upplication</groupId>
1616
<artifactId>s3fs</artifactId>
17-
<version>1.0.1</version>
17+
<version>1.0.2</version>
1818
</dependency>
1919
```
2020

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.upplication</groupId>
55
<artifactId>s3fs</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0.1</version>
7+
<version>1.0.2</version>
88
<name>s3fs</name>
99
<description>S3 filesystem provider for Java 7</description>
1010
<url>https://github.com/Upplication/Amazon-S3-FileSystem-NIO2</url>

src/main/java/com/upplication/s3fs/S3FileSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public S3FileSystem(S3FileSystemProvider provider, String key, AmazonS3 client,
3939
}
4040

4141
@Override
42-
public FileSystemProvider provider() {
42+
public S3FileSystemProvider provider() {
4343
return provider;
4444
}
4545

src/main/java/com/upplication/s3fs/S3Path.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) thr
379379
public Iterator<Path> iterator() {
380380
ImmutableList.Builder<Path> builder = ImmutableList.builder();
381381

382-
for (Iterator<String> iterator = parts.iterator(); iterator.hasNext();) {
383-
String part = iterator.next();
382+
for (String part : parts) {
384383
builder.add(new S3Path(fileSystem, null, ImmutableList.of(part)));
385384
}
386385

src/main/java/com/upplication/s3fs/S3SeekableByteChannel.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
import java.nio.file.Files;
1212
import java.nio.file.OpenOption;
1313
import java.nio.file.Path;
14+
import java.nio.file.StandardCopyOption;
1415
import java.nio.file.StandardOpenOption;
16+
import java.util.Collections;
1517
import java.util.HashSet;
1618
import java.util.Set;
1719

1820
import org.apache.tika.Tika;
1921

2022
import com.amazonaws.services.s3.model.ObjectMetadata;
2123
import com.amazonaws.services.s3.model.S3Object;
22-
import com.upplication.s3fs.util.IOUtils;
2324

2425
public class S3SeekableByteChannel implements SeekableByteChannel {
2526

@@ -30,25 +31,33 @@ public class S3SeekableByteChannel implements SeekableByteChannel {
3031

3132
public S3SeekableByteChannel(S3Path path, Set<? extends OpenOption> options) throws IOException {
3233
this.path = path;
33-
this.options = options;
34+
this.options = Collections.unmodifiableSet(new HashSet<>(options));
3435
String key = path.getKey();
35-
tempFile = Files.createTempFile("temp-s3-", key.replaceAll("/", "_"));
36-
boolean existed = ((S3FileSystemProvider)path.getFileSystem().provider()).exists(path);
36+
boolean existed = path.getFileSystem().provider().exists(path);
3737

38-
if (existed && options.contains(StandardOpenOption.CREATE_NEW))
38+
if (existed && this.options.contains(StandardOpenOption.CREATE_NEW))
3939
throw new FileAlreadyExistsException(format("target already exists: %s", path));
4040

41-
if(existed) {
42-
S3Object object = path.getFileSystem()
43-
.getClient()
44-
.getObject(path.getFileStore().getBucket().getName(), key);
45-
InputStream is = object.getObjectContent();
46-
Files.write(tempFile, IOUtils.toByteArray(is), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
47-
}
48-
49-
options.remove(StandardOpenOption.CREATE_NEW);
41+
tempFile = Files.createTempFile("temp-s3-", key.replaceAll("/", "_"));
42+
boolean removeTempFile = true;
43+
try {
44+
if (existed) {
45+
try (S3Object object = path.getFileSystem()
46+
.getClient()
47+
.getObject(path.getFileStore().getBucket().getName(), key)) {
48+
Files.copy(object.getObjectContent(), tempFile, StandardCopyOption.REPLACE_EXISTING);
49+
}
50+
}
5051

51-
seekable = Files.newByteChannel(tempFile, options);
52+
Set<? extends OpenOption> seekOptions = new HashSet<>(this.options);
53+
seekOptions.remove(StandardOpenOption.CREATE_NEW);
54+
seekable = Files.newByteChannel(tempFile, seekOptions);
55+
removeTempFile = false;
56+
} finally {
57+
if (removeTempFile) {
58+
Files.deleteIfExists(tempFile);
59+
}
60+
}
5261
}
5362

5463
@Override

src/test/java/com/upplication/s3fs/S3FileSystemProviderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ public void createsAnonymous() {
129129
verify(s3fsProvider).createFileSystem(eq(uri), eq(buildFakeProps(null, null)));
130130
}
131131

132+
@Test
133+
public void createWithDefaultEndpoint() {
134+
Properties props = new Properties();
135+
props.setProperty(SECRET_KEY, "better secret key");
136+
props.setProperty(ACCESS_KEY, "better access key");
137+
props.setProperty(CHARSET_KEY, "UTF-8");
138+
doReturn(props).when(s3fsProvider).loadAmazonProperties();
139+
URI uri = URI.create("s3:///");
140+
141+
FileSystem fileSystem = s3fsProvider.newFileSystem(uri, ImmutableMap.<String, Object> of());
142+
assertNotNull(fileSystem);
143+
144+
verify(s3fsProvider).createFileSystem(eq(uri), eq(buildFakeProps("better access key", "better secret key", "UTF-8")));
145+
}
146+
132147
@Test(expected = IllegalArgumentException.class)
133148
public void createWithOnlyAccessKey() {
134149
Properties props = new Properties();

0 commit comments

Comments
 (0)