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

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

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

public abstract class ZipUtil
{
  static byte[] copy(byte[] from)
  {
    if (from != null)
    {
      byte[] to = new byte[from.length];
      System.arraycopy(from, 0, to, 0, to.length);
      return to;
    }
    return null;
  }
  
  public static boolean isUTF8(byte[] bs)
  {
    if ((bs.length > 3) && (bs[0] == 239) && (bs[1] == 187) && (bs[2] == 191)) {
      return true;
    }
    int encodingBytesCount = 0;
    byte[] arrayOfByte = bs;int j = bs.length;
    for (int i = 0; i < j; i++)
    {
      byte element = arrayOfByte[i];
      byte c = element;
      if (encodingBytesCount == 0)
      {
        if ((c & 0x80) != 0) {
          if ((c & 0xC0) == 192)
          {
            encodingBytesCount = 1;
            c = (byte)(c << 2);
            while ((c & 0x80) == 128)
            {
              c = (byte)(c << 1);
              encodingBytesCount++;
            }
          }
          else
          {
            return false;
          }
        }
      }
      else if ((c & 0xC0) == 128) {
        encodingBytesCount--;
      } else {
        return false;
      }
    }
    if (encodingBytesCount != 0) {
      return false;
    }
    return true;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy