Java Code Examples for com.google.zxing.common.BitSource#getByteOffset()

The following examples show how to use com.google.zxing.common.BitSource#getByteOffset() . These examples are extracted from open source projects. 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
/**
 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
 */
private static void decodeBase256Segment(BitSource bits,
                                         StringBuilder result,
                                         Collection<byte[]> byteSegments)
    throws FormatException {
  // Figure out how long the Base 256 Segment is.
  int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
  int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
  int count;
  if (d1 == 0) {  // Read the remainder of the symbol
    count = bits.available() / 8;
  } else if (d1 < 250) {
    count = d1;
  } else {
    count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
  }

  // We're seeing NegativeArraySizeException errors from users.
  if (count < 0) {
    throw FormatException.getFormatInstance();
  }

  byte[] bytes = new byte[count];
  for (int i = 0; i < count; i++) {
    // Have seen this particular error in the wild, such as at
    // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
    if (bits.available() < 8) {
      throw FormatException.getFormatInstance();
    }
    bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
  }
  byteSegments.add(bytes);
  try {
    result.append(new String(bytes, "ISO8859_1"));
  } catch (UnsupportedEncodingException uee) {
    throw new IllegalStateException("Platform does not support required encoding: " + uee);
  }
}
 
Example 2
/**
 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
 */
private static void decodeBase256Segment(BitSource bits,
                                         StringBuilder result,
                                         Collection<byte[]> byteSegments)
    throws FormatException {
  // Figure out how long the Base 256 Segment is.
  int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
  int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
  int count;
  if (d1 == 0) {  // Read the remainder of the symbol
    count = bits.available() / 8;
  } else if (d1 < 250) {
    count = d1;
  } else {
    count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
  }

  // We're seeing NegativeArraySizeException errors from users.
  if (count < 0) {
    throw FormatException.getFormatInstance();
  }

  byte[] bytes = new byte[count];
  for (int i = 0; i < count; i++) {
    // Have seen this particular error in the wild, such as at
    // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
    if (bits.available() < 8) {
      throw FormatException.getFormatInstance();
    }
    bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
  }
  byteSegments.add(bytes);
  try {
    result.append(new String(bytes, "ISO8859_1"));
  } catch (UnsupportedEncodingException uee) {
    throw new IllegalStateException("Platform does not support required encoding: " + uee);
  }
}
 
Example 3
Source Project: weex   File: DecodedBitStreamParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
 */
private static void decodeBase256Segment(BitSource bits,
                                         StringBuilder result,
                                         Collection<byte[]> byteSegments)
    throws FormatException {
  // Figure out how long the Base 256 Segment is.
  int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
  int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
  int count;
  if (d1 == 0) {  // Read the remainder of the symbol
    count = bits.available() / 8;
  } else if (d1 < 250) {
    count = d1;
  } else {
    count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
  }

  // We're seeing NegativeArraySizeException errors from users.
  if (count < 0) {
    throw FormatException.getFormatInstance();
  }

  byte[] bytes = new byte[count];
  for (int i = 0; i < count; i++) {
    // Have seen this particular error in the wild, such as at
    // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
    if (bits.available() < 8) {
      throw FormatException.getFormatInstance();
    }
    bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
  }
  byteSegments.add(bytes);
  try {
    result.append(new String(bytes, "ISO8859_1"));
  } catch (UnsupportedEncodingException uee) {
    throw new IllegalStateException("Platform does not support required encoding: " + uee);
  }
}
 
Example 4
/**
 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
 */
private static void decodeBase256Segment(BitSource bits,
                                         StringBuilder result,
                                         Collection<byte[]> byteSegments)
    throws FormatException {
  // Figure out how long the Base 256 Segment is.
  int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
  int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
  int count;
  if (d1 == 0) {  // Read the remainder of the symbol
    count = bits.available() / 8;
  } else if (d1 < 250) {
    count = d1;
  } else {
    count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
  }

  // We're seeing NegativeArraySizeException errors from users.
  if (count < 0) {
    throw FormatException.getFormatInstance();
  }

  byte[] bytes = new byte[count];
  for (int i = 0; i < count; i++) {
    // Have seen this particular error in the wild, such as at
    // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
    if (bits.available() < 8) {
      throw FormatException.getFormatInstance();
    }
    bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
  }
  byteSegments.add(bytes);
  try {
    result.append(new String(bytes, "ISO8859_1"));
  } catch (UnsupportedEncodingException uee) {
    throw new IllegalStateException("Platform does not support required encoding: " + uee);
  }
}
 
Example 5
Source Project: reacteu-app   File: DecodedBitStreamParser.java    License: MIT License 5 votes vote down vote up
/**
 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
 */
private static void decodeBase256Segment(BitSource bits,
                                         StringBuilder result,
                                         Collection<byte[]> byteSegments)
    throws FormatException {
  // Figure out how long the Base 256 Segment is.
  int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
  int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
  int count;
  if (d1 == 0) {  // Read the remainder of the symbol
    count = bits.available() / 8;
  } else if (d1 < 250) {
    count = d1;
  } else {
    count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
  }

  // We're seeing NegativeArraySizeException errors from users.
  if (count < 0) {
    throw FormatException.getFormatInstance();
  }

  byte[] bytes = new byte[count];
  for (int i = 0; i < count; i++) {
    // Have seen this particular error in the wild, such as at
    // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
    if (bits.available() < 8) {
      throw FormatException.getFormatInstance();
    }
    bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
  }
  byteSegments.add(bytes);
  try {
    result.append(new String(bytes, "ISO8859_1"));
  } catch (UnsupportedEncodingException uee) {
    throw new IllegalStateException("Platform does not support required encoding: " + uee);
  }
}
 
Example 6
/**
 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
 */
private static void decodeBase256Segment(BitSource bits, StringBuilder result, Collection<byte[]> byteSegments)
		throws FormatException {
	// Figure out how long the Base 256 Segment is.
	int codewordPosition = 1 + bits.getByteOffset(); // position is
														// 1-indexed
	int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
	int count;
	if (d1 == 0) { // Read the remainder of the symbol
		count = bits.available() / 8;
	} else if (d1 < 250) {
		count = d1;
	} else {
		count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
	}

	// We're seeing NegativeArraySizeException errors from users.
	if (count < 0) {
		throw FormatException.getFormatInstance();
	}

	byte[] bytes = new byte[count];
	for (int i = 0; i < count; i++) {
		// Have seen this particular error in the wild, such as at
		// http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
		if (bits.available() < 8) {
			throw FormatException.getFormatInstance();
		}
		bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
	}
	byteSegments.add(bytes);
	try {
		result.append(new String(bytes, "ISO8859_1"));
	} catch (UnsupportedEncodingException uee) {
		throw new IllegalStateException("Platform does not support required encoding: " + uee);
	}
}
 
Example 7
Source Project: MiBandDecompiled   File: c.java    License: Apache License 2.0 4 votes vote down vote up
private static void a(BitSource bitsource, StringBuilder stringbuilder, Collection collection)
{
    int i = 1 + bitsource.getByteOffset();
    int j = bitsource.readBits(8);
    int k = i + 1;
    int l = a(j, i);
    int l1;
    if (l == 0)
    {
        l1 = bitsource.available() / 8;
    } else
    if (l < 250)
    {
        l1 = l;
    } else
    {
        int i1 = 250 * (l - 249);
        int j1 = bitsource.readBits(8);
        int k1 = k + 1;
        l1 = i1 + a(j1, k);
        k = k1;
    }
    if (l1 < 0)
    {
        throw FormatException.getFormatInstance();
    }
    byte abyte0[] = new byte[l1];
    for (int i2 = 0; i2 < l1;)
    {
        if (bitsource.available() < 8)
        {
            throw FormatException.getFormatInstance();
        }
        int j2 = bitsource.readBits(8);
        int k2 = k + 1;
        abyte0[i2] = (byte)a(j2, k);
        i2++;
        k = k2;
    }

    collection.add(abyte0);
    try
    {
        stringbuilder.append(new String(abyte0, "ISO8859_1"));
        return;
    }
    catch (UnsupportedEncodingException unsupportedencodingexception)
    {
        throw new IllegalStateException((new StringBuilder()).append("Platform does not support required encoding: ").append(unsupportedencodingexception).toString());
    }
}