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

Commit eaef1b9

Browse files
committed
fixed issue #49
1 parent 02e8cbf commit eaef1b9

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

pom.xml

Lines changed: 1 addition & 6 deletions
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.1.2</version>
7+
<version>1.2.0</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>
@@ -71,11 +71,6 @@
7171
<artifactId>guava</artifactId>
7272
<version>18.0</version>
7373
</dependency>
74-
<dependency>
75-
<groupId>org.unbescape</groupId>
76-
<artifactId>unbescape</artifactId>
77-
<version>1.1.0.RELEASE</version>
78-
</dependency>
7974
<dependency>
8075
<groupId>org.apache.tika</groupId>
8176
<artifactId>tika-core</artifactId>

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.nio.file.PathMatcher;
1010
import java.nio.file.WatchService;
1111
import java.nio.file.attribute.UserPrincipalLookupService;
12-
import java.nio.file.spi.FileSystemProvider;
1312
import java.util.List;
1413
import java.util.Set;
1514

@@ -18,7 +17,6 @@
1817
import com.google.common.base.Joiner;
1918
import com.google.common.collect.ImmutableList;
2019
import com.google.common.collect.ImmutableSet;
21-
import org.unbescape.uri.UriEscape;
2220

2321
/**
2422
* S3FileSystem with a concrete client configured and ready to use.
@@ -135,19 +133,15 @@ public String[] key2Parts(String keyParts) {
135133
String[] split = new String[parts.length];
136134
int i=0;
137135
for (String part : parts) {
138-
split[i++] = UriEscape.unescapeUriPathSegment(part);
136+
split[i++] = part;
139137
}
140138
return split;
141139
}
142140

143141
public String parts2Key(List<String> parts) {
144142
if (parts.isEmpty())
145143
return "";
146-
ImmutableList.Builder<String> builder = ImmutableList.builder();
147-
for (String part : parts) {
148-
builder.add(UriEscape.escapeUriPathSegment(part));
149-
}
150-
return Joiner.on(PATH_SEPARATOR).join(builder.build());
144+
return Joiner.on(PATH_SEPARATOR).join(ImmutableList.copyOf(parts));
151145
}
152146

153147
@Override

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.net.URI;
27-
import java.net.URISyntaxException;
2827
import java.nio.channels.SeekableByteChannel;
2928
import java.nio.file.*;
3029
import java.nio.file.attribute.BasicFileAttributes;

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,15 @@
77

88
import java.io.File;
99
import java.io.IOException;
10-
import java.io.InputStream;
1110
import java.net.URI;
12-
import java.nio.channels.SeekableByteChannel;
13-
import java.nio.file.AccessDeniedException;
14-
import java.nio.file.AccessMode;
15-
import java.nio.file.CopyOption;
16-
import java.nio.file.DirectoryNotEmptyException;
17-
import java.nio.file.FileAlreadyExistsException;
18-
import java.nio.file.FileVisitor;
19-
import java.nio.file.Files;
2011
import java.nio.file.LinkOption;
21-
import java.nio.file.NoSuchFileException;
22-
import java.nio.file.OpenOption;
2312
import java.nio.file.Path;
2413
import java.nio.file.WatchEvent;
2514
import java.nio.file.WatchKey;
2615
import java.nio.file.WatchService;
27-
import java.nio.file.attribute.BasicFileAttributes;
28-
import java.nio.file.attribute.FileAttribute;
2916
import java.util.Arrays;
3017
import java.util.Iterator;
3118
import java.util.List;
32-
import java.util.Set;
3319

3420
import javax.annotation.Nullable;
3521

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.EnumSet;
2222
import java.util.UUID;
2323

24+
import com.amazonaws.services.s3.AmazonS3;
25+
import com.amazonaws.services.s3.AmazonS3Client;
2426
import org.junit.Before;
2527

2628
import com.amazonaws.services.s3.model.ObjectMetadata;

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Set;
2121

22+
import com.amazonaws.services.s3.AmazonS3Client;
2223
import com.google.common.collect.ImmutableMap;
2324
import org.junit.Before;
2425
import org.junit.Test;
@@ -276,7 +277,7 @@ public void parts2Key() {
276277
S3FileSystem s3fs = new S3FileSystem(provider, null, amazonClientMock, "mirror1.amazon.test");
277278
S3Path path = s3fs.getPath("/bucket", "folder with spaces", "file");
278279
try {
279-
assertEquals("folder%20with%20spaces/file", path.getKey());
280+
assertEquals("folder with spaces/file", path.getKey());
280281
} finally {
281282
try {
282283
s3fs.close();
@@ -285,6 +286,34 @@ public void parts2Key() {
285286
}
286287
}
287288
}
289+
290+
@Test
291+
public void urlWithSpecialCharacters() throws IOException {
292+
String fileName = "βeta.png";
293+
String expected = "https://bucket.s3.amazonaws.com/%CE%B2eta.png";
294+
295+
AmazonS3Client amazonS3Client = new AmazonS3Client();
296+
S3FileSystem s3FileSystem = new S3FileSystem(null, null, amazonS3Client, "mirror");
297+
S3Path path = new S3Path(s3FileSystem, fileName);
298+
299+
String url = amazonS3Client.getResourceUrl("bucket", path.getKey());
300+
301+
assertEquals(expected, url);
302+
}
303+
304+
@Test
305+
public void urlWithSpaceCharacters() throws IOException {
306+
String fileName = "beta gaming.png";
307+
String expected = "https://bucket.s3.amazonaws.com/beta%20gaming.png";
308+
309+
AmazonS3Client amazonS3Client = new AmazonS3Client();
310+
S3FileSystem s3FileSystem = new S3FileSystem(null, null, amazonS3Client, "mirror");
311+
S3Path path = new S3Path(s3FileSystem, fileName);
312+
313+
String url = amazonS3Client.getResourceUrl("bucket", path.getKey());
314+
315+
assertEquals(expected, url);
316+
}
288317

289318
@Test
290319
public void createDirectory() throws IOException {

0 commit comments

Comments
 (0)