LUCENE-6430: fix URI delegation for non-ascii files

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1674177 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-04-17 01:04:56 +00:00
parent 4e73212034
commit 3dd6b59650
2 changed files with 17 additions and 11 deletions

View File

@ -357,4 +357,20 @@ public class TestMockFilesystems extends LuceneTestCase {
assertEquals(f1.hashCode(), f1Again.hashCode());
assertFalse(f1.equals(f2));
}
public void testURI() throws IOException {
Path dir = FilterPath.unwrap(createTempDir());
FileSystem fs = new FilterFileSystemProvider("test://", dir.getFileSystem()).getFileSystem(URI.create("file:///"));
Path wrapped = new FilterPath(dir, fs);
Path f1 = wrapped.resolve("file1");
URI uri = f1.toUri();
Path f2 = fs.provider().getPath(uri);
assertEquals(f1, f2);
Path f3 = wrapped.resolve("中国");
URI uri2 = f3.toUri();
Path f4 = fs.provider().getPath(uri2);
assertEquals(f3, f4);
}
}

View File

@ -17,12 +17,10 @@ package org.apache.lucene.mockfile;
* limitations under the License.
*/
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
@ -126,7 +124,7 @@ public class FilterFileSystemProvider extends FileSystemProvider {
if (fileSystem == null) {
throw new IllegalStateException("subclass did not initialize singleton filesystem");
}
Path path = delegate.getPath(toDelegate(uri));
Path path = delegate.getPath(uri);
return new FilterPath(path, fileSystem);
}
@ -258,14 +256,6 @@ public class FilterFileSystemProvider extends FileSystemProvider {
}
}
private URI toDelegate(URI uri) {
try {
return new URI(delegate.getScheme(), uri.getSchemeSpecificPart(), uri.getFragment());
} catch (URISyntaxException e) {
throw new IOError(e);
}
}
/**
* Override to trigger some behavior when the filesystem is closed.
* <p>