private boolean doScan() throws SoapEnvelopeNotFoundException {
        xmlPreamble.startIdx = xmlPreamble.endIdx = -1;
        envelopeDecl.startIdx = envelopeDecl.endIdx = -1;
        headers.startIdx = headers.endIdx = -1;
        
        int currentIdx = 0;
        while (currentIdx < buffer.length()) {
            byte currentByte = buffer.get(currentIdx);
            if (currentByte == (byte) '<') {
                if (xmlPreamble.startIdx == -1 && isPreamble(currentIdx)) {
                    currentIdx = consumePreamble(currentIdx);
                } else if (envelopeDecl.startIdx == -1) {
                    currentIdx = consumeEnvelopeDecl(currentIdx);
                    if (currentIdx == -1) {
                        throw new SoapEnvelopeNotFoundException();
                    }
                } else {
                    currentIdx = consumeHeaders(currentIdx);
                    if (currentIdx == -1) {
                        throw new SoapEnvelopeNotFoundException();
                    }
                }
            } else {
                currentIdx++;
            }
            
            if (headers.endIdx != -1) {
                return true;
            }
        }
        
        return false;
    }
@return true if the scan found what it was looking for, false if more data is needed
gateway/engine/core/src/main/java/io/apiman/gateway/engine/soap/SoapHeaderScanner.java