commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url UrlFileObject.java UrlFileProvider.java UrlFileSystem.java
Date Wed, 21 Aug 2002 01:39:48 GMT
adammurdoch    2002/08/20 18:39:47

  Modified:    vfs/src/java/org/apache/commons/vfs/provider
                        AbstractFileProvider.java
  Added:       vfs/src/java/org/apache/commons/vfs/provider/url
                        UrlFileObject.java UrlFileProvider.java
                        UrlFileSystem.java
  Log:
  Added a file provider that is backed by java.net.URL instances.  Pretty rough at the moment.
  
  Revision  Changes    Path
  1.3       +7 -0      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileProvider.java
  
  Index: AbstractFileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileProvider.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractFileProvider.java	20 Aug 2002 06:10:50 -0000	1.2
  +++ AbstractFileProvider.java	21 Aug 2002 01:39:47 -0000	1.3
  @@ -35,4 +35,11 @@
       {
           m_context = context;
       }
  +
  +    /**
  +     * Closes the provider.  This implementation does nothing.
  +     */
  +    public void close()
  +    {
  +    }
   }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileObject.java
  
  Index: UrlFileObject.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.url;
  
  import java.io.InputStream;
  import java.net.URL;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileType;
  import org.apache.commons.vfs.provider.AbstractFileObject;
  
  /**
   * A {@link FileObject} implementation backed by a {@link URL}.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/21 01:39:47 $
   */
  class UrlFileObject
      extends AbstractFileObject
      implements FileObject
  {
      private URL url;
  
      public UrlFileObject( UrlFileSystem fs,
                            FileName fileName,
                            URL url )
      {
          super( fileName, fs );
          this.url = url;
      }
  
      /**
       * Determines the type of the file.
       */
      protected FileType doGetType() throws Exception
      {
          // TODO - implement this
          return FileType.FILE;
      }
  
      /**
       * Returns the size of the file content (in bytes).
       */
      protected long doGetContentSize() throws Exception
      {
          return url.openConnection().getContentLength();
      }
  
      /**
       * Lists the children of the file.
       */
      protected String[] doListChildren() throws Exception
      {
          throw new FileSystemException( "Not implemented." );
      }
  
      /**
       * Creates an input stream to read the file content from.
       */
      protected InputStream doGetInputStream() throws Exception
      {
          return url.openStream();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
  
  Index: UrlFileProvider.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.url;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.provider.AbstractFileSystemProvider;
  import org.apache.commons.vfs.provider.DefaultFileName;
  import org.apache.commons.vfs.provider.FileSystem;
  import org.apache.commons.vfs.provider.ParsedUri;
  import org.apache.commons.vfs.provider.UriParser;
  
  /**
   * A file provider backed by Java's URL API.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/21 01:39:47 $
   */
  public class UrlFileProvider
      extends AbstractFileSystemProvider
  {
      private final UriParser parser = new UriParser();
  
      /**
       * Parses a URI into its components.
       */
      protected ParsedUri parseUri( FileObject baseFile, String uri )
          throws FileSystemException
      {
          return parser.parseUri( uri );
      }
  
      /**
       * Creates the filesystem.
       */
      protected FileSystem createFileSystem( ParsedUri uri )
          throws FileSystemException
      {
          final DefaultFileName rootName = new DefaultFileName( parser, uri.getRootUri(),
"/" );
          return new UrlFileSystem( getContext(), rootName );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileSystem.java
  
  Index: UrlFileSystem.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.url;
  
  import org.apache.commons.vfs.provider.FileSystem;
  import org.apache.commons.vfs.provider.AbstractFileSystem;
  import org.apache.commons.vfs.provider.FileSystemProviderContext;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import java.net.URL;
  import java.net.MalformedURLException;
  
  /**
   * A File system backed by Java's URL API.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/21 01:39:47 $
   */
  public class UrlFileSystem
      extends AbstractFileSystem
      implements FileSystem
  {
      public UrlFileSystem( final FileSystemProviderContext context,
                            final FileName rootName )
      {
          super( context, rootName );
      }
  
      /**
       * Creates a file object.
       */
      protected FileObject createFile( final FileName name ) throws FileSystemException
      {
          try
          {
              final URL url = new URL( name.getURI() );
              return new UrlFileObject( this, name, url );
          }
          catch ( MalformedURLException e )
          {
              throw new FileSystemException( e );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message