commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philippe Poulard <>
Subject [VFS] questions and suggestions
Date Tue, 10 May 2005 17:02:29 GMT

as I'm trying to add a new provider for VFS ("xmldb" scheme), I have 
some questions/suggestions to ask/submit :


Suggestion : Using NIO

I've seen that copying an input stream to an output stream is made with 
FileUtil ; however, when dealing with local files, NIO is not used ; 
i've seen that IS and OS are wrapped in monitored IS/OS, but native 
FileIS and FileOS could be used for a fast copy, like this :

      * Perform a fast copy from file to file.
      * @param input The input to read from.
      * @param output The output to write to.
      * @throws IOException When an I/O error occurs.
     public static void fastCopy( FileInputStream input, 
FileOutputStream output ) throws IOException {
         FileChannel fcin = input.getChannel();
         FileChannel fcout = output.getChannel();
         ByteBuffer buffer = ByteBuffer.allocateDirect( 1024 );
         while (true) {
             int r = buffer );
             if (r==-1) {
             fcout.write( buffer );

      * Copy an input to an output.
      * If both arguments are related to files,
      * a fast copy is performed.
      * @param input The input to read from.
      * @param output The output to write to.
      * @throws IOException When an I/O error occurs.
      * @see #fastCopy(FileInputStream, FileOutputStream)
     public static void copy( InputStream input, OutputStream output )
             throws IOException {
         if ( input instanceof FileInputStream && output instanceof 
FileOutputStream ) {
             // very special case
             fastCopy( (FileInputStream) input, (FileOutputStream) output);
         byte[] buf = new byte[1024];
         int len;
         while ((len = > 0) {
             output.write(buf, 0, len);
Isn't there a way to test if the wrapper could be bypassed if IS and OS 
are good candidates to fast copy ?

Anyway, in the original code, the IS is put in a byte[] ; isn't that 
dangerous when dealing simultaneously with very large files ?


Question : why not use parser ?

I've seen that the code contains its own URI parser ; why not use those 
provided in ?
Additionally, the parser is improved : although that didn't 
cause any troubles, I encountered files that were stored with 
"file:////" instead of "file:///" ; did I miss something ?


Suggestion : dealing with opaque URIs

the FileObject method URL getURL() is somewhat restrictive ; it should 
be replaced by URI getURI() because a FileObject is not necessary 
accessible with an URL
if the URI is really an URL, it can be easily transformed to an URL
if the URI is not an URL, the method willgetURL() will fail

this is important because I also plan to implement some URN schemes, if 
I have enough time


Suggestion : adding a capability to deal with I/O services

URIs that represent remote connexions to some serveurs may also support 
"services" ; an example is XML:DB (the new provider that I try to implement)
with XML:DB it is possible to get a service for special purpose 
interactions with the server, for example a query service.
Providers that support a new Capability.SERVICE could supply a new 
method such as getService( String name, String version) that gives a 
Service like those defined in XML:DB
like this :
     /** A very general purpose service. */
     public interface Service {
         public void addParam( Object name, Object value );
         public void removeParam( Object name );
         public Map getParams();
         public Object justDoIt();
(just think about better method names)


Question : I didn't found in the todo list something that looks like a 
synchronized copy ; is there an obvious implementation or nobody ever 
thought about it ?


Misc : I've seen in the Todo list : "Add more selectors: XPath"

I use myself VFS to traverse file systems with XPath ; that' fine 
because one can use XPath expressions like this :
io:file( '/path/to/my/xml/docs' )//*[@is-file][ends-with( name(), '.xml' )]
I create a wrapper for FileObject (that also extend FileObject) that 
gives an XML-friendly object, that is to say that behaves like an XML 
element that is traversable with XPath

have a look here :
this is an Active Tags module tightly coupled to VFS capabilities
have a look at the Active Tags frontpage too :

at this moment, the implementation works fine with VFS


that's all for the moment ; VFS is a great tool, thanks to the 
developers team :)


           (. .)
|   Philippe Poulard    |

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message