Decode baseline and sequencal scan

@return
@throws IOException
545157
protected int decodeScan(int marker) throws IOException {

        try {
            while (marker != MarkerConstants.SOS) {
                readTables(marker);

                marker = nextMarker();

                if (marker == -1) {
                    return marker;
                }
            }
        } catch (JPEGMarkerException e) {
            // just ignore unknown marker
            return -1;
        }

        // Decode scan header
        int[] componentIndexes = readScanHeader();
        Component[] components = frameHeader.getComponents();

        // Calculate MCU size
        calculateMCUs(componentIndexes, components);

        try {
            int restartsLeft = restartInterval;
            in.resetBuffer();
            resetDecoder();
            HuffmanTable curDCTable;
            HuffmanTable curACTable;
            QuantizationTable curQTable;

            for (int m = 0; m < MCUsPerColumn * MCUsPerRow; m++) {
                // If support restart interval
                if (restartInterval > 0 && restartsLeft == 0) {
                    marker = nextMarker();

                    if (marker > MarkerConstants.RST7 || marker < MarkerConstants.RST0) {
                        return marker;
                    }

                    in.resetBuffer();
                    resetDecoder();

                    restartsLeft = restartInterval;
                }

                // Begin decode MCU
                for (int c = 0, index = 0, ctr = 0; c < blocksNumInMCU; c++) {
                    index = blocksInMCU[c];

                    if (c == 0) {
                        ctr = 0;
                    } else {
                        if (index == blocksInMCU[c - 1]) {
                            ctr++;
                        } else {
                            ctr = 0;
                        }
                    }

                    // Begin decode block
                    curACTable = components[index].acHuffTable;
                    curDCTable = components[index].dcHuffTable;
                    curQTable = components[index].qTable;

                    // init 0
                    for (int z = 0; z < DCTSIZE2; z++) {
                        singleBlockData[z] = 0;
                    }

                    int s = 0, r = 0;

                    // Decode DC
                    s = curDCTable.decode(in);
                    if (s > 0) {
                        r = (int) in.readBits(s);
                        s = curDCTable.extend(r, s);
                    }

                    preDC[index] = s = preDC[index] + s;
                    singleBlockData[0] = s;

                    // Decode AC
                    for (int k = 1;;) {
                        s = curACTable.decode(in);

                        r = s >> 4;
                        s = s & 15;

                        if (s == 0) {
                            if (r == 15) {
                                k += 16;
                                continue;
                            } else {
                                break;
                            }
                        } else {
                            k += r;

                            r = (int) in.readBits(s);
                            s = curACTable.extend(r, s);

                            // Output coefficient in natural (dezigzagged) order
                            singleBlockData[MarkerConstants.BLOCK_NATURAL_ORDER[k]] = s;

                            if (k >= 63) {
                                break;
                            } else {
                                k++;
                            }
                        }
                    }
                    // End decode block

                    if (fastIDCTMode) {
                        throw new UnsupportedOperationException("Not implemented yet");
                    } else {
                        inverseDCTCalculator.calculate(singleBlockData, 0, curQTable.getQ(), singleMCUData[index],
                                                       ctr * DCTSIZE2, components[index].getHorizonDCTScaledSize(),
                                                       components[index].getVerticaDCTScaledSize());

                    }
                }
                // End decode MCU

                writeMCU();

                restartsLeft--;
            }

            marker = nextMarker();
        } catch (JPEGMarkerException e) { // Unexpected marker occur
            marker = e.getMarker();
        } catch (EOFException e) {
            marker = -1;
        } catch (ArrayIndexOutOfBoundsException e) {
            // just ignore huffman decode error
            marker = -1;
            broken = true;
        }

        return marker;
    }
5851
public static byte[] decodeToBytes(CharSequence in) throws IOException{
		if(in == null) return null;
		ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length());
		decode(in, baos);
		return baos.toByteArray();
	}
860261
static CharSequence decode(final CharSequence s) {
    if (!contains(s, '%')) {
      return s.toString();
    }
    return decode0(s);
  }
581011
private static ByteBuffer decodePercentEncodedOctets(String s, int i, ByteBuffer bb) {
        if (bb == null) {
            bb = ByteBuffer.allocate(1);
        } else {
            bb.clear();
        }

        while (true) {
            // Decode the hex digits
            bb.put((byte) (decodeHex(s, i++) << 4 | decodeHex(s, i++)));

            // Finish if at the end of the string
            if (i == s.length()) {
                break;
            }

            // Finish if no more percent-encoded octets follow
            if (s.charAt(i++) != '%') {
                break;
            }

            // Check if the byte buffer needs to be increased in size
            if (bb.position() == bb.capacity()) {
                bb.flip();
                // Create a new byte buffer with the maximum number of possible
                // octets, hence resize should only occur once
                ByteBuffer bb_new = ByteBuffer.allocate(s.length() / 3);
                bb_new.put(bb);
                bb = bb_new;
            }
        }

        bb.flip();
        return bb;
    }
1314905
public static int decodeSequence(byte[] flakeBytes) {
        ByteBuffer buffer = ByteBuffer.allocate(16);
        buffer.put(flakeBytes);
        buffer.flip();
        buffer.getLong();
        return (int)(buffer.getLong() & 0x000000000000FFFF);
    }
1309979
@Override
    public int decode ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
        int len = super.decode(buffer, bufferIndex);
        if ( this.byteCount == 0 ) {
            // otherwise hasMore may not be correctly set
            readBytesWireFormat(buffer, len + bufferIndex);
        }
        nextElement();
        return len;
    }
794450
public static void decode(CharSequence in, Appendable out) throws IOException{
		decode(in, UTF_8, out);
	}
1326321
public byte[] decodeBinary() throws IOException {
		final int length = decodeUnsignedInteger();
		byte[] result = new byte[length];

		istream.read(result, 0, length);
		return result;
	}
1215082
@Override
    public int read() throws IOException {
        // initalize the lookahead
        if (lookaheadChar == UNDEFINED) {
            lookaheadChar = super.read();
        }
        lastChar = lookaheadChar;
        if (super.ready()) {
            lookaheadChar = super.read();
        } else {
            lookaheadChar = UNDEFINED;
        }
        if (lastChar == '\n') {
            lineCounter++;
        }
        return lastChar;
    }
685331
private boolean scanHeaders()
    throws IOException
  {
    int ch = read();
    long length = 0;

    _headers.clear();
    while (ch > 0 && ch != '\n' && ch != '\r') {
      _line.clear();

      _line.append((char) ch);
      for (ch = read();
           ch >= 0 && ch != '\n' && ch != '\r';
           ch = read()) {
        _line.append((char) ch);

        if (_maxLength < length++)
          throw new IOException(L.l("header length {0} exceeded.", _maxLength));
      }

      if (ch == '\r') {
        if ((ch = read()) == '\n')
          ch = read();
      }
      else if (ch == '\n')
        ch = read();

      int i = 0;
      for (; i < _line.length() && _line.charAt(i) != ':'; i++) {
      }

      String key = null;
      String value = null;
      if (i < _line.length()) {
        key = _line.substring(0, i).trim().toLowerCase(Locale.ENGLISH);
        value = _line.substring(i + 1).trim();

        List<String> values = _headers.get(key);

        if (values == null) {
          values = new ArrayList<>();
        }

        values.add(value);

        _headers.put(key, values);
      }
    }

    if (ch == '\r') {
      if ((ch = read()) != '\n') {
        _peek[0] = (byte) ch;
        _peekOffset = 0;
        _peekLength = 1;
      }
    }

    return true;
  }
1195408
public byte decodeBuffer(String inputString)[] throws IOException {
        byte    inputBuffer[] = new byte[inputString.length()];
        ByteArrayInputStream inStream;
        ByteArrayOutputStream outStream;

        inputString.getBytes(0, inputString.length(), inputBuffer, 0);
        inStream = new ByteArrayInputStream(inputBuffer);
        outStream = new ByteArrayOutputStream();
        decodeBuffer(inStream, outStream);
        return (outStream.toByteArray());
    }
171063
byte[] decodeLikeABoss(final byte[] input) {

        if (input == null) {
            throw new NullPointerException("input");
        }

        if ((input.length & 0x01) == 0x01) {
            throw new IllegalArgumentException(
                "input.length(" + input.length + ") is not even");
        }

        final byte[] output = new byte[input.length / 2];

        int index = 0; // index in input
        for (int i = 0; i < output.length; i++) {
            final String s = new String(
                input, index, 2, StandardCharsets.US_ASCII);
            output[i] = (byte) Integer.parseInt(s, 16);
            index += 2;
        }

        return output;
    }
538026
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.allocationSize = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.endOfFile = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.numberOfLinks = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.deletePending = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        this.directory = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        return bufferIndex - start;
    }
687192
int decode( byte[] buffer, int bufferIndex ) {
        int start = headerStart = bufferIndex;

        bufferIndex += readHeaderWireFormat( buffer, bufferIndex );
        bufferIndex += readAndXWireFormat( buffer, bufferIndex );

        length = bufferIndex - start;
        return length;
    }
1220038
@Override
    protected void decode(DataInputStream buffer) throws IOException
    {
        entityId = buffer.readShort();
        final int number = buffer.readByte();
        for (int i = 0; i < number; i++)
        {
            decode(buffer, i);
        }
    }
424824
public static ByteBuffer decode(String input) throws IOException {
		return decode(input.getBytes(StandardCharsets.US_ASCII));
	}
167154
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.replaceIfExists = buffer[ bufferIndex ] != 0;
        bufferIndex += 8;
        bufferIndex += 8;

        int nameLen = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        byte[] nameBytes = new byte[nameLen];
        System.arraycopy(buffer, bufferIndex, nameBytes, 0, nameBytes.length);
        bufferIndex += nameLen;
        this.fileName = new String(nameBytes, StandardCharsets.UTF_16LE);
        return bufferIndex - start;
    }