--- \apache-ant-1.7.0\src\main\org\apache\tools\tar\TarUtils.java Wed Dec 13 07:16:18 2006 +++ tar\TarUtils.java Wed May 23 20:13:01 2007 @@ -146,6 +146,38 @@ } /** + * Encodes an octal integer to a header buffer using older Gnu format. + * + * @param value The header value + * @param buf The buffer to which to encode. + * @param offset The offset into the buffer to which to encode. + * @param length The number of header bytes to encode. + * @return The new offset to header buffer. + */ + public static int setOldOctalBytes(long value, byte[] buf, int offset, int length) { + int idx = length - 1; + + buf[offset + idx] = 0; + --idx; + + if (value == 0) { + buf[offset + idx] = (byte) '0'; + --idx; + } else { + for (long val = value; idx >= 0 && val > 0; --idx) { + buf[offset + idx] = (byte) ((byte) '0' + (byte) (val & 7)); + val = val >> 3; + } + } + + for (; idx >= 0; --idx) { + buf[offset + idx] = (byte) '0'; + } + + return offset + length; + } + + /** * Parse an octal long integer from a header buffer. * * @param value The header value @@ -174,6 +206,24 @@ */ public static int getCheckSumOctalBytes(long value, byte[] buf, int offset, int length) { getOctalBytes(value, buf, offset, length); + + buf[offset + length - 1] = (byte) ' '; + buf[offset + length - 2] = 0; + + return offset + length; + } + + /** + * Encode the checksum octal integer to a header buffer. + * + * @param value The header value + * @param buf The buffer to which to encode. + * @param offset The offset into the buffer to which to encode. + * @param length The number of header bytes to encode. + * @return The new offset to header buffer. + */ + public static int setOldCheckSumOctalBytes(long value, byte[] buf, int offset, int length) { + setOldOctalBytes(value, buf, offset, length - 1); buf[offset + length - 1] = (byte) ' '; buf[offset + length - 2] = 0;