Link to home
Start Free TrialLog in
Avatar of Gadi031698
Gadi031698

asked on

Accessing remote RandomAccessFile

I should write a Servlet that should read from files on a remote host using RandomAccessFile.
Is it possible?  What naming conventions should I use?
ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gadi031698
Gadi031698

ASKER

If I use a URL object, then I can read remote files using openStream, but I would like to read as randomAccess.
The question about the naming conventions was whether to use URLs or the \\host\dir convention.
accessing URL is not accesing file !!!
URL object is just a wrapper of some kind of remote protocol (HTTP / FTP etc.) and as you know the answer you receive can be just a "virtual" query result. (results from database query etc.)

so when you access URL, your computer sends the description of the object you need and the other computer sends the object - itself.
When using HTTP you just send the file name and receive the file (as a stream).

so if you want to have random access to this file you can
1. if the file is not very big - create a memory image of the file on the client computer (byte array) and maybe a "RandomAccessFile wrapper"
2. if the file is Very big and you can't keep it in memory - you should implement a server side CGI which can return parts of the file.

Unfortunately the file is very big.
I understand that I have to write a CGI/Servlet for every server to be accessed.
Am I right?
yes you have to write a CGI / Servlet which can return part of the file (given name, offset and bytes to read).

this CGI/Servlet will extend the default web server beahviour.

of course, you can implement some sort of cache for the client, which will give the bytes immediately if it has a copy or send an HTTP request to the CGI if it has not.

Note: you write one script/servlet with the needed functionality and then you can use this script on every web-server that you work with. (but applets can send request only to their 'parent' server ...)