com.android.dex.util.ByteOutput Java Examples

The following examples show how to use com.android.dex.util.ByteOutput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EncodedValueCodec.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Writes an unsigned integral to {@code out}.
 */
public static void writeUnsignedIntegralValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfLeadingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #2
Source File: EncodedValueCodec.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Writes an unsigned integral to {@code out}.
 */
public static void writeUnsignedIntegralValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfLeadingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #3
Source File: EncodedValueCodec.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Writes an unsigned integral to {@code out}.
 */
public static void writeUnsignedIntegralValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfLeadingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #4
Source File: EncodedValueCodec.java    From aapt with Apache License 2.0 6 votes vote down vote up
/**
 * Writes an unsigned integral to {@code out}.
 */
public static void writeUnsignedIntegralValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfLeadingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #5
Source File: EncodedValueCodec.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Writes an unsigned integral to {@code out}.
 */
public static void writeUnsignedIntegralValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfLeadingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #6
Source File: EncodedValueCodec.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a right-zero-extended value to {@code out}.
 */
public static void writeRightZeroExtendedValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfTrailingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    // Scootch the first bits to be written down to the low-order bits.
    value >>= 64 - (requiredBytes * 8);

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #7
Source File: Leb128.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as a signed integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeSignedLeb128(ByteOutput out, int value) {
    int remaining = value >> 7;
    boolean hasMore = true;
    int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

    while (hasMore) {
        hasMore = (remaining != end)
                || ((remaining & 1) != ((value >> 6) & 1));

        out.writeByte((byte) ((value & 0x7f) | (hasMore ? 0x80 : 0)));
        value = remaining;
        remaining >>= 7;
    }
}
 
Example #8
Source File: Leb128.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as an unsigned integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeUnsignedLeb128(ByteOutput out, int value) {
    int remaining = value >>> 7;

    while (remaining != 0) {
        out.writeByte((byte) ((value & 0x7f) | 0x80));
        value = remaining;
        remaining >>>= 7;
    }

    out.writeByte((byte) (value & 0x7f));
}
 
Example #9
Source File: EncodedValueCodec.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a right-zero-extended value to {@code out}.
 */
public static void writeRightZeroExtendedValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfTrailingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    // Scootch the first bits to be written down to the low-order bits.
    value >>= 64 - (requiredBytes * 8);

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #10
Source File: EncodedValueCodec.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a signed integral to {@code out}.
 */
public static void writeSignedIntegralValue(ByteOutput out, int type, long value) {
    /*
     * Figure out how many bits are needed to represent the value,
     * including a sign bit: The bit count is subtracted from 65
     * and not 64 to account for the sign bit. The xor operation
     * has the effect of leaving non-negative values alone and
     * unary complementing negative values (so that a leading zero
     * count always returns a useful number for our present
     * purpose).
     */
    int requiredBits = 65 - Long.numberOfLeadingZeros(value ^ (value >> 63));

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #11
Source File: Leb128.java    From aapt with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as a signed integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeSignedLeb128(ByteOutput out, int value) {
    int remaining = value >> 7;
    boolean hasMore = true;
    int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

    while (hasMore) {
        hasMore = (remaining != end)
                || ((remaining & 1) != ((value >> 6) & 1));

        out.writeByte((byte) ((value & 0x7f) | (hasMore ? 0x80 : 0)));
        value = remaining;
        remaining >>= 7;
    }
}
 
Example #12
Source File: Leb128.java    From aapt with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as an unsigned integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeUnsignedLeb128(ByteOutput out, int value) {
    int remaining = value >>> 7;

    while (remaining != 0) {
        out.writeByte((byte) ((value & 0x7f) | 0x80));
        value = remaining;
        remaining >>>= 7;
    }

    out.writeByte((byte) (value & 0x7f));
}
 
Example #13
Source File: EncodedValueCodec.java    From aapt with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a right-zero-extended value to {@code out}.
 */
public static void writeRightZeroExtendedValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfTrailingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    // Scootch the first bits to be written down to the low-order bits.
    value >>= 64 - (requiredBytes * 8);

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #14
Source File: EncodedValueCodec.java    From aapt with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a signed integral to {@code out}.
 */
public static void writeSignedIntegralValue(ByteOutput out, int type, long value) {
    /*
     * Figure out how many bits are needed to represent the value,
     * including a sign bit: The bit count is subtracted from 65
     * and not 64 to account for the sign bit. The xor operation
     * has the effect of leaving non-negative values alone and
     * unary complementing negative values (so that a leading zero
     * count always returns a useful number for our present
     * purpose).
     */
    int requiredBits = 65 - Long.numberOfLeadingZeros(value ^ (value >> 63));

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #15
Source File: Leb128.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as a signed integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeSignedLeb128(ByteOutput out, int value) {
    int remaining = value >> 7;
    boolean hasMore = true;
    int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

    while (hasMore) {
        hasMore = (remaining != end)
                || ((remaining & 1) != ((value >> 6) & 1));

        out.writeByte((byte) ((value & 0x7f) | (hasMore ? 0x80 : 0)));
        value = remaining;
        remaining >>= 7;
    }
}
 
Example #16
Source File: Leb128.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as an unsigned integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeUnsignedLeb128(ByteOutput out, int value) {
    int remaining = value >>> 7;

    while (remaining != 0) {
        out.writeByte((byte) ((value & 0x7f) | 0x80));
        value = remaining;
        remaining >>>= 7;
    }

    out.writeByte((byte) (value & 0x7f));
}
 
Example #17
Source File: EncodedValueCodec.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a signed integral to {@code out}.
 */
public static void writeSignedIntegralValue(ByteOutput out, int type, long value) {
    /*
     * Figure out how many bits are needed to represent the value,
     * including a sign bit: The bit count is subtracted from 65
     * and not 64 to account for the sign bit. The xor operation
     * has the effect of leaving non-negative values alone and
     * unary complementing negative values (so that a leading zero
     * count always returns a useful number for our present
     * purpose).
     */
    int requiredBits = 65 - Long.numberOfLeadingZeros(value ^ (value >> 63));

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #18
Source File: EncodedValueCodec.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a signed integral to {@code out}.
 */
public static void writeSignedIntegralValue(ByteOutput out, int type, long value) {
    /*
     * Figure out how many bits are needed to represent the value,
     * including a sign bit: The bit count is subtracted from 65
     * and not 64 to account for the sign bit. The xor operation
     * has the effect of leaving non-negative values alone and
     * unary complementing negative values (so that a leading zero
     * count always returns a useful number for our present
     * purpose).
     */
    int requiredBits = 65 - Long.numberOfLeadingZeros(value ^ (value >> 63));

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #19
Source File: Leb128.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as a signed integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeSignedLeb128(ByteOutput out, int value) {
    int remaining = value >> 7;
    boolean hasMore = true;
    int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

    while (hasMore) {
        hasMore = (remaining != end)
                || ((remaining & 1) != ((value >> 6) & 1));

        out.writeByte((byte) ((value & 0x7f) | (hasMore ? 0x80 : 0)));
        value = remaining;
        remaining >>= 7;
    }
}
 
Example #20
Source File: Leb128.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as an unsigned integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeUnsignedLeb128(ByteOutput out, int value) {
    int remaining = value >>> 7;

    while (remaining != 0) {
        out.writeByte((byte) ((value & 0x7f) | 0x80));
        value = remaining;
        remaining >>>= 7;
    }

    out.writeByte((byte) (value & 0x7f));
}
 
Example #21
Source File: EncodedValueCodec.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a right-zero-extended value to {@code out}.
 */
public static void writeRightZeroExtendedValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfTrailingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    // Scootch the first bits to be written down to the low-order bits.
    value >>= 64 - (requiredBytes * 8);

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #22
Source File: EncodedValueCodec.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a signed integral to {@code out}.
 */
public static void writeSignedIntegralValue(ByteOutput out, int type, long value) {
    /*
     * Figure out how many bits are needed to represent the value,
     * including a sign bit: The bit count is subtracted from 65
     * and not 64 to account for the sign bit. The xor operation
     * has the effect of leaving non-negative values alone and
     * unary complementing negative values (so that a leading zero
     * count always returns a useful number for our present
     * purpose).
     */
    int requiredBits = 65 - Long.numberOfLeadingZeros(value ^ (value >> 63));

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #23
Source File: Leb128.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as a signed integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeSignedLeb128(ByteOutput out, int value) {
    int remaining = value >> 7;
    boolean hasMore = true;
    int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

    while (hasMore) {
        hasMore = (remaining != end)
                || ((remaining & 1) != ((value >> 6) & 1));

        out.writeByte((byte) ((value & 0x7f) | (hasMore ? 0x80 : 0)));
        value = remaining;
        remaining >>= 7;
    }
}
 
Example #24
Source File: Leb128.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@code value} as an unsigned integer to {@code out}, starting at
 * {@code offset}. Returns the number of bytes written.
 */
public static void writeUnsignedLeb128(ByteOutput out, int value) {
    int remaining = value >>> 7;

    while (remaining != 0) {
        out.writeByte((byte) ((value & 0x7f) | 0x80));
        value = remaining;
        remaining >>>= 7;
    }

    out.writeByte((byte) (value & 0x7f));
}
 
Example #25
Source File: EncodedValueCodec.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a right-zero-extended value to {@code out}.
 */
public static void writeRightZeroExtendedValue(ByteOutput out, int type, long value) {
    // Figure out how many bits are needed to represent the value.
    int requiredBits = 64 - Long.numberOfTrailingZeros(value);
    if (requiredBits == 0) {
        requiredBits = 1;
    }

    // Round up the requiredBits to a number of bytes.
    int requiredBytes = (requiredBits + 0x07) >> 3;

    // Scootch the first bits to be written down to the low-order bits.
    value >>= 64 - (requiredBytes * 8);

    /*
     * Write the header byte, which includes the type and
     * requiredBytes - 1.
     */
    out.writeByte(type | ((requiredBytes - 1) << 5));

    // Write the value, per se.
    while (requiredBytes > 0) {
        out.writeByte((byte) value);
        value >>= 8;
        requiredBytes--;
    }
}
 
Example #26
Source File: IndexMap.java    From Box with Apache License 2.0 4 votes vote down vote up
public EncodedValueTransformer(ByteOutput out) {
    this.out = out;
}
 
Example #27
Source File: IndexMap.java    From Box with Apache License 2.0 4 votes vote down vote up
public EncodedValueTransformer(ByteOutput out) {
    this.out = out;
}
 
Example #28
Source File: IndexMap.java    From buck with Apache License 2.0 4 votes vote down vote up
public EncodedValueTransformer(ByteOutput out) {
    this.out = out;
}