{"id":43,"date":"2012-01-23T17:34:31","date_gmt":"2012-01-23T16:34:31","guid":{"rendered":"http:\/\/www.flamingpenguin.co.uk\/blog\/?p=43"},"modified":"2012-01-23T17:34:31","modified_gmt":"2012-01-23T16:34:31","slug":"unzip-with-apache-vfs-2-0-java","status":"publish","type":"post","link":"https:\/\/www.flamingpenguin.co.uk\/blog\/2012\/01\/23\/unzip-with-apache-vfs-2-0-java\/","title":{"rendered":"Unzip with Apache VFS 2.0 (Java)"},"content":{"rendered":"<p><a href=\"http:\/\/commons.apache.org\/vfs\/\" title=\"commons vfs\">Apache VFS 2.0<\/a> is strange but super powerful. Uncompress a file at a given URI to a given output location: <\/p>\n<pre lang=\"xml\"> \r\n<dependency>\r\n   <groupId>org.apache.commons<\/groupId>\r\n   <artifactId>commons-vfs2<\/artifactId>\r\n   <version>2.0<\/version>\r\n<\/dependency>\r\n<\/pre>\n<pre lang=\"java\">\r\nimport java.io.File;\r\nimport java.io.IOException;\r\nimport java.net.URI;\r\n\r\nimport org.apache.commons.vfs2.AllFileSelector;\r\nimport org.apache.commons.vfs2.FileObject;\r\nimport org.apache.commons.vfs2.FileSystemException;\r\nimport org.apache.commons.vfs2.FileSystemManager;\r\nimport org.apache.commons.vfs2.VFS;\r\n\r\npublic class ZipfileUnpacker\r\n{\r\n   private final FileSystemManager fileSystemManager;\r\n   private final URI packLocation;\r\n\r\n   public ZipfileUnpacker(final URI packLocation) throws FileSystemException\r\n   {\r\n      this.fileSystemManager = VFS.getManager();\r\n      this.packLocation = packLocation;\r\n   }\r\n\r\n   @Override\r\n   public void unpack(final File outputDir) throws IOException\r\n   {\r\n      outputDir.mkdirs();\r\n\r\n      final FileObject packFileObject = fileSystemManager.resolveFile(packLocation.toString());\r\n      try\r\n      {\r\n         final FileObject zipFileSystem = fileSystemManager.createFileSystem(packFileObject);\r\n         try\r\n         {\r\n            fileSystemManager.toFileObject(outputDir).copyFrom(zipFileSystem, new AllFileSelector());\r\n         }\r\n         finally\r\n         {\r\n            zipFileSystem.close();\r\n         }\r\n      }\r\n      finally\r\n      {\r\n         packFileObject.close();\r\n      }\r\n   }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apache VFS 2.0 is strange but super powerful. Uncompress a file at a given URI to a given output location: org.apache.commons commons-vfs2 2.0 import java.io.File; import java.io.IOException; import java.net.URI; import org.apache.commons.vfs2.AllFileSelector; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.VFS; public &hellip; <a href=\"https:\/\/www.flamingpenguin.co.uk\/blog\/2012\/01\/23\/unzip-with-apache-vfs-2-0-java\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":0,"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flamingpenguin.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}