Package io.undertow.websockets.extensions

Examples of io.undertow.websockets.extensions.ExtensionByteBuffer


     * @return          a {@link ExtensionByteBuffer} instance as a wrapper of original buffer with extra buffers;
     *                  {@code null} if no extra buffers needed
     * @throws IOException
     */
    protected ExtensionByteBuffer applyExtensions(final ByteBuffer buffer, final int position, final int length) throws IOException {
        ExtensionByteBuffer extBuffer = new ExtensionByteBuffer(getWebSocketChannel(), buffer, position);
        int newLength = length;
        if (extensions != null) {
            for (ExtensionFunction ext : extensions) {
                ext.beforeWrite(this, extBuffer, position, newLength);
                if (extBuffer.getFilled() == 0) {
                    buffer.position(position);
                    newLength = 0;
                } else if (extBuffer.getFilled() != newLength) {
                    newLength = extBuffer.getFilled();
                }
            }
        }
        buffer.flip();
        if (extBuffer.hasExtra()) {
            extBuffer.flipExtra();
            return extBuffer;
        } else {
            return null;
        }
    }
View Full Code Here


     * @return          a {@link ExtensionByteBuffer} instance as a wrapper of original buffer with extra buffers;
     *                  {@code null} if no extra buffers needed
     * @throws IOException
     */
    protected ExtensionByteBuffer applyExtensionsFlush(final ByteBuffer buffer, final int position, final int length) throws IOException {
        ExtensionByteBuffer extBuffer = new ExtensionByteBuffer(getWebSocketChannel(), buffer, position);
        int newLength = length;
        if (extensions != null) {
            for (ExtensionFunction ext : extensions) {
                ext.beforeFlush(this, extBuffer, position, newLength);
                if (extBuffer.getFilled() == 0) {
                    buffer.position(position);
                    newLength = 0;
                } else if (extBuffer.getFilled() != newLength) {
                    newLength = extBuffer.getFilled();
                }
            }
        }
        buffer.flip();
        if (extBuffer.hasExtra()) {
            extBuffer.flipExtra();
            return extBuffer;
        } else {
            return null;
        }
    }
View Full Code Here

    @Override
    public void shutdownWrites() throws IOException {
        if (getRsv() > 0 && isOpen()) {
            Pooled<ByteBuffer> pooledPadding = this.getChannel().getBufferPool().allocate();
            ByteBuffer buffer = pooledPadding.getResource();
            ExtensionByteBuffer extPadding = applyExtensionsFlush(buffer, 0, buffer.remaining());
            try {
                if (masker != null) {
                    masker.beforeWrite(buffer, 0, buffer.remaining());
                }
                while (buffer.hasRemaining()) {
                    super.write(buffer);
                }
                if (extPadding != null) {
                    while (extPadding.hasExtraRemaining()) {
                        super.write(extPadding.getExtraRemainingBuffer());
                    }
                }
            } finally {
                pooledPadding.free();
                if (extPadding != null && extPadding.hasExtra()) {
                    extPadding.free();
                }
            }
        }
        super.shutdownWrites();
    }
View Full Code Here

     * @return          a {@link ExtensionByteBuffer} instance as a wrapper of original buffer with extra buffers;
     *                  {@code null} if no extra buffers needed
     * @throws IOException
     */
    protected ExtensionByteBuffer applyExtensions(final ByteBuffer buffer, final int position, final int length) throws IOException {
        ExtensionByteBuffer extBuffer = new ExtensionByteBuffer(getWebSocketChannel(), buffer, position);
        int newLength = length;
        if (extensions != null) {
            for (ExtensionFunction ext : extensions) {
                ext.afterRead(this, extBuffer, position, newLength);
                if (extBuffer.getFilled() == 0) {
                    buffer.position(position);
                    newLength = 0;
                } else if (extBuffer.getFilled() != newLength) {
                    newLength = extBuffer.getFilled();
                }
            }
        }
        if (!extBuffer.hasExtra()) {
            return null;
        }
        return extBuffer;
    }
View Full Code Here

TOP

Related Classes of io.undertow.websockets.extensions.ExtensionByteBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.