Results 1 to 5 of 5
- 04-02-2010, 06:17 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
get the size and filename of the jar file run from and SHA
i'm currently writing a client-server rpg game and i used some networking code to allow the program to download its own updates.
at the minute, whilst im testing it, i want to check the filesize of the jar file compared to the one on the server. how can i get the file size and name of the jar file being run from?
cant seem to find an easy way to get the jar file name, or the filesize.
also later on will be using SHA to compute the value of the jar file to check if has been altered, if anyone knows how to do this.
thanksLast edited by aztectrev; 04-03-2010 at 07:45 PM.
- 04-03-2010, 08:33 AM #2
Java Code:java.net.URL url = this.getClass().getResource(""); System.out.println(url.getPath());
If you run it as a jar it will contain the path to the jar followed by the path of the class in the jar.
c:/some/where/is/MyJar.jar!/com/myproject/main.class
You can parse out the file path and use the File object to get details about the file (i.e. file size)
For the file updater i wrote i used the check sum of the file contents to determine it's version and whether or not it needed updating.
Java Code:CheckedInputStream cis = new CheckedInputStream(is, new Adler32());
I'm not sure how you would determine if the file is altered or not... they could just send you the value you want to see instead the actual value you would have computed. I would say let them alter the jar if they want... just never trust the client and what they are sending you.My Hobby Project: LegacyClone
- 04-03-2010, 11:41 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
still a problem
i use eclipse as my java ide and use the export runnable jar option, but it exports it in a way that the path returned by the URL is 'rsrc:' followed by the package name and not the full path. this seems to be something to do with the jar in jar loader it uses, as it packages the jar libraries.
the checkedinputstream looks like it could do the job though, once i sort this first problem. another reason i want to use checkedinputstream is the game may change alot and the filesize might be the same, but the contents different. i dont want people to be able to use an old version
thanks for reply
- 04-03-2010, 06:12 PM #4
I usually use Netbeans to build my jars but i ran a quick test using eclipse exporting as a runnable jar; eclipse showed my path to be (in linux; ran from console):
file:/home/someone/Desktop/someone.jar!/Main.class
another reason i want to use checkedinputstream is the game may change alot and the filesize might be the same, but the contents different.
Yep seems there would be a pretty high chance of the file size being the same at some point. One issue i found with the checkedInputStream and jar files is the timestamps of the files inside the jar. If the timestamp changes but the file is the same you get a different checksum value. Instead of taking the checksum of the jar i had to take a checksum of each file contained in the jar.Last edited by mrmatt1111; 04-03-2010 at 06:19 PM.
My Hobby Project: LegacyClone
- 04-03-2010, 06:20 PM #5
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
fixed, kind of
i managed to work around it, it was a prob with exporting, as the external jars were placed within my main jar. i changed the export option to just place them external jars in the same directory, as my own and it now returns proper path and then i could use Checkedinputstream on my jar file
Similar Threads
-
PDF file size
By tim in forum Suggestions & FeedbackReplies: 2Last Post: 04-08-2010, 12:59 PM -
validation on file size
By kirtichopra2003 in forum Advanced JavaReplies: 1Last Post: 10-30-2009, 07:08 AM -
Jar resource file size
By OrangeDog in forum Java AppletsReplies: 1Last Post: 04-30-2009, 04:12 AM -
Set the Size of jvm.log file
By kasidandu in forum New To JavaReplies: 0Last Post: 03-16-2009, 04:08 PM -
File size
By eva in forum New To JavaReplies: 2Last Post: 12-19-2007, 09:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks