Marshall the first line.

@return WsByteBuffer[] of line ready to be written.
177041
public WsByteBuffer[] marshallLine() {
        final boolean bTrace = TraceComponent.isAnyTracingEnabled();
        if (bTrace && tc.isEntryEnabled()) {
            Tr.entry(tc, "marshallLine");
        }

        WsByteBuffer[] firstLine = new WsByteBuffer[1];
        firstLine[0] = allocateBuffer(getOutgoingBufferSize());
        firstLine = putBytes(getMarshalledFirstToken(), firstLine);
        firstLine = putByte(BNFHeaders.SPACE, firstLine);
        firstLine = putBytes(getMarshalledSecondToken(), firstLine);
        firstLine = putByte(BNFHeaders.SPACE, firstLine);
        firstLine = putBytes(getMarshalledThirdToken(), firstLine);
        firstLine = putBytes(BNFHeaders.EOL, firstLine);

        // don't flip the last buffer as headers get tacked on the end

        if (bTrace && tc.isEntryEnabled()) {
            Tr.exit(tc, "marshallLine");
        }
        return firstLine;
    }
109255
public function getLines()
    {
        $lines = explode(PHP_EOL, $this->comment);

        $wrapper = function($line)
        {
            return new Line($line);
        };

        return array_map($wrapper, $lines);
    }
696183
public synchronized byte[] getBuffer() {
        byte[] dest = new byte[buf.length];
        System.arraycopy(buf, 0, dest, 0, dest.length);
        return dest;
    }
665752
public ObjectManagerByteArrayOutputStream[] getBuffers(ObjectManagerByteArrayOutputStream byteArrayOutputStream)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "getBuffers");

        ObjectManagerByteArrayOutputStream[] buffers = new ObjectManagerByteArrayOutputStream[1
                                                                                              + (tokensToAdd.size()) * 2
                                                                                              + (tokensToOptimisticReplace.size()) * 2
                                                                                              + (tokensToDelete.size())
                                                                                              + (tokensToNotify.size())];

        int bufferIndex = 0; // The next buffer to use.

        // Create the buffer to contain the header for this log record.
        byteArrayOutputStream.reset();
        buffers[bufferIndex++] = byteArrayOutputStream;
        java.io.DataOutputStream dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);
        try {
            dataOutputStream.writeInt(LogRecord.TYPE_OPTIMISTIC_REPLACE);
            dataOutputStream.writeInt(tokensToAdd.size());
            dataOutputStream.writeInt(tokensToOptimisticReplace.size());
            dataOutputStream.writeInt(tokensToDelete.size());
            dataOutputStream.writeInt(tokensToNotify.size());
            logicalUnitOfWork.writeObject(dataOutputStream);
            dataOutputStream.writeInt(transactionState);

        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, "getBuffers", exception, "1:228:1.11");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           "getBuffers"
                           , exception);
            throw new PermanentIOException(this,
                                           exception);
        } // catch.

        java.util.Iterator serializedObjectIterator = serializedManagedObjectBytes.iterator();

        //  Create the buffers containing the serialized ManagedObjects to add.
        for (int i = 0; i < tokensToAdd.size(); i++) {
            byteArrayOutputStream = new ObjectManagerByteArrayOutputStream((int) Token.maximumSerializedSize() + 4);
            dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);
            ((Token) tokensToAdd.get(i)).writeObject(dataOutputStream);

            ObjectManagerByteArrayOutputStream managedObjectBytes = (ObjectManagerByteArrayOutputStream) serializedObjectIterator.next();
            try {
                dataOutputStream.writeInt(managedObjectBytes.getCount());

            } catch (java.io.IOException exception) {
                // No FFDC Code Needed.
                ObjectManager.ffdc.processException(this, cclass, "getBuffers", exception, "1:253:1.11");

                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                    trace.exit(this,
                               cclass,
                               "getBuffers",
                               exception);
                throw new PermanentIOException(this,
                                               exception);
            } // catch.
            buffers[bufferIndex++] = byteArrayOutputStream;

            // Now add a buffer containing the serialzed ManagedObject itself.
            buffers[bufferIndex++] = managedObjectBytes;
        } // for tokensToOptimisticAdd.size().

        // Create the buffers containing the serialized ManagedObjects to optimistic replace.
        for (int i = 0; i < tokensToOptimisticReplace.size(); i++) {
            byteArrayOutputStream = new ObjectManagerByteArrayOutputStream((int) Token.maximumSerializedSize() + 4);
            dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);

            ((Token) tokensToOptimisticReplace.get(i)).writeObject(dataOutputStream);

            ObjectManagerByteArrayOutputStream managedObjectBytes = (ObjectManagerByteArrayOutputStream) serializedObjectIterator.next();
            try {
                dataOutputStream.writeInt(managedObjectBytes.getCount());

            } catch (java.io.IOException exception) {
                // No FFDC Code Needed.
                ObjectManager.ffdc.processException(this, cclass, "getBuffers", exception, "1:282:1.11");

                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                    trace.exit(this,
                               cclass,
                               "getBuffers",
                               exception);
                throw new PermanentIOException(this,
                                               exception);
            } // catch.
            buffers[bufferIndex++] = byteArrayOutputStream;

            // Now add a buffer containing the serialzed ManagedObject itself.
            buffers[bufferIndex++] = managedObjectBytes;
        } // for tokensToOptimisticReplace.size().

        // Create the buffers containing the Tokens to delete.
        for (int i = 0; i < tokensToDelete.size(); i++) {
            byteArrayOutputStream = new ObjectManagerByteArrayOutputStream((int) Token.maximumSerializedSize());
            dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);
            ((Token) tokensToDelete.get(i)).writeObject(dataOutputStream);
            buffers[bufferIndex++] = byteArrayOutputStream;
        } // for tokensToDelete.size().

        // Create the buffers containing the Tokens to notify.
        for (int i = 0; i < tokensToNotify.size(); i++) {
            byteArrayOutputStream = new ObjectManagerByteArrayOutputStream((int) Token.maximumSerializedSize());
            dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);
            ((Token) tokensToNotify.get(i)).writeObject(dataOutputStream);
            buffers[bufferIndex++] = byteArrayOutputStream;
        } // for tokensToNotify.size().

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "getBuffers",
                       "return=" + buffers);
        return buffers;
    }
786534
public function first()
    {
        foreach ($this as $result) {
            if ($this->_statement && !$this->_useBuffering) {
                $this->_statement->closeCursor();
            }

            return $result;
        }
    }
147418
public ByteBuffer preProcessOneWriteBuffer() {
        // We can process the single buffer case more efficiently than if we
        // include it as a part of the multi-buffer logic
        WsByteBufferImpl wsBuffImpl = null;
        try {
            wsBuffImpl = (WsByteBufferImpl) getBuffer();
        } catch (ClassCastException cce) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Writing with a non-WsByteBufferImpl");
            }
            return getBuffer().getWrappedByteBuffer();
        }

        if (!wsBuffImpl.isDirect() && wsBuffImpl.hasArray()) {
            wsBuffImpl.copyToDirectBuffer();
            return wsBuffImpl.oWsBBDirect;
        }
        return wsBuffImpl.getWrappedByteBufferNonSafe();
    }
1138996
public function getStreamContentStartOffset()
    {
        if ($this->parent) {
            return $this->streamContentStartPos - $this->parent->streamPartStartPos;
        }
        return $this->streamContentStartPos;
    }
586211
public char[] getSmallCBuffer(int minSize)
    {
        char[] result = null;
        if (mSmallCBuffer != null && mSmallCBuffer.length >= minSize) {
            result = mSmallCBuffer;
            mSmallCBuffer = null;
        }
//System.err.println("DEBUG: Alloc CSmall: "+result);
        return result;
    }
1162247
public function startOfLine()
    {
        if (false === strpos($this->prefixes, '^')) {
            $this->prefixes = '^' . $this->prefixes;
        }

        return $this;
    }
1374340
public byte[] getBuffer() {
        if(buf == null)
            return null;
        if(offset == 0 && length == buf.length)
            return buf;
        else {
            byte[] retval=new byte[length];
            System.arraycopy(buf, offset, retval, 0, length);
            return retval;
        }
    }
900512
public static WsByteBuffer[] expandBufferArray(WsByteBuffer[] oldList, WsByteBuffer[] newBuffers) {
        if (null == oldList && null == newBuffers) {
            // if both are null then just exit
            return null;
        }

        int oldLen = (null != oldList ? oldList.length : 0);
        int newLen = (null != newBuffers ? newBuffers.length : 0);
        WsByteBuffer[] bb = new WsByteBuffer[oldLen + newLen];
        if (0 < oldLen) {
            System.arraycopy(oldList, 0, bb, 0, oldLen);
        }
        if (0 < newLen) {
            System.arraycopy(newBuffers, 0, bb, oldLen, newLen);
        }
        return bb;
    }
811900
public static WsByteBuffer[] expandBufferArray(WsByteBuffer[] list, WsByteBuffer buffer) {
        if (null == buffer)
            return list;
        int len = (null != list ? list.length : 0);
        WsByteBuffer[] bb = new WsByteBuffer[len + 1];
        if (0 < len) {
            System.arraycopy(list, 0, bb, 0, len);
        }
        bb[len] = buffer;
        return bb;
    }
1134482
protected float[] findLimitsTwoLines() {
        boolean repeat = false;
        for (;;) {
            if (repeat && currentLeading == 0)
                return null;
            repeat = true;
            float x1[] = findLimitsOneLine();
            if (lineStatus == LINE_STATUS_OFFLIMITS)
                return null;
            yLine -= currentLeading;
            if (lineStatus == LINE_STATUS_NOLINE) {
                continue;
            }
            float x2[] = findLimitsOneLine();
            if (lineStatus == LINE_STATUS_OFFLIMITS)
                return null;
            if (lineStatus == LINE_STATUS_NOLINE) {
                yLine -= currentLeading;
                continue;
            }
            if (x1[0] >= x2[1] || x2[0] >= x1[1])
                continue;
            return new float[]{x1[0], x1[1], x2[0], x2[1]};
        }
    }
88032
public function first()
    {
        $this->throwExceptionIfEmpty();

        $keys = $this->keys();
        $keyOfTheFirstElement = $keys->shift();
        return $this->offsetGet($keyOfTheFirstElement);
    }
319094
protected function write()
    {
        if (!isset($this->pipes[0])) {
            return;
        }
        $input = $this->input;

        if ($input instanceof \Iterator) {
            if (!$input->valid()) {
                $input = null;
            } elseif (is_resource($input = $input->current())) {
                stream_set_blocking($input, 0);
            } elseif (!isset($this->inputBuffer[0])) {
                if (!is_string($input)) {
                    if (!is_scalar($input)) {
                        throw new InvalidArgumentException(sprintf('%s yielded a value of type "%s", but only scalars and stream resources are supported', get_class($this->input), gettype($input)));
                    }
                    $input = (string) $input;
                }
                $this->inputBuffer = $input;
                $this->input->next();
                $input = null;
            } else {
                $input = null;
            }
        }

        $r = $e = array();
        $w = array($this->pipes[0]);

        // let's have a look if something changed in streams
        if (false === $n = @stream_select($r, $w, $e, 0, 0)) {
            return;
        }

        foreach ($w as $stdin) {
            if (isset($this->inputBuffer[0])) {
                $written = fwrite($stdin, $this->inputBuffer);
                $this->inputBuffer = substr($this->inputBuffer, $written);
                if (isset($this->inputBuffer[0])) {
                    return array($this->pipes[0]);
                }
            }

            if ($input) {
                for (;;) {
                    $data = fread($input, self::CHUNK_SIZE);
                    if (!isset($data[0])) {
                        break;
                    }
                    $written = fwrite($stdin, $data);
                    $data = substr($data, $written);
                    if (isset($data[0])) {
                        $this->inputBuffer = $data;

                        return array($this->pipes[0]);
                    }
                }
                if (feof($input)) {
                    if ($this->input instanceof \Iterator) {
                        $this->input->next();
                    } else {
                        $this->input = null;
                    }
                }
            }
        }

        // no input to read on resource, buffer is empty
        if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) {
            $this->input = null;
            fclose($this->pipes[0]);
            unset($this->pipes[0]);
        } elseif (!$w) {
            return array($this->pipes[0]);
        }
    }
619550
@Override
    public WsByteBuffer[] marshallBinaryFirstLine() {
        WsByteBuffer[] firstLine = new WsByteBuffer[1];
        firstLine[0] = allocateBuffer(getOutgoingBufferSize());
        byte[] data = null;

        // marshall the binary protocol version first
        firstLine = putByte(HttpInternalConstants.BINARY_TRANSPORT_V1, firstLine);

        if (getMethodValue().isUndefined()) {
            // unknown method....marshall (masked(len)+Str)
            data = this.myMethod.getByteArray();
            firstLine = putInt(data.length | GenericConstants.KNOWN_MASK, firstLine);
            firstLine = putBytes(data, firstLine);
        } else {
            // known method...marshall methodID
            firstLine = putInt(this.myMethod.getOrdinal(), firstLine);
        }

        // URI(len + str)
        byte[] uri = getResource();
        firstLine = putInt(uri.length, firstLine);
        firstLine = putBytes(uri, firstLine);

        if (getVersionValue().isUndefined()) {
            // unknown version....marshall (masked(len)+Str)
            data = getVersionValue().getByteArray();
            firstLine = putInt(data.length | GenericConstants.KNOWN_MASK, firstLine);
            firstLine = putBytes(data, firstLine);
        } else {
            // known version...marshall versionID
            firstLine = putInt(getVersionValue().getOrdinal(), firstLine);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            String url = GenericUtils.nullOutPasswords(getMarshalledSecondToken(), (byte) '&');
            Tr.event(tc, "Marshalling binary first line: " + getMethod() + " " + url + " " + getVersion());
        }
        // don't flip the last buffer as headers get tacked on the end
        return firstLine;
    }
1022738
public WsByteBuffer[] marshallMessage() throws MessageSentException {
        final boolean bTrace = TraceComponent.isAnyTracingEnabled();
        if (bTrace && tc.isEntryEnabled()) {
            Tr.entry(tc, "marshallMessage");
        }

        preMarshallMessage();
        WsByteBuffer[] marshalledObj = hasFirstLineChanged() ? marshallLine() : null;
        headerComplianceCheck();
        marshalledObj = marshallHeaders(marshalledObj);
        postMarshallMessage();

        if (bTrace && tc.isEntryEnabled()) {
            Tr.exit(tc, "marshallMessage");
        }
        return marshalledObj;
    }