You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/04/20 22:25:53 UTC
[commons-vfs] branch master updated: FileSystemManager.createFileSystem(FileObject) fails on Gzip files. #92.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new f3b7a06f FileSystemManager.createFileSystem(FileObject) fails on Gzip files. #92.
f3b7a06f is described below
commit f3b7a06f28aab2db829806e0e857c05b71a14305
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Apr 20 18:25:47 2022 -0400
FileSystemManager.createFileSystem(FileObject) fails on Gzip files. #92.
---
.../org/apache/commons/vfs2/impl/FileTypeMap.java | 7 ++--
.../commons/vfs2/provider/gzip/GzipTest.java | 41 ++++++++++++++++++++++
src/changes/changes.xml | 3 ++
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileTypeMap.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileTypeMap.java
index 29c41db8..82e300ff 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileTypeMap.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileTypeMap.java
@@ -65,11 +65,14 @@ final class FileTypeMap {
* @throws FileSystemException if an error occurs.
*/
public String getScheme(final FileObject fileObject) throws FileSystemException {
- // Check the file's mime type for a match
+ // Check the file's MIME type for a match
final FileContent content = fileObject.getContent();
final String mimeType = content.getContentInfo().getContentType();
if (mimeType != null) {
- return mimeTypeMap.get(mimeType);
+ final String scheme = mimeTypeMap.get(mimeType);
+ if (scheme != null) {
+ return scheme;
+ }
}
// no specific mime-type - if it is a file also check the extension
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java
new file mode 100644
index 00000000..c4a0b399
--- /dev/null
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.provider.gzip;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.VFS;
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+public class GzipTest {
+
+ @Test
+ public void testCreateGzipFileSystem() throws IOException {
+
+ final File gzFile = new File("src/test/resources/test-data/好.txt.gz");
+ FileSystemManager manager = VFS.getManager();
+
+ try (FileObject localFileObject = manager.resolveFile(gzFile.getAbsolutePath()); FileObject gzFileObject = manager.createFileSystem(localFileObject);) {
+ Assert.assertTrue(gzFileObject instanceof GzipFileObject);
+ }
+ }
+}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 77cfbaf9..af6badc2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,6 +92,9 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Boris Petrov, Gary Gregory">
Refactor AbstractFileObject#getOutputStream() #151.
</action>
+ <action type="fix" issue="VFS-770" dev="ggregory" due-to="Thomas BELOT, PeterAlfredLee, Gary Gregory">
+ FileSystemManager.createFileSystem(FileObject) fails on Gzip files. #92.
+ </action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Seth Falco">
Add vscode files to gitignore #205.