Class LittleEndianUtils
- java.lang.Object
-
- com.android.tools.build.apkzlib.zip.utils.LittleEndianUtils
-
public class LittleEndianUtils extends java.lang.ObjectUtilities to read and write 16, 32, and 64 bit integers with support for little-endian encoding, as used in zip files. Zip files actually use unsigned data types. We use Java's native (signed) data types but will use long (64 bit) to ensure we can fit the whole range for the 16 and 32 bit fields.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intreadUnsigned2Le(java.nio.ByteBuffer bytes)Reads 2 bytes in little-endian format and converts them into a 16-bit value.static longreadUnsigned4Le(java.nio.ByteBuffer bytes)Reads 4 bytes in little-endian format and converts them into a 32-bit value.static longreadUnsigned8Le(java.nio.ByteBuffer bytes)Reads 8 bytes in little-endian format and converts them into a 64-bit value.static voidwriteUnsigned2Le(java.nio.ByteBuffer output, int value)Writes 2 bytes in little-endian format, converting them from a 16-bit value.static voidwriteUnsigned4Le(java.nio.ByteBuffer output, long value)Writes 4 bytes in little-endian format, converting them from a 32-bit value.static voidwriteUnsigned8Le(java.nio.ByteBuffer output, long value)Writes 8 bytes in little-endian format, converting them from a signed 64-bit value.
-
-
-
Method Detail
-
readUnsigned8Le
public static long readUnsigned8Le(java.nio.ByteBuffer bytes) throws java.io.IOExceptionReads 8 bytes in little-endian format and converts them into a 64-bit value.- Parameters:
bytes- from where should the bytes be read; the first 8 bytes of the source will be read.- Returns:
- the 64-bit value
- Throws:
java.io.IOException- failed to read the value.
-
readUnsigned4Le
public static long readUnsigned4Le(java.nio.ByteBuffer bytes) throws java.io.IOExceptionReads 4 bytes in little-endian format and converts them into a 32-bit value.- Parameters:
bytes- from where should the bytes be read; the first 4 bytes of the source will be read- Returns:
- the 32-bit value
- Throws:
java.io.IOException- failed to read the value
-
readUnsigned2Le
public static int readUnsigned2Le(java.nio.ByteBuffer bytes) throws java.io.IOExceptionReads 2 bytes in little-endian format and converts them into a 16-bit value.- Parameters:
bytes- from where should the bytes be read; the first 2 bytes of the source will be read- Returns:
- the 16-bit value
- Throws:
java.io.IOException- failed to read the value
-
writeUnsigned8Le
public static void writeUnsigned8Le(java.nio.ByteBuffer output, long value) throws java.io.IOExceptionWrites 8 bytes in little-endian format, converting them from a signed 64-bit value.- Parameters:
output- the output stream where the bytes will be written.value- the 64-bit value to convert.- Throws:
java.io.IOException- failed to write the value data.
-
writeUnsigned4Le
public static void writeUnsigned4Le(java.nio.ByteBuffer output, long value) throws java.io.IOExceptionWrites 4 bytes in little-endian format, converting them from a 32-bit value.- Parameters:
output- the output stream where the bytes will be writtenvalue- the 32-bit value to convert- Throws:
java.io.IOException- failed to write the value data
-
writeUnsigned2Le
public static void writeUnsigned2Le(java.nio.ByteBuffer output, int value) throws java.io.IOExceptionWrites 2 bytes in little-endian format, converting them from a 16-bit value.- Parameters:
output- the output stream where the bytes will be writtenvalue- the 16-bit value to convert- Throws:
java.io.IOException- failed to write the value data
-
-