Java Code Examples for com.google.gwt.typedarrays.shared.Uint8Array#get()

The following examples show how to use com.google.gwt.typedarrays.shared.Uint8Array#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DjVuText.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
private static int nextChar(
  Uint8Array byteArray,
  int    pos)
{
  if(pos < byteArray.length())
  {
    while(++pos < byteArray.length())
    {
      if((byteArray.get(pos) & 0xc0) != 0x80)
      {
        return pos;
      }
    }
  }

  return pos;
}
 
Example 2
Source File: DjVuText.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
private int firstEndSpace(
  final Uint8Array byteArray,
  int          start,
  final int    length)
{
  for(int pos = start + length; --pos >= start;)
  {
    if(
      ((byteArray.get(pos) & 0xc0) != 0x80)
      && !isspace(getChar(byteArray, pos)))
    {
      return nextChar(byteArray, pos);
    }
  }

  return start;
}
 
Example 3
Source File: DjVuText.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
private static int prevChar(
  Uint8Array byteArray,
  int    pos)
{
  if(pos >= 0)
  {
    while(--pos >= 0)
    {
      if((byteArray.get(pos) & 0xc0) != 0x80)
      {
        return pos;
      }
    }
  }

  return pos;
}
 
Example 4
Source File: Conversion.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static byte[] convertBytes(ArrayBuffer buffer) {
    Uint8Array array = TypedArrays.createUint8Array(buffer);
    byte[] res = new byte[array.length()];
    for (int i = 0; i < res.length; i++) {
        res[i] = (byte) (array.get(i));
    }
    return res;
}
 
Example 5
Source File: DjVuText.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean char_equal(
  byte[] first,
  int    firstPos,
  Uint8Array second,
  int    secondPos)
{    
  if(first[firstPos] != second.get(secondPos++))
  {
    return false;
  }

  if((first[firstPos++] & 0xc0) < 0x80)
  {
    return true;
  }

  // skip the first bytes (assumed to be equal)
  while(
    ((first[firstPos] & 0xc0) == 0x80)
    && ((second.get(secondPos) & 0xc0) == 0x80))
  {
    // both bytes are UTF8 continuation bytes
    if(first[firstPos++] != second.get(secondPos++))
    {
      return false;
    }
  }

  // All continuation bytes up to this position (if any) agree and 
  // at least one of the byteArrays has run out of continuation bytes.
  // The characters are equal if the current bytes are not
  // continuation bytes.
  return (((first[firstPos] & 0xc0) != 0x80)
  && ((second.get(secondPos) & 0xc0) != 0x80));
}
 
Example 6
Source File: DjVuText.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
private int getChar(
  Uint8Array byteArray,
  int    pos)
{
  int value = byteArray.get(pos++);
  if (value > 0 && (value >> 7) == 0)
    return value;

  switch(value & 0xc0)
  {
    case 0x80 :
      throw new IllegalStateException("Invalid UTF8");
    case 0x40 :
      return value;
    default :
      value = (value << 6) | (byteArray.get(pos++) & 0x7f);

      if((value & 0x800) == 0)
      {
        return value & 0x7ff;
      }

      value = (value << 6) | (byteArray.get(pos++) & 0x7f);

      if((value & 0x10000) == 0)
      {
        return value & 0xffff;
      }

      value = (value << 6) | (byteArray.get(pos++) & 0x7f);

      if((value & 0x200000) == 0)
      {
        return value & 0x1fffff;
      }

      value = (value << 6) | (byteArray.get(pos++) & 0x7f);

      if((value & 0x4000000) == 0)
      {
        return value & 0x3ffffff;
      }

      return (value << 6) | (byteArray.get(pos++) & 0x7f);
  }
}