return formatLongOctalBytes(value, buf, offset, length); formatLongBinary(value, buf, offset, length, negative); formatBigIntegerBinary(value, buf, offset, length, negative);
private int writeEntryHeaderField(long value, byte[] outbuf, int offset, int length, boolean starMode) { if (!starMode && (value < 0 || value >= (1L << (3 * (length - 1))))) { // value doesn't fit into field when written as octal // number, will be written to PAX header or causes an // error return TarUtils.formatLongOctalBytes(0, outbuf, offset, length); } return TarUtils.formatLongOctalOrBinaryBytes(value, outbuf, offset, length); }
/** * Writes an octal value into a buffer. * * Uses {@link #formatUnsignedOctalString} to format * the value as an octal string with leading zeros. * The converted number is followed by NUL and then space. * * @param value The value to convert * @param buf The destination buffer * @param offset The starting offset into the buffer. * @param length The size of the buffer. * @return The updated value of offset, i.e. offset+length * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer */ public static int formatCheckSumOctalBytes(final long value, final byte[] buf, final int offset, final int length) { int idx = length - 2; // for NUL and space formatUnsignedOctalString(value, buf, offset, idx); buf[offset + idx++] = 0; // Trailing null buf[offset + idx] = (byte) ' '; // Trailing space return offset + length; }
/** * Compute the value contained in a byte buffer. If the most * significant bit of the first byte in the buffer is set, this * bit is ignored and the rest of the buffer is interpreted as a * binary number. Otherwise, the buffer is interpreted as an * octal number as per the parseOctal function above. * * @param buffer The buffer from which to parse. * @param offset The offset into the buffer from which to parse. * @param length The maximum number of bytes to parse. * @return The long value of the octal or binary string. * @throws IllegalArgumentException if the trailing space/NUL is * missing or an invalid byte is detected in an octal number, or * if a binary number would exceed the size of a signed long * 64-bit integer. */ public static long parseOctalOrBinary(final byte[] buffer, final int offset, final int length) { if ((buffer[offset] & 0x80) == 0) { return parseOctal(buffer, offset, length); } final boolean negative = buffer[offset] == (byte) 0xff; if (length < 9) { return parseBinaryLong(buffer, offset, length, negative); } return parseBinaryBigInteger(buffer, offset, length, negative); }
int offset = 0; offset = TarUtils.formatNameBytes(name, outbuf, offset, NAMELEN, encoding); offset = writeEntryHeaderField(mode, outbuf, offset, MODELEN, starMode); offset = TarUtils.formatNameBytes(linkName, outbuf, offset, NAMELEN, encoding); offset = TarUtils.formatNameBytes(magic, outbuf, offset, PURE_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, long chk = TarUtils.computeCheckSum(outbuf); TarUtils.formatCheckSumOctalBytes(chk, outbuf, csOffset, CHKSUMLEN);
/** * Copy a name into a buffer. * Copies characters from the name into the buffer * starting at the specified offset. * If the buffer is longer than the name, the buffer * is filled with trailing NULs. * If the name is longer than the buffer, * the output is truncated. * * @param name The header name from which to copy the characters. * @param buf The buffer where the name is to be stored. * @param offset The starting offset into the buffer * @param length The maximum number of header bytes to copy. * @return The updated offset, i.e. offset + length */ public static int formatNameBytes(final String name, final byte[] buf, final int offset, final int length) { try { return formatNameBytes(name, buf, offset, length, DEFAULT_ENCODING); } catch (final IOException ex) { try { return formatNameBytes(name, buf, offset, length, FALLBACK_ENCODING); } catch (final IOException ex2) { // impossible throw new RuntimeException(ex2); //NOSONAR } } }
exceptionMessage(buffer, offset, length, start, currentByte));
/** * Write an octal long integer into a buffer. * * Uses {@link #formatUnsignedOctalString} to format * the value as an octal string with leading zeros. * The converted number is followed by a space. * * @param value The value to write as octal * @param buf The destinationbuffer. * @param offset The starting offset into the buffer. * @param length The length of the buffer * @return The updated offset * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer */ public static int formatLongOctalBytes(final long value, final byte[] buf, final int offset, final int length) { final int idx = length - 1; // For space formatUnsignedOctalString(value, buf, offset, idx); buf[offset + idx] = (byte) ' '; // Trailing space return offset + length; }
/** * Write an octal integer into a buffer. * * Uses {@link #formatUnsignedOctalString} to format * the value as an octal string with leading zeros. * The converted number is followed by space and NUL * * @param value The value to write * @param buf The buffer to receive the output * @param offset The starting offset into the buffer * @param length The size of the output buffer * @return The updated offset, i.e offset+length * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer */ public static int formatOctalBytes(final long value, final byte[] buf, final int offset, final int length) { int idx = length - 2; // For space and trailing null formatUnsignedOctalString(value, buf, offset, idx); buf[offset + idx++] = (byte) ' '; // Trailing space buf[offset + idx] = 0; // Trailing null return offset + length; }