Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > RandomAccessFile in JAR

Reply
Thread Tools

RandomAccessFile in JAR

 
 
ak
Guest
Posts: n/a
 
      10-24-2003
Hi, I need to create RandomAccessFile for file which is in JAR. Is it
possible?


 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      10-24-2003
"ak" <(E-Mail Removed)> writes:
> Hi, I need to create RandomAccessFile for file which is in JAR. Is it
> possible?


No.
 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-24-2003
ak wrote:
> Hi, I need to create RandomAccessFile for file which is in JAR. Is it
> possible?


No. The compression makes local changes impossible.

 
Reply With Quote
 
Ben_
Guest
Posts: n/a
 
      10-24-2003
Hello,

If what you want to do is modify a ZipEntry without extracting it, then I
don't see it feasible, because you have to extract the ZipEntry to alter it
and then re-zip it. My assumption is based on the fact that the API doesn't
mention this and on the fact that it's what Zip file managers do (like
WinZip, etc).


 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      10-24-2003

"Michael Borgwardt" <(E-Mail Removed)> schrieb im Newsbeitrag
news:bnb0ku$v6il9$(E-Mail Removed)-berlin.de...
> ak wrote:
> > Hi, I need to create RandomAccessFile for file which is in JAR. Is it
> > possible?

>
> No. The compression makes local changes impossible.
>

Hmm, I don't want to change anything. Just create RandomAccessFile.


 
Reply With Quote
 
Ben_
Guest
Posts: n/a
 
      10-24-2003
> Hmm, I don't want to change anything. Just create RandomAccessFile.
The idea you have is obvious to you, but not to us. You should give details
if you want support...


 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      10-24-2003
That simple, i wrote RandomAccessByteArray (which extends
RandomAccessFile) - so I can read byte array as RandomAccessFile.
Constructor of RandomAccessFile needs valid File.
I used before some temporary file. But this approach dont work if my
programm runs in applet.


hier is my code:

//create file in same directory with my JAR file
private static File f = new File("..\\xxx.tmp");

int fp;

private static File createFile() throws IOException {
FileOutputStream fos = new FileOutputStream(f);
//ensure that file really created
fos.write(100);
IOutils.closeStream(fos);
return f;
}

byte[] buf;
String mode;
int length;
int offset;

/**
* create new RandomAccessByteArray that looks like RandomAccessFile
* @param mode ignored
* @param data byte array
* @throws IOException
*/
public RandomAccessByteArray(String mode, byte[] data) throws IOException {
this(mode, data, 0, data.length);
}

/**
* create new RandomAccessByteArray that looks like RandomAccessFile
* @param mode ignored
* @param data byte array
* @param off index of the first byte
* @param length number of bytes
* @throws IOException
*/
public RandomAccessByteArray(String mode, byte[] data, int off, int length)
throws IOException {
super(createFile(), "r");
this.mode = mode;
this.buf = data;
this.length = length;
this.offset = off;

//clean up
try {
super.close();
}
catch(IOException ex) {
ex.printStackTrace();
}
finally {
f.delete();
}
}


"Ben_" <reply@newsgroup> schrieb im Newsbeitrag
news:3f9913ff$0$259$(E-Mail Removed) e...
> > Hmm, I don't want to change anything. Just create RandomAccessFile.

> The idea you have is obvious to you, but not to us. You should give

details
> if you want support...
>
>



 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-24-2003
ak wrote:
> That simple, i wrote RandomAccessByteArray (which extends
> RandomAccessFile) - so I can read byte array as RandomAccessFile.
> Constructor of RandomAccessFile needs valid File.
> I used before some temporary file. But this approach dont work if my
> programm runs in applet.


And you thought you could put it in the applet's own JAR???
That's even more impossible.

Do you actually need *random* access? Or just the readXX methods?
In the latter case, a DataInputStream wrapped around a ByteArrayInputStream
offers the same.

 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      10-24-2003
Yes, I really need *random* access.


"Michael Borgwardt" <(E-Mail Removed)> schrieb im Newsbeitrag
news:bnb7gk$v74ju$(E-Mail Removed)-berlin.de...
> ak wrote:
> > That simple, i wrote RandomAccessByteArray (which extends
> > RandomAccessFile) - so I can read byte array as RandomAccessFile.
> > Constructor of RandomAccessFile needs valid File.
> > I used before some temporary file. But this approach dont work if my
> > programm runs in applet.

>
> And you thought you could put it in the applet's own JAR???
> That's even more impossible.
>
> Do you actually need *random* access? Or just the readXX methods?
> In the latter case, a DataInputStream wrapped around a

ByteArrayInputStream
> offers the same.



 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-24-2003
ak wrote:
> Yes, I really need *random* access.


Then I think the best method would be to implement the methods from
RandomAccessFile that you need yourself to work directly on a byte
array. Shouldn't be too difficult.

Having a temporary file is simply not possible in an applet, at least
not with the standard security policy.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
RandomAccessFile opening of a file inside an executable jar? Christopher Fuhrman Java 5 08-20-2004 02:46 AM



Advertisments