« February 2005 | Main | April 2005 »

March 2005 Archives

March 10, 2005

Java copy file code

just cause i didnt find code on this fast enough here is code to copy a file using java. It reads the file in while writting it out using buffered readers and writters:

public static void copy(String from, String to) throws IOException{
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(from);
out = new FileOutputStream(to);
int length = 128*10240; // danger!
byte[] bytes = new byte[length];
int read=0;
for(;;){
read=in.read(bytes,0,length);
if(read==-1){
break;
}
out.write(bytes,0,read);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}

March 30, 2005

Java Tar and problems

I have been working on adding a bunch of GNU tar features to java tar. I will release the source soon, but I just wanted to comment on the lack of good documentation on the format that makes it very hard to work with the GNU tar format... Simple things like regular tar takes char 32 as a null and ignored character... and so does GNUtar for the regular tar fields but in the offset field needed for multi volume tars 32 crashes the program giving you header errors. It only accepts char 48 as a null which in the other size field it accepts either 32 or 48... things like this are commented no where and i only discoved by writting and editing the GNU tar source. Which is also far under documentated in the code and very hard to follow.

GNU Tar size field: If your working with GNU tar the size field is just like the standard tar field in ustar... except which is no where to be found in their documentation when you support unlimited size files. If you have a file larger than 8GB to support it you must write the number as bits in twos compliment notation. Also after doing the you have to flip the sign bit (the very most left 0) to a 1. Which would normally mean you have a negative number and now if you decode this as a twos compliment you end up with a huge negative number... but not encoded it normally as a positive number and flip that bit. I only figured this out after manually reading and decoding gnu tar and stanttard ustar headers for a long time. The is nothing that talks about how the support for unlimited files was added to gnu tar... well hopefully if you are having the same problem you found this page. So upgrading GNU tar or other programs to support GNU tar should be easier.

I have added support for these gnu features to javatar:
Multi volume
verification
unlimited filesize
fast single file extraction
Tar Table of contents (xml of the files and there offsets with in the tar)

If your interested in this or have any questions about GNU tar or JAva tar feel free to send me an email and ask.

java code tar

I have released a development version of java tar with added support for various GNU tar features like multi file, verification, and breaking the 8GB barrier. It is pretty nice so if your into learning some java code or working with tar there is alot of good info here and well documentated source code.

Java Tar upgrades

Java Tar

Java Tar source. This might not be the final draft, but it is getting pretty close. Most features seem to be working well and the source is very well documentated. So if you want or need the new GNU features you can get them from java tar here. The main java tar build hasnt incoporated these yet but all of the modifications have been sent off to them, so hopefully they will incorporate them soon.

Java Tar homepage

Until then feel free to download the java tar source from me. You can edit and modify as much as the orginal liscense allows, which says it is public domain use it as you wish. I would like to give a big thanks to Timothy Gerard Endres, who is the orginal author of Java Tar. If you have any questions comments or problems let me know.


Download Java Tar

Web 2.0 craziness

View Dan Mayer's profile on LinkedIn


I Power Seekler
I Power Seekler

www.flickr.com
This is a Flickr badge showing public photos and videos from mayer_dan. Make your own badge here.

Creative Commons License
This weblog is licensed under a Creative Commons License.