/** * Parse an entry's header information from a header buffer. * * @param header The tar entry header buffer to get information from. */ public void parseTarHeader(byte[] header) { int offset = 0; name = TarUtils.parseName(header, offset, TarConstants.NAMELEN); offset += TarConstants.NAMELEN; mode = (int)TarUtils.parseOctal(header, offset, TarConstants.MODELEN); offset += TarConstants.MODELEN; userId = (int)TarUtils.parseOctal(header, offset, TarConstants.UIDLEN); offset += TarConstants.UIDLEN; groupId = (int)TarUtils.parseOctal(header, offset, TarConstants.GIDLEN); offset += TarConstants.GIDLEN; size = TarUtils.parseOctal(header, offset, TarConstants.SIZELEN); offset += TarConstants.SIZELEN; modTime = TarUtils.parseOctal(header, offset, TarConstants.MODTIMELEN); offset += TarConstants.MODTIMELEN; offset += TarConstants.CHKSUMLEN; linkFlag = header[offset++]; linkName = TarUtils.parseName(header, offset, TarConstants.NAMELEN); offset += TarConstants.NAMELEN; magic = TarUtils.parseName(header, offset, TarConstants.MAGICLEN); offset += TarConstants.MAGICLEN; version = TarUtils.parseName(header, offset, TarConstants.VERSIONLEN); offset += TarConstants.VERSIONLEN; userName = TarUtils.parseName(header, offset, TarConstants.UNAMELEN); offset += TarConstants.UNAMELEN; groupName = TarUtils.parseName(header, offset, TarConstants.GNAMELEN); offset += TarConstants.GNAMELEN; devMajor = (int)TarUtils.parseOctal(header, offset, TarConstants.DEVLEN); offset += TarConstants.DEVLEN; devMinor = (int)TarUtils.parseOctal(header, offset, TarConstants.DEVLEN); offset += TarConstants.DEVLEN; String prefix = TarUtils.parseName(header, offset, TarConstants.PREFIXLEN); // SunOS tar -E does not add / to directory names, so fix up to be consistent if (isDirectory() && !name.EndsWith("/")) { name = name + "/"; } if (prefix.length() > 0) { name = prefix + "/" + name; } }
/** * Write an entry's header information to a header buffer. * * @param outbuf The tar entry header buffer to fill in. */ public void writeEntryHeader(byte[] outbuf) { int offset = 0; offset = TarUtils.formatNameBytes(name, outbuf, offset, TarConstants.NAMELEN); offset = TarUtils.formatOctalBytes(mode, outbuf, offset, TarConstants.MODELEN); offset = TarUtils.formatOctalBytes(userId, outbuf, offset, TarConstants.UIDLEN); offset = TarUtils.formatOctalBytes(groupId, outbuf, offset, TarConstants.GIDLEN); offset = TarUtils.formatLongOctalBytes(size, outbuf, offset, TarConstants.SIZELEN); offset = TarUtils.formatLongOctalBytes(modTime, outbuf, offset, TarConstants.MODTIMELEN); int csOffset = offset; for (int c = 0; c < TarConstants.CHKSUMLEN; ++c) { outbuf[offset++] = (byte)' '; } outbuf[offset++] = linkFlag; offset = TarUtils.formatNameBytes(linkName, outbuf, offset, TarConstants.NAMELEN); offset = TarUtils.formatNameBytes(magic, outbuf, offset, TarConstants.MAGICLEN); offset = TarUtils.formatNameBytes(version, outbuf, offset, TarConstants.VERSIONLEN); offset = TarUtils.formatNameBytes(userName, outbuf, offset, TarConstants.UNAMELEN); offset = TarUtils.formatNameBytes(groupName, outbuf, offset, TarConstants.GNAMELEN); offset = TarUtils.formatOctalBytes(devMajor, outbuf, offset, TarConstants.DEVLEN); offset = TarUtils.formatOctalBytes(devMinor, outbuf, offset, TarConstants.DEVLEN); while (offset < outbuf.Length) { outbuf[offset++] = 0; } long chk = TarUtils.computeCheckSum(outbuf); TarUtils.formatCheckSumOctalBytes(chk, outbuf, csOffset, TarConstants.CHKSUMLEN); }