com.zving.preloader.zip.ZipUtil Maven / Gradle / Ivy
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;
}
}