/** * 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.getNameBytes(this.name, outbuf, offset, NAMELEN); offset = TarUtils.getOctalBytes(this.mode, outbuf, offset, MODELEN); offset = TarUtils.getOctalBytes(this.userId, outbuf, offset, UIDLEN); offset = TarUtils.getOctalBytes(this.groupId, outbuf, offset, GIDLEN); offset = TarUtils.getLongOctalBytes(this.size, outbuf, offset, SIZELEN); offset = TarUtils.getLongOctalBytes(this.modTime, outbuf, offset, MODTIMELEN); int csOffset = offset; for (int c = 0; c < CHKSUMLEN; ++c) { outbuf[offset++] = (byte) ' '; } outbuf[offset++] = this.linkFlag; offset = TarUtils.getNameBytes(this.linkName, outbuf, offset, NAMELEN); offset = TarUtils.getNameBytes(this.magic, outbuf, offset, MAGICLEN); offset = TarUtils.getNameBytes(this.userName, outbuf, offset, UNAMELEN); offset = TarUtils.getNameBytes(this.groupName, outbuf, offset, GNAMELEN); offset = TarUtils.getOctalBytes(this.devMajor, outbuf, offset, DEVLEN); offset = TarUtils.getOctalBytes(this.devMinor, outbuf, offset, DEVLEN); while (offset < outbuf.length) { outbuf[offset++] = 0; } long checkSum = TarUtils.computeCheckSum(outbuf); TarUtils.getCheckSumOctalBytes(checkSum, outbuf, csOffset, CHKSUMLEN); }
/** * Write an entry's header information to a header buffer. * * @param outbuf The tar entry header buffer to fill in. * @param encoding encoding to use when writing the file name. * @param starMode whether to use the star/GNU tar/BSD tar extension for numeric fields if their * value doesn't fit in the maximum size of standard tar archives * @since 1.4 */ public void writeEntryHeader(byte[] outbuf, ZipEncoding encoding, boolean starMode) throws IOException { int offset = 0; offset = TarUtils.formatNameBytes(name, outbuf, offset, NAMELEN, encoding); offset = writeEntryHeaderField(mode, outbuf, offset, MODELEN, starMode); offset = writeEntryHeaderField(userId, outbuf, offset, UIDLEN, starMode); offset = writeEntryHeaderField(groupId, outbuf, offset, GIDLEN, starMode); offset = writeEntryHeaderField(size, outbuf, offset, SIZELEN, starMode); offset = writeEntryHeaderField(modTime, outbuf, offset, MODTIMELEN, starMode); int csOffset = offset; for (int c = 0; c < CHKSUMLEN; ++c) { outbuf[offset++] = (byte) ' '; } outbuf[offset++] = linkFlag; offset = TarUtils.formatNameBytes(linkName, outbuf, offset, NAMELEN, encoding); offset = TarUtils.formatNameBytes(magic, outbuf, offset, MAGICLEN); offset = TarUtils.formatNameBytes(version, outbuf, offset, VERSIONLEN); offset = TarUtils.formatNameBytes(userName, outbuf, offset, UNAMELEN, encoding); offset = TarUtils.formatNameBytes(groupName, outbuf, offset, GNAMELEN, encoding); offset = writeEntryHeaderField(devMajor, outbuf, offset, DEVLEN, starMode); offset = writeEntryHeaderField(devMinor, outbuf, offset, DEVLEN, starMode); while (offset < outbuf.length) { outbuf[offset++] = 0; } long chk = TarUtils.computeCheckSum(outbuf); TarUtils.formatCheckSumOctalBytes(chk, outbuf, csOffset, CHKSUMLEN); }