tags:

views:

31

answers:

1

Dear all,

I'm implementing a Java-based system which needs accessing both the native and networked filesystems. Using the Java File class is easy and straight forward in the native case, and I'd like to keep this consistency to user even the filesystem is connected over the network.

e.g. File folder = new File("some_folder"); File[] files = folder.listFiles(); if the instance "folder" is network-attached, the folder.listFiles() will trigger the related network transaction to retrieve the remote file structure.

The problems include, is it possible to extending the File class with the same name? If a new given name for the subClass is needed, e.g. NetedFile, how to deal with the return type in the methods like File[] listFiles() while I don't want to wrap the element from File to NetedFile one-by-one.

Please kindly advise.

Thanks & regards, William Choi

+1  A: 

The good news is that if you mount a remote file system on your machine using NFS, SMB and other protocols, then File objects for files or directories on the remote FS should just work. No extra coding is required.

The bad news is that this doesn't work for remote file systems that you access using FTP or HTTP. Also, the remote filesystem mounting and access must be implemented at the operating system level.

EDIT

If you are trying to treat a regular HTTP server as a file system, you've got a number of problems, starting with the problem that the standard HTTP protocol does not make any distinction between files or directories. They are all "resources".

If you are talking about a WebDAV enabled HTTP server, there are apparently drivers around that allow you to mount a remote WebDAV server as a file system; e.g. do a Google search for "webdav mount windows" or "webdav mount linux".

If you have to do all of this in Java (e.g. if the proprietary "channel" is a Java class), I don't know how you would go about doing it.

Stephen C
Thanks Stephen,
William Choi
And actually I'm facing the bad one, since we have our own proprietary http channel class to operate on.
William Choi
Thx Stephen. Yes, all in pure java. It seems to me I have to change the design that keep the File class no extension, and add a new class e.g. NetedFS which has methods that take File as argument to perform the related operation.
William Choi