Determines the encoding block groups for the specified data.
325517
private static List< Block > createBlocks(int[] data, boolean debug) {

        List< Block > blocks = new ArrayList<>();
        Block current = null;

        for (int i = 0; i < data.length; i++) {
            EncodingMode mode = chooseMode(data[i]);
            if ((current != null && current.mode == mode) &&
                (mode != EncodingMode.NUM || current.length < MAX_NUMERIC_COMPACTION_BLOCK_SIZE)) {
                current.length++;
            } else {
                current = new Block(mode);
                blocks.add(current);
            }
        }

        if (debug) {
            System.out.println("Initial block pattern: " + blocks);
        }

        smoothBlocks(blocks);

        if (debug) {
            System.out.println("Final block pattern: " + blocks);
        }

        return blocks;
    }
142829
private String getCommaSeperatedIndexes(Set<String> data) {

        Iterator<String> it = data.iterator();
        String res = it.next();
        if (data.size() == 1) {
            return res;
        }
        res += ", ";
        while (it.hasNext()) {
            res += it.next() + ", ";
        }
        res = res.substring(0, res.length() - 2);
        return res;
    }
1329773
public byte[] convertBlock(int[] input, int inPos, byte[] output, int numOfComponents, int startCoordinate,
                               int row, int scanlineStride) {
        int index = 0, inputOffset = 0, bounds = 0;
        int len = output.length;

        for (int i = 0; i < DCTSIZE; i++) {
            index = startCoordinate + i * scanlineStride;
            bounds = row * scanlineStride;

            for (int j = 0; j < DCTSIZE; j++) {
                if (index >= len) {
                    return output;
                }

                if (index < bounds) {
                    for (int c = 0; c < numOfComponents; c++) {
                        output[index++] = (byte) (255 - (input[inputOffset++] & 0xFF));
                    }
                } else {
                    inputOffset += numOfComponents;
                }
            }

            row++;
        }

        return output;
    }
300497
def detect_encoding(value):
    """"""
    # https://tools.ietf.org/html/rfc4627#section-3
    if six.PY2:
        null_pattern = tuple(bool(ord(char)) for char in value[:4])
    else:
        null_pattern = tuple(bool(char) for char in value[:4])

    encodings = {
        # Zero is a null-byte, 1 is anything else.
        (0, 0, 0, 1): 'utf-32-be',
        (0, 1, 0, 1): 'utf-16-be',
        (1, 0, 0, 0): 'utf-32-le',
        (1, 0, 1, 0): 'utf-16-le',
    }

    return encodings.get(null_pattern, 'utf-8')
585305
private static int readDataBlock(String text, int offset, int length, List<byte[]> blocks)
   {
      int bytes = length / 2;
      byte[] data = new byte[bytes];

      for (int index = 0; index < bytes; index++)
      {
         data[index] = (byte) Integer.parseInt(text.substring(offset, offset + 2), 16);
         offset += 2;
      }

      blocks.add(data);
      return (offset);
   }
182583
def auto_decode(data):
    # type: (bytes) -> Text
    """"""
    for bom, encoding in BOMS:
        if data.startswith(bom):
            return data[len(bom):].decode(encoding)
    # Lets check the first two lines as in PEP263
    for line in data.split(b'\n')[:2]:
        if line[0:1] == b'#' and ENCODING_RE.search(line):
            encoding = ENCODING_RE.search(line).groups()[0].decode('ascii')
            return data.decode(encoding)
    return data.decode(
        locale.getpreferredencoding(False) or sys.getdefaultencoding(),
    )
53536
def evaluate_block(self, groups):
        """"""

        if self.blocks:
            self.block_comments.append([groups['block'][2:-2], self.line_num, self.current_encoding])
862159
@NonNull
    private String determineEncoding(HttpRequest request) {
        MediaType mimeType = request.getContentType();
        if (mimeType == null) return Charsets.UTF_8.name();
        Charset charset = mimeType.getCharset();
        return charset == null ? Charsets.UTF_8.name() : charset.name();
    }
33212
public static String decodeBZ(byte[] data) {
    try {
      return new String(decodeBZRaw(data), "UTF-8");
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
180199
def chunk_encoding(chunks, chunk):
    '''
    '''
    chunks.extend(("%X\r\n" % len(chunk)).encode('utf-8'))
    chunks.extend(chunk)
    chunks.extend(CRLF)
947172
private static void smoothBlocks(List< Block > blocks) {

        for (int i = 0; i < blocks.size(); i++) {
            Block block = blocks.get(i);
            EncodingMode last = (i > 0 ? blocks.get(i - 1).mode : EncodingMode.FALSE);
            EncodingMode next = (i < blocks.size() - 1 ? blocks.get(i + 1).mode : EncodingMode.FALSE);
            if (block.mode == EncodingMode.NUM) {
                if (i == 0) { /* first block */
                    if (next == EncodingMode.TEX && block.length < 8) {
                        block.mode = EncodingMode.TEX;
                    } else if (next == EncodingMode.BYT && block.length == 1) {
                        block.mode = EncodingMode.BYT;
                    }
                } else if (i == blocks.size() - 1) { /* last block */
                    if (last == EncodingMode.TEX && block.length < 7) {
                        block.mode = EncodingMode.TEX;
                    } else if (last == EncodingMode.BYT && block.length == 1) {
                        block.mode = EncodingMode.BYT;
                    }
                } else { /* not first or last block */
                    if (last == EncodingMode.BYT && next == EncodingMode.BYT && block.length < 4) {
                        block.mode = EncodingMode.BYT;
                    } else if (last == EncodingMode.BYT && next == EncodingMode.TEX && block.length < 4) {
                        block.mode = EncodingMode.TEX;
                    } else if (last == EncodingMode.TEX && next == EncodingMode.BYT && block.length < 5) {
                        block.mode = EncodingMode.TEX;
                    } else if (last == EncodingMode.TEX && next == EncodingMode.TEX && block.length < 8) {
                        block.mode = EncodingMode.TEX;
                    } else if (last == EncodingMode.NUM && next == EncodingMode.TEX && block.length < 8) {
                        block.mode = EncodingMode.TEX;
                    }
                }
            }
        }

        mergeBlocks(blocks);

        for (int i = 0; i < blocks.size(); i++) {
            Block block = blocks.get(i);
            EncodingMode last = (i > 0 ? blocks.get(i - 1).mode : EncodingMode.FALSE);
            EncodingMode next = (i < blocks.size() - 1 ? blocks.get(i + 1).mode : EncodingMode.FALSE);
            if (block.mode == EncodingMode.TEX && i > 0) { /* not the first */
                if (i == blocks.size() - 1) { /* the last one */
                    if (last == EncodingMode.BYT && block.length == 1) {
                        block.mode = EncodingMode.BYT;
                    }
                } else { /* not the last one */
                    if (last == EncodingMode.BYT && next == EncodingMode.BYT && block.length < 5) {
                        block.mode = EncodingMode.BYT;
                    }
                    if (((last == EncodingMode.BYT && next != EncodingMode.BYT) ||
                         (last != EncodingMode.BYT && next == EncodingMode.BYT)) && (block.length < 3)) {
                        block.mode = EncodingMode.BYT;
                    }
                }
            }
        }

        mergeBlocks(blocks);
    }
469646
public static byte[] encodeBZ(byte[] data) {
    try {
      int blockSize = 4;
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      BZip2CompressorOutputStream compresser = new BZip2CompressorOutputStream(output, blockSize);
      compresser.write(data);
      compresser.close();
      byte[] bytes = output.toByteArray();
      return bytes;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
949051
private void createHuffmanDecodingTables(final int alphaSize,
      final int nGroups) {
    final Data dataShadow = this.data;
    final char[][] len = dataShadow.temp_charArray2d;
    final int[] minLens = dataShadow.minLens;
    final int[][] limit = dataShadow.limit;
    final int[][] base = dataShadow.base;
    final int[][] perm = dataShadow.perm;

    for (int t = 0; t < nGroups; t++) {
      int minLen = 32;
      int maxLen = 0;
      final char[] len_t = len[t];
      for (int i = alphaSize; --i >= 0;) {
        final char lent = len_t[i];
        if (lent > maxLen) {
          maxLen = lent;
        }
        if (lent < minLen) {
          minLen = lent;
        }
      }
      hbCreateDecodeTables(limit[t], base[t], perm[t], len[t], minLen,
          maxLen, alphaSize);
      minLens[t] = minLen;
    }
  }
1351013
def _byte_encode(self, token):
    """"""
    # Vocab ids for all bytes follow ids for the subwords
    offset = len(self._subwords)
    if token == "_":
      return [len(self._subwords) + ord(" ")]
    return [i + offset for i in list(bytearray(tf.compat.as_bytes(token)))]
670974
private static byte[] decodeInternal(byte[] data)
    {
        int tail = data.length;
        while (data[tail-1] == '=')  tail--;
        byte dest[] = new byte[tail - data.length/4];

        // ascii printable to 0-63 conversion
        for (int idx = 0; idx <data.length; idx++)
        {
            if (data[idx] == '=')    data[idx] = 0;
            else if (data[idx] == '/') data[idx] = 63;
            else if (data[idx] == '+') data[idx] = 62;
            else if (data[idx] >= '0'  &&  data[idx] <= '9')
                data[idx] = (byte)(data[idx] - ('0' - 52));
            else if (data[idx] >= 'a'  &&  data[idx] <= 'z')
                data[idx] = (byte)(data[idx] - ('a' - 26));
            else if (data[idx] >= 'A'  &&  data[idx] <= 'Z')
                data[idx] = (byte)(data[idx] - 'A');
        }

        // 4-byte to 3-byte conversion
        int sidx, didx;
        for (sidx = 0, didx=0; didx < dest.length-2; sidx += 4, didx += 3)
        {
            dest[didx]   = (byte) ( ((data[sidx] << 2) & 255) |
                    ((data[sidx+1] >>> 4) & 3) );
            dest[didx+1] = (byte) ( ((data[sidx+1] << 4) & 255) |
                    ((data[sidx+2] >>> 2) & 017) );
            dest[didx+2] = (byte) ( ((data[sidx+2] << 6) & 255) |
                    (data[sidx+3] & 077) );
        }
        if (didx < dest.length)
        {
            dest[didx]   = (byte) ( ((data[sidx] << 2) & 255) |
                    ((data[sidx+1] >>> 4) & 3) );
        }
        if (++didx < dest.length)
        {
            dest[didx]   = (byte) ( ((data[sidx+1] << 4) & 255) |
                    ((data[sidx+2] >>> 2) & 017) );
        }
        return dest;
    }
910466
def toUnicode(data, encoding=DEFAULT_ENCODING):
    
    if isinstance(data, unicode_type):
        return data

    if isinstance(data, bytes_type):
        return unicode_type(data, encoding=encoding)

    if hasattr(data, '__iter__'):
        try:
            dict(data)
        except TypeError:
            pass
        except ValueError:
            return (toUnicode(i, encoding) for i in data)
        else:
            if hasattr(data, 'items'):
                data = data.items()

            return dict(((toUnicode(k, encoding), toUnicode(v, encoding)) for k, v in data))
    return data
543867
function makeEncoding($height = 0, $width = 0, $data = 0, $fw = 0, $bytes = 0, $datablocks = 0, $rsblocks = 0) {
        $t = array(
            'height' => $height,
            'width' => $width,
            'data' => $data,
            'fw' => $fw,
            'bytes' => $bytes,
            'datablocks' => $datablocks,
            'rsblocks' => $rsblocks
        );
        return $t;
    }