Skip to content

Commit

Permalink
fixed issue #49
Browse files Browse the repository at this point in the history
  • Loading branch information
jarnaiz committed Nov 21, 2015
1 parent 02e8cbf commit eaef1b9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.upplication</groupId>
<artifactId>s3fs</artifactId>
<packaging>jar</packaging>
<version>1.1.2</version>
<version>1.2.0</version>
<name>s3fs</name>
<description>S3 filesystem provider for Java 7</description>
<url>https://github.com/Upplication/Amazon-S3-FileSystem-NIO2</url>
Expand Down Expand Up @@ -71,11 +71,6 @@
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/upplication/s3fs/S3FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.nio.file.PathMatcher;
import java.nio.file.WatchService;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.spi.FileSystemProvider;
import java.util.List;
import java.util.Set;

Expand All @@ -18,7 +17,6 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.unbescape.uri.UriEscape;

/**
* S3FileSystem with a concrete client configured and ready to use.
Expand Down Expand Up @@ -135,19 +133,15 @@ public String[] key2Parts(String keyParts) {
String[] split = new String[parts.length];
int i=0;
for (String part : parts) {
split[i++] = UriEscape.unescapeUriPathSegment(part);
split[i++] = part;
}
return split;
}

public String parts2Key(List<String> parts) {
if (parts.isEmpty())
return "";
ImmutableList.Builder<String> builder = ImmutableList.builder();
for (String part : parts) {
builder.add(UriEscape.escapeUriPathSegment(part));
}
return Joiner.on(PATH_SEPARATOR).join(builder.build());
return Joiner.on(PATH_SEPARATOR).join(ImmutableList.copyOf(parts));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/upplication/s3fs/S3Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,15 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.AccessDeniedException;
import java.nio.file.AccessMode;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.annotation.Nullable;

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/upplication/s3fs/FilesOperationsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.EnumSet;
import java.util.UUID;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import org.junit.Before;

import com.amazonaws.services.s3.model.ObjectMetadata;
Expand Down
31 changes: 30 additions & 1 deletion src/test/java/com/upplication/s3fs/S3FileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;

import com.amazonaws.services.s3.AmazonS3Client;
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -276,7 +277,7 @@ public void parts2Key() {
S3FileSystem s3fs = new S3FileSystem(provider, null, amazonClientMock, "mirror1.amazon.test");
S3Path path = s3fs.getPath("/bucket", "folder with spaces", "file");
try {
assertEquals("folder%20with%20spaces/file", path.getKey());
assertEquals("folder with spaces/file", path.getKey());
} finally {
try {
s3fs.close();
Expand All @@ -285,6 +286,34 @@ public void parts2Key() {
}
}
}

@Test
public void urlWithSpecialCharacters() throws IOException {
String fileName = "βeta.png";
String expected = "https://bucket.s3.amazonaws.com/%CE%B2eta.png";

AmazonS3Client amazonS3Client = new AmazonS3Client();
S3FileSystem s3FileSystem = new S3FileSystem(null, null, amazonS3Client, "mirror");
S3Path path = new S3Path(s3FileSystem, fileName);

String url = amazonS3Client.getResourceUrl("bucket", path.getKey());

assertEquals(expected, url);
}

@Test
public void urlWithSpaceCharacters() throws IOException {
String fileName = "beta gaming.png";
String expected = "https://bucket.s3.amazonaws.com/beta%20gaming.png";

AmazonS3Client amazonS3Client = new AmazonS3Client();
S3FileSystem s3FileSystem = new S3FileSystem(null, null, amazonS3Client, "mirror");
S3Path path = new S3Path(s3FileSystem, fileName);

String url = amazonS3Client.getResourceUrl("bucket", path.getKey());

assertEquals(expected, url);
}

@Test
public void createDirectory() throws IOException {
Expand Down

0 comments on commit eaef1b9

Please sign in to comment.