[jboss-cvs] JBossAS SVN: r93964 - in projects/demos/microcontainer/trunk/vfs/src/main: java/org/jboss/demos and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 23 16:27:27 EDT 2009
Author: alesj
Date: 2009-09-23 16:27:26 -0400 (Wed, 23 Sep 2009)
New Revision: 93964
Added:
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/Handler.java
projects/demos/microcontainer/trunk/vfs/src/main/resources/
projects/demos/microcontainer/trunk/vfs/src/main/resources/compressed.gzip
projects/demos/microcontainer/trunk/vfs/src/main/resources/text.txt
Modified:
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContextFactory.java
projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java
Log:
Add compressed use case.
Added: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java (rev 0)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/bootstrap/vfs/VFSMain.java 2009-09-23 20:27:26 UTC (rev 93964)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.bootstrap.vfs;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.FileNotFoundException;
+import java.net.URL;
+
+import org.jboss.demos.vfs.gzip.GZipVFSContextFactory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSContextFactoryLocator;
+
+/**
+ * Demo simple GZIP usage.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VFSMain
+{
+ public static void main(String[] args)
+ {
+ try
+ {
+ initGZip();
+
+ // demos.home
+ String demosHome = System.getProperty("demos.home");
+ if (demosHome == null)
+ {
+ if (args.length > 0)
+ demosHome = args[0];
+ else
+ demosHome = "/projects/demos";
+ }
+
+ File test = new File(demosHome + "/vfs/src/main/resources/compressed.gzip");
+ if (test.exists() == false)
+ throw new FileNotFoundException(test.getAbsolutePath());
+
+ String urlString = test.toURI().toURL().toExternalForm();
+ URL url = new URL("gzip" + urlString.substring("file".length()));
+ VirtualFile file = VFS.getRoot(url);
+
+ System.out.println();
+ InputStream is = file.openStream();
+ try
+ {
+ BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
+ String line;
+ while((line = buffer.readLine()) != null)
+ {
+ System.out.println(line);
+ }
+ }
+ finally
+ {
+ is.close();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ }
+
+ protected static void initGZip() throws Exception
+ {
+ // add gzip url handler
+ String pkgs = System.getProperty("java.protocol.handler.pkgs");
+ if (pkgs == null || pkgs.trim().length() == 0)
+ {
+ pkgs = "org.jboss.demos.vfs";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ else if (pkgs.contains("org.jboss.virtual.protocol") == false)
+ {
+ pkgs += "|org.jboss.demos.vfs";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+
+ VFS.init();
+ VFSContextFactoryLocator.registerFactory(new GZipVFSContextFactory());
+ }
+}
Modified: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java 2009-09-23 20:23:32 UTC (rev 93963)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContext.java 2009-09-23 20:27:26 UTC (rev 93964)
@@ -21,6 +21,7 @@
*/
package org.jboss.demos.vfs.gzip;
+import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -28,6 +29,7 @@
import org.jboss.virtual.plugins.context.AbstractVFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.VFSUtils;
/**
* GZIP vfs context.
@@ -36,6 +38,9 @@
*/
public class GZipVFSContext extends AbstractVFSContext
{
+ private File file;
+ private VirtualFileHandler root;
+
public GZipVFSContext(URI rootURI)
{
super(rootURI);
@@ -46,13 +51,36 @@
super(rootURL);
}
+ protected File getFile()
+ {
+ if (file == null)
+ {
+ try
+ {
+ URI rootURI = getRootURI();
+ String urlString = rootURI.toURL().toExternalForm();
+ URL url = new URL("file" + urlString.substring(urlString.indexOf(":/")));
+ file = new File(VFSUtils.toURI(url));
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return file;
+ }
+
public String getName()
{
- return null;
+ return getFile().getName();
}
public VirtualFileHandler getRoot() throws IOException
{
- return null;
+ if (root == null)
+ root = new GZipVirtualFileHandler(this, null, getFile());
+
+ return root;
}
}
\ No newline at end of file
Modified: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContextFactory.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContextFactory.java 2009-09-23 20:23:32 UTC (rev 93963)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVFSContextFactory.java 2009-09-23 20:27:26 UTC (rev 93964)
@@ -57,6 +57,6 @@
public VFSContext getVFS(URI rootURI) throws IOException
{
- return null; // TODO
+ return new GZipVFSContext(rootURI);
}
}
Modified: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java 2009-09-23 20:23:32 UTC (rev 93963)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/GZipVirtualFileHandler.java 2009-09-23 20:27:26 UTC (rev 93964)
@@ -21,12 +21,17 @@
*/
package org.jboss.demos.vfs.gzip;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Collections;
import java.util.List;
+import java.util.zip.GZIPInputStream;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -38,63 +43,67 @@
*/
public class GZipVirtualFileHandler extends AbstractVirtualFileHandler
{
- public GZipVirtualFileHandler(VFSContext context, VirtualFileHandler parent, String name)
+ private File file;
+
+ public GZipVirtualFileHandler(VFSContext context, VirtualFileHandler parent, File file) throws IOException
{
- super(context, parent, name);
+ super(context, parent, file.getName());
+ this.file = file;
+ setVfsUrl(context.getRootURI().toURL());
}
public URI toURI() throws URISyntaxException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return VFSUtils.toURI(getVfsUrl());
}
public long getLastModified() throws IOException
{
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ return file.lastModified();
}
public long getSize() throws IOException
{
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ return file.length();
}
public boolean exists() throws IOException
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return file.exists();
}
public boolean isLeaf() throws IOException
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return file.isFile();
}
public boolean isHidden() throws IOException
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return file.isHidden();
}
public InputStream openStream() throws IOException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return new GZIPInputStream(new FileInputStream(file));
}
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return Collections.emptyList();
}
public VirtualFileHandler getChild(String path) throws IOException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
public boolean removeChild(String name) throws IOException
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return false;
}
public boolean isNested() throws IOException
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return false;
}
}
\ No newline at end of file
Added: projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/Handler.java
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/Handler.java (rev 0)
+++ projects/demos/microcontainer/trunk/vfs/src/main/java/org/jboss/demos/vfs/gzip/Handler.java 2009-09-23 20:27:26 UTC (rev 93964)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.vfs.gzip;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
+/**
+ * GZIP url handler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class Handler extends URLStreamHandler
+{
+ protected URLConnection openConnection(URL url) throws IOException
+ {
+ VirtualFile file = VFS.getRoot(url);
+ return new VirtualFileURLConnection(url, file);
+ }
+}
Added: projects/demos/microcontainer/trunk/vfs/src/main/resources/compressed.gzip
===================================================================
(Binary files differ)
Property changes on: projects/demos/microcontainer/trunk/vfs/src/main/resources/compressed.gzip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: projects/demos/microcontainer/trunk/vfs/src/main/resources/text.txt
===================================================================
--- projects/demos/microcontainer/trunk/vfs/src/main/resources/text.txt (rev 0)
+++ projects/demos/microcontainer/trunk/vfs/src/main/resources/text.txt 2009-09-23 20:27:26 UTC (rev 93964)
@@ -0,0 +1,6 @@
+Welcome to DZone's JBoss Microcontainer series!
+
+This article talks about our VFS impl.
+I hope you enjoy it.
+
+-Ales
More information about the jboss-cvs-commits
mailing list