/*
We overload this because we want readAndXWireFormat to
read the parameter words and bytes. This is so when
commands are batched together we can recursivly call
readAndXWireFormat without reading the non-existent header.
349850
@Override
    public int decode ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
        int start = this.headerStart = bufferIndex;

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

        int len = bufferIndex - start;
        this.length = len;

        if ( isRetainPayload() ) {
            byte[] payload = new byte[len];
            System.arraycopy(buffer, 4, payload, 0, len);
            setRawPayload(payload);
        }

        if ( !verifySignature(buffer, 4, len) ) {
            throw new SMBProtocolDecodingException("Signature verification failed for " + this.getClass().getName());
        }
        return len;
    }
554378
@Override
    protected void parse() throws ProtocolException {
        cursor = offset;
        optimalEncodingMessageSize = 4;

        // version
        version = readUint32();
        // peek at marker
        byte marker = payload[cursor];
        boolean useSegwit = marker == 0;
        // marker, flag
        if (useSegwit) {
            readBytes(2);
            optimalEncodingMessageSize += 2;
        }
        // txin_count, txins
        parseInputs();
        // txout_count, txouts
        parseOutputs();
        // script_witnesses
        if (useSegwit)
            parseWitnesses();
        // lock_time
        lockTime = readUint32();
        optimalEncodingMessageSize += 4;

        length = cursor - offset;
    }
398618
@Override
    protected int readBytesWireFormat ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        int structureSize = SMBUtil.readInt2(buffer, bufferIndex);
        if ( structureSize != 60 ) {
            throw new SMBProtocolDecodingException("Expected structureSize = 60");
        }
        this.closeFlags = SMBUtil.readInt2(buffer, bufferIndex + 2);
        bufferIndex += 4;
        bufferIndex += 4; // Reserved
        this.creationTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.lastAccessTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.lastWriteTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.changeTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.allocationSize = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.endOfFile = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.fileAttributes = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;

        if ( log.isDebugEnabled() ) {
            log.debug(String.format("Closed %s (%s)", Hexdump.toHexString(this.fileId), this.fileName));
        }

        return bufferIndex - start;
    }
1349940
@Override
    protected int writeParameterWordsWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;

        SMBUtil.writeInt2(this.fid, dst, dstIndex);
        dstIndex += 2;

        dst[ dstIndex ] = this.typeOfLock;
        dst[ dstIndex + 1 ] = this.newOpLockLevel;
        dstIndex += 2;

        SMBUtil.writeInt4(this.timeout, dst, dstIndex);
        dstIndex += 4;

        SMBUtil.writeInt2(this.unlocks != null ? this.unlocks.length : 0, dst, dstIndex);
        dstIndex += 2;

        SMBUtil.writeInt2(this.locks != null ? this.locks.length : 0, dst, dstIndex);
        dstIndex += 2;
        return start - dstIndex;
    }
180656
private void defineReadStructMethod()
    {
        MethodDefinition read = new MethodDefinition(
                a(PUBLIC),
                "read",
                structType,
                arg("protocol", TProtocol.class)
        ).addException(Exception.class);

        // TProtocolReader reader = new TProtocolReader(protocol);
        read.addLocalVariable(type(TProtocolReader.class), "reader");
        read.newObject(TProtocolReader.class);
        read.dup();
        read.loadVariable("protocol");
        read.invokeConstructor(type(TProtocolReader.class), type(TProtocol.class));
        read.storeVariable("reader");

        // read all of the data in to local variables
        Map<Short, LocalVariableDefinition> structData = readFieldValues(read);

        // build the struct
        LocalVariableDefinition result = buildStruct(read, structData);

        // push instance on stack, and return it
        read.loadVariable(result).retObject();

        classDefinition.addMethod(read);
    }
741625
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(49, dst, dstIndex);
        dst[ dstIndex + 2 ] = this.padding;
        dst[ dstIndex + 3 ] = this.readFlags;
        dstIndex += 4;
        SMBUtil.writeInt4(this.readLength, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt8(this.offset, dst, dstIndex);
        dstIndex += 8;
        System.arraycopy(this.fileId, 0, dst, dstIndex, 16);
        dstIndex += 16;
        SMBUtil.writeInt4(this.minimumCount, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt4(this.channel, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt4(this.remainingBytes, dst, dstIndex);
        dstIndex += 4;

        // ReadChannelInfo
        SMBUtil.writeInt2(0, dst, dstIndex);
        SMBUtil.writeInt2(0, dst, dstIndex + 2);
        dstIndex += 4;

        // one byte in buffer must be zero
        dst[ dstIndex ] = 0;
        dstIndex += 1;

        return dstIndex - start;
    }
1109273
private void processParameters() throws BadElementException, IOException {
        type = IMGTEMPLATE;
        originalType = ORIGINAL_WMF;
        InputStream is = null;
        try {
            String errorID;
            if (rawData == null){
                is = url.openStream();
                errorID = url.toString();
            }
            else{
                is = new java.io.ByteArrayInputStream(rawData);
                errorID = "Byte array";
            }
            InputMeta in = new InputMeta(is);
            if (in.readInt() != 0x9AC6CDD7)	{
                throw new BadElementException(errorID + " is not a valid placeable windows metafile.");
            }
            in.readWord();
            int left = in.readShort();
            int top = in.readShort();
            int right = in.readShort();
            int bottom = in.readShort();
            int inch = in.readWord();
            dpiX = 72;
            dpiY = 72;
            scaledHeight = (float)(bottom - top) / inch * 72f;
            setTop(scaledHeight);
            scaledWidth = (float)(right - left) / inch * 72f;
            setRight(scaledWidth);
        }
        finally {
            if (is != null) {
                is.close();
            }
            plainWidth = getWidth();
            plainHeight = getHeight();
        }
    }
229607
protected boolean loadMore()
        throws XMLStreamException
    {
        WstxInputSource input = mInput;
        do {
            /* Need to make sure offsets are properly updated for error
             * reporting purposes, and do this now while previous amounts
             * are still known.
             */
            mCurrInputProcessed += mInputEnd;
            verifyLimit("Maximum document characters", mConfig.getMaxCharacters(), mCurrInputProcessed);
            mCurrInputRowStart -= mInputEnd;
            int count;
            try {
                count = input.readInto(this);
                if (count > 0) {
                    return true;
                }
                input.close();
            } catch (IOException ioe) {
                throw constructFromIOE(ioe);
            }
            if (input == mRootInput) {
                /* Note: no need to check entity/input nesting in this
                 * particular case, since it will be handled by higher level
                 * parsing code (results in an unexpected EOF)
                 */
                return false;
            }
            WstxInputSource parent = input.getParent();
            if (parent == null) { // sanity check!
                throwNullParent(input);
            }
            /* 13-Feb-2006, TSa: Ok, do we violate a proper nesting constraints
             *   with this input block closure?
             */
            if (mCurrDepth != input.getScopeId()) {
                handleIncompleteEntityProblem(input);
            }

            mInput = input = parent;
            input.restoreContext(this);
            mInputTopDepth = input.getScopeId();
            /* 21-Feb-2006, TSa: Since linefeed normalization needs to be
             *   suppressed for internal entity expansion, we may need to
             *   change the state...
             */
            if (!mNormalizeLFs) {
                mNormalizeLFs = !input.fromInternalEntity();
            }
            // Maybe there are leftovers from that input in buffer now?
        } while (mInputPtr >= mInputEnd);

        return true;
    }
166753
private void makeWiring(WebSphereBeanDeploymentArchive wireFromBda, WebSphereBeanDeploymentArchive wireToBda, ClassLoader wireToBdaCL, ClassLoader wireFromBdaCL) {
        while (wireFromBdaCL != null) {
            if (wireFromBdaCL == wireToBdaCL) {
                wireFromBda.addBeanDeploymentArchive(wireToBda);
                break;
            } else {
                wireFromBdaCL = wireFromBdaCL.getParent();
            }
        }
        //if we are here, it means the wireToBdaCL is root classloader, loading java.xx classes. All other bdas should be accessible to this new bda.
        if (wireFromBdaCL == wireToBdaCL) {
            wireFromBda.addBeanDeploymentArchive(wireToBda);
        }
    }
570139
protected int decodeMandatoryVariableParameters(ISUPParameterFactory parameterFactory, byte[] b, int index)
            throws ParameterException {
        // FIXME: possibly this should also be per msg, since if msg lacks
        // proper parameter, decoding wotn pick this up and will throw
        // some bad output, which wont give a clue about reason...
        int readCount = 0;
        // int optionalOffset = 0;

        if (b.length - index > 0) {

            byte extPIndex = -1;
            try {
                int count = getNumberOfMandatoryVariableLengthParameters();
                readCount = count;
                for (int parameterIndex = 0; parameterIndex < count; parameterIndex++) {
                    int lengthPointerIndex = index + parameterIndex;
                    int parameterLengthIndex = b[lengthPointerIndex] + lengthPointerIndex;

                    int parameterLength = b[parameterLengthIndex];
                    byte[] parameterBody = new byte[parameterLength];
                    System.arraycopy(b, parameterLengthIndex + 1, parameterBody, 0, parameterLength);
                    decodeMandatoryVariableBody(parameterFactory, parameterBody, parameterIndex);

                }

                // optionalOffset = b[index + readCount];
            } catch (ArrayIndexOutOfBoundsException aioobe) {
                throw new ParameterException(
                        "Failed to read parameter, to few octets in buffer, parameter index: " + extPIndex, aioobe);
            } catch (IllegalArgumentException e) {
                throw new ParameterException("Failed to parse, paramet index: " + extPIndex, e);
            }
        } else {
            throw new ParameterException(
                    "To few bytes to decode mandatory variable part. There should be atleast on byte to indicate optional part.");
        }

        // return readCount + optionalOffset;
        return readCount;
    }
595752
@Override
    public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
        internalStmt.setBinaryStream(parameterIndex, x);
    }
366959
@Override
  public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);

    isPruned = in.readBoolean();
    size = in.readVInt();
    termsEncoding = TermsByQueryRequest.TermsEncoding.values()[in.readVInt()];
    encodedTerms = in.readBytesRef();
  }
816910
@Override
	public void channelRead0(ChannelHandlerContext ctx, RoutedRequest routedRequest) throws Exception {
		String requestPath = routedRequest.getPath();

		respondWithFile(ctx, routedRequest.getRequest(), requestPath);
	}
312909
@Override
    public void readFragmentFrom(MwsReader r) {
        currencyCode = r.read("CurrencyCode", String.class);
        amount = r.read("Amount", String.class);
    }
614411
@Override
    public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
        final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
        ic.deploymentName = null;
        ic.serverGroup = null;
        String deploymentName = name.getValue(parsedCmd);
        if (name != null) {
            ic.deploymentName = deploymentName;
        }
        ic.serverGroup = serverGroup.getValue(parsedCmd);
        return ic.buildRequest(ctx);
    }
254379
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        SMBUtil.writeInt2(4, dst, dstIndex);
        SMBUtil.writeInt2(0, dst, dstIndex + 2);
        return 4;
    }
1134648
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(24, dst, dstIndex);
        SMBUtil.writeInt2(this.closeFlags, dst, dstIndex + 2);
        dstIndex += 4;
        dstIndex += 4; // Reserved
        System.arraycopy(this.fileId, 0, dst, dstIndex, 16);
        dstIndex += 16;

        if ( log.isDebugEnabled() ) {
            log.debug(String.format("Closing %s (%s)", Hexdump.toHexString(this.fileId), this.fileName));
        }
        return dstIndex - start;
    }