TrueZIP 6.8.3

de.schlichtherle.util.zip
Class LittleEndian

java.lang.Object
  extended by de.schlichtherle.util.zip.LittleEndian

final class LittleEndian
extends Object

Provides static utility methods for reading and writing integer values in little endian format from or to byte arrays.

This class is safe for multithreading.

Since:
TrueZIP 6.7
Author:
Christian Schlichtherle

Constructor Summary
private LittleEndian()
          This class cannot get instantiated.
 
Method Summary
static int readInt(byte[] buf, int off)
          Reads a signed integer value from the byte array buf at the offset off as four bytes, low byte first.
static long readLong(byte[] buf, int off)
          Reads a (signed) long integer value from the byte array buf at the offset off as eight bytes, low byte first.
static short readShort(byte[] buf, int off)
          Reads a signed short integer value from the byte array buf at the offset off as two bytes, low byte first.
static long readUInt(byte[] buf, int off)
          Reads an unsigned integer value from the byte array buf at the offset off as four bytes, low byte first.
static int readUShort(byte[] buf, int off)
          Reads an unsigned short integer value from the byte array buf at the offset off as two bytes, low byte first.
static void writeInt(int i, byte[] buf, int off)
          Writes the integer value i to the byte array buf at the zero based offset off as four bytes, low byte first.
static void writeLong(long l, byte[] buf, int off)
          Writes the long integer value l to the byte array buf at the zero based offset off as eight bytes, low byte first.
static void writeShort(int s, byte[] buf, int off)
          Writes the integer value s to the byte array buf at the zero based offset off as two bytes, low byte first.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LittleEndian

private LittleEndian()
This class cannot get instantiated.

Method Detail

readShort

public static short readShort(byte[] buf,
                              int off)
Reads a signed short integer value from the byte array buf at the offset off as two bytes, low byte first.

Parameters:
buf - The byte array to read the signed short integer value from.
off - The zero based offset in the byte array where the first byte of the signed short integer value is read from.
Returns:
The signed short integer value read from the byte array.

readUShort

public static int readUShort(byte[] buf,
                             int off)
Reads an unsigned short integer value from the byte array buf at the offset off as two bytes, low byte first. Note that it is not necessary to check the return value with UShort.check(int, java.lang.String, java.lang.String).

Parameters:
buf - The byte array to read the unsigned short integer value from.
off - The zero based offset in the byte array where the first byte of the unsigned short integer value is read from.
Returns:
The unsigned short integer value read from the byte array. Java does not provide unsigned short as a primitive type, hence an int is returned which's two most significant bytes are zero.

readInt

public static int readInt(byte[] buf,
                          int off)
Reads a signed integer value from the byte array buf at the offset off as four bytes, low byte first.

Parameters:
buf - The byte array to read the signed integer value from.
off - The zero based offset in the byte array where the first byte of the signed integer value is read from.
Returns:
The signed integer value read from the byte array.

readUInt

public static long readUInt(byte[] buf,
                            int off)
Reads an unsigned integer value from the byte array buf at the offset off as four bytes, low byte first. Note that it is not necessary to check the return value with UInt.check(long, java.lang.String, java.lang.String).

Parameters:
buf - The byte array to read the unsigned integer value from.
off - The zero based offset in the byte array where the first byte of the unsigned integer value is read from.
Returns:
The unsigned integer value read from the byte array. Java does not provide unsigned int as a primitive type, hence a long is returned which's four most significant bytes are zero.

readLong

public static long readLong(byte[] buf,
                            int off)
Reads a (signed) long integer value from the byte array buf at the offset off as eight bytes, low byte first.

Parameters:
buf - The byte array to read the signed long integer value from.
off - The zero based offset in the byte array where the first byte of the (signed) long integer value is read from.
Returns:
The (signed) long integer value read from the byte array.

writeShort

public static void writeShort(int s,
                              byte[] buf,
                              int off)
Writes the integer value s to the byte array buf at the zero based offset off as two bytes, low byte first. The most significant two bytes of the integer value are ignored.

Parameters:
s - The short integer value to be written.
buf - The byte array to write the short integer value to.
off - The zero based offset in the byte array where the first byte of the short integer value is written to.

writeInt

public static void writeInt(int i,
                            byte[] buf,
                            int off)
Writes the integer value i to the byte array buf at the zero based offset off as four bytes, low byte first.

Parameters:
i - The integer value to be written.
buf - The byte array to write the integer value to.
off - The zero based offset in the byte array where the first byte of the integer value is written to.

writeLong

public static void writeLong(long l,
                             byte[] buf,
                             int off)
Writes the long integer value l to the byte array buf at the zero based offset off as eight bytes, low byte first.

Parameters:
l - The long integer value to be written.
buf - The byte array to write the long integer value to.
off - The zero based offset in the byte array where the first byte of the long integer value is written to.

TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.