Re: Java support of GNU Tar



james.w.appleby@xxxxxxxxx wrote:

The error I get occurs when I am trying to repack the files into a
Tar. The relevant part of the stack trace is:

java.io.IOException: request to write '7608' bytes exceeds size in
header of '0' bytes
at org.apache.tools.tar.TarOutputStream.write(TarOutputStream.java:
235)
at utilities.ArchiveFormatter.packGZip(ArchiveFormatter.java:324)

Has anyone ever tried to use the Apache code for their own code or
have any idea why I would get the exception above?

I have never used any of the tar pakages for Java so the following is only an
educated guess.

I suspect that you'll have to supply the size of the tar file entry before you
start writing the data for that entry.

From the sound of the error message, the Apache code hasn't been told how long
the data is going to be and has defaulted to zero. So when you call
TarOutputStream.write() it checks that you are not writing more data than it
has been told to expect, and -- finding that you are -- refuses to play.

In the tar file format the size of each file's data is embedded in the output
file /before/ the data itself. So obviously the TarOutputStream needs to know
how much data you are going to supply in advance[*]. The ICE implementation of
TarGzipOuputStream has code to buffer-up the write()s in memory until the entry
is close()ed, at which time it updates the header, and then writes the real
data. (I don't know why TarOutputStream doesn't do the same thing for
uncompressed tar files -- maybe I'm missing an option somewhere.) Which is
presumably why your existing code worked with that package.

If the Apache equivalent of TarGzipOuputStream lacks that feature for some
reason, or if it doesn't work the same way, then maybe that's why you are
seeing this failure.

-- chris

[*] Actually, it could just write the data as you supply it and then go back in
the output file and patch the size information, but the ICE implementation
doesn't try to do that -- and anyway it couldn't because you can't jump back
and forth in a gzip-compressed stream.





.



Relevant Pages

  • Re: Why "dd" for cloning?
    ... Those are all filesystems on a LVM. ... how do you make an *IMAGE* with tar or cp? ... If I make a tar backup of my Linux box (of some *random* version of the ... can view/extract/whatever elements of that tar file on some other ...
    (comp.os.linux.misc)
  • Re: Toasting MiNT
    ... Jim DeClercq wrote: ... > There is nothing at all wrong with tar. ... > needed to put the tar file onto a CD. ... auto folder, mint folder, aes, desktop, mke2fs and tar. ...
    (comp.sys.atari.st)
  • Re: Q about using tar to do backups
    ... >>I'm using tar to create a complete system backup. ... >>dont want to delete the old 500 meg tar file but i would like to replace ...
    (alt.linux)
  • [AIX4.3 tar -u] "tar -u" introduces checksum error in tar file made previously on SOLARIS
    ... I have a tar files made on SOLARIS. ... When I update them on AIX platform ... let's make the initial tar file ...
    (comp.unix.aix)
  • Problem untaring python2.5
    ... i am not able to untar python 2.5 source code using " ... tar: Skipping to next header ...
    (comp.lang.python)