All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zving.preloader.zip.ZipLong Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package com.zving.preloader.zip;

public final class ZipLong
  implements Cloneable
{
  private static final int WORD = 4;
  private static final int BYTE_MASK = 255;
  private static final int BYTE_1 = 1;
  private static final int BYTE_1_MASK = 65280;
  private static final int BYTE_1_SHIFT = 8;
  private static final int BYTE_2 = 2;
  private static final int BYTE_2_MASK = 16711680;
  private static final int BYTE_2_SHIFT = 16;
  private static final int BYTE_3 = 3;
  private static final long BYTE_3_MASK = 4278190080L;
  private static final int BYTE_3_SHIFT = 24;
  private long value;
  
  public ZipLong(long value)
  {
    this.value = value;
  }
  
  public ZipLong(byte[] bytes)
  {
    this(bytes, 0);
  }
  
  public ZipLong(byte[] bytes, int offset)
  {
    this.value = getValue(bytes, offset);
  }
  
  public byte[] getBytes()
  {
    return getBytes(this.value);
  }
  
  public long getValue()
  {
    return this.value;
  }
  
  public static byte[] getBytes(long value)
  {
    byte[] result = new byte[4];
    result[0] = ((byte)(int)(value & 0xFF));
    result[1] = ((byte)(int)((value & 0xFF00) >> 8));
    result[2] = ((byte)(int)((value & 0xFF0000) >> 16));
    result[3] = ((byte)(int)((value & 0xFF000000) >> 24));
    return result;
  }
  
  public static long getValue(byte[] bytes, int offset)
  {
    long value = bytes[(offset + 3)] << 24 & 0xFF000000;
    value += (bytes[(offset + 2)] << 16 & 0xFF0000);
    value += (bytes[(offset + 1)] << 8 & 0xFF00);
    value += (bytes[offset] & 0xFF);
    return value;
  }
  
  public static long getValue(byte[] bytes)
  {
    return getValue(bytes, 0);
  }
  
  public boolean equals(Object o)
  {
    if ((o == null) || (!(o instanceof ZipLong))) {
      return false;
    }
    return this.value == ((ZipLong)o).getValue();
  }
  
  public int hashCode()
  {
    return (int)this.value;
  }
  
  public Object clone()
  {
    try
    {
      return super.clone();
    }
    catch (CloneNotSupportedException cnfe)
    {
      throw new RuntimeException(cnfe);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy