Package com.facebook.presto.jdbc.internal.netty.buffer

Examples of com.facebook.presto.jdbc.internal.netty.buffer.ChannelBuffer


        if (hostName == null) {
            throw new IllegalArgumentException("hostName is null");
        }
        byte[] userBytes = System.getProperty("user.name", "").getBytes(UTF_8);
        byte[] hostNameBytes = hostName.getBytes(UTF_8);
        ChannelBuffer handshake = ChannelBuffers.dynamicBuffer(10 + userBytes.length + hostNameBytes.length);
        handshake.writeByte(SOCKS_VERSION_4); // SOCKS version
        handshake.writeByte(CONNECT); // CONNECT
        handshake.writeShort(port); // port
        handshake.writeByte(0x00); // fake ip
        handshake.writeByte(0x00); // fake ip
        handshake.writeByte(0x00); // fake ip
        handshake.writeByte(0x01); // fake ip
        handshake.writeBytes(userBytes); // user name
        handshake.writeByte(0x00); // null terminating the string
        handshake.writeBytes(hostNameBytes); // remote host name to connect to
        handshake.writeByte(0x00); // null terminating the string
        return handshake;
    }
View Full Code Here


    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
            throws Exception
    {
        channelFuture.setChannel(ctx.getChannel());
        if (e.getMessage() instanceof ChannelBuffer) {
            ChannelBuffer msg = (ChannelBuffer) e.getMessage();
            if (msg.readableBytes() < 8) {
                channelFuture.setFailure(new IOException("invalid sock server reply length = " + msg.readableBytes()));
            }
            // ignore
            msg.readByte();
            int status = msg.readByte();
            int port = msg.readShort();
            byte[] addr = new byte[4];
            msg.readBytes(addr);

            ctx.getChannel().setAttachment(new InetSocketAddress(InetAddress.getByAddress(addr), port));

            if (status == SocksProtocols.REQUEST_GRANTED) {
                ctx.getPipeline().remove(Socks4ClientBootstrap.FRAME_DECODER);
View Full Code Here

    /**
     * @deprecated use {@link #base64(ChannelBuffer)}
     */
    @Deprecated
    static String base64(byte[] bytes) {
        ChannelBuffer hashed = ChannelBuffers.wrappedBuffer(bytes);
        return Base64.encode(hashed).toString(CharsetUtil.UTF_8);
    }
View Full Code Here

     * try to look at the remoteAddress and decide to use SOCKS4 or SOCKS4a handshake
     * packet.
     */
    private ChannelFuture socksConnect(Channel channel, InetSocketAddress remoteAddress)
    {
        ChannelBuffer handshake = null;
        if ((remoteAddress.getAddress() == null && remoteAddress.getHostName() != null) || remoteAddress.getHostName().equals("localhost")) {
            handshake = createSock4aPacket(remoteAddress.getHostName(), remoteAddress.getPort());
        }
        if (remoteAddress.getAddress() != null) {
            handshake = createSocks4packet(remoteAddress.getAddress(), remoteAddress.getPort());
View Full Code Here

        int frameSize = delimPos - ridx;
        if (frameSize > maxFrameSize) {
            throw new TooLongFrameException();
        }

        ChannelBuffer binaryData = buffer.readBytes(frameSize);
        buffer.skipBytes(1);

        int ffDelimPos = binaryData.indexOf(binaryData.readerIndex(), binaryData.writerIndex(), (byte) 0xFF);
        if (ffDelimPos >= 0) {
            throw new IllegalArgumentException("a text frame should not contain 0xFF.");
        }

        return new TextWebSocketFrame(binaryData);
View Full Code Here

        if (finished) {
            return ChannelBuffers.EMPTY_BUFFER;
        }

        ChannelBuffer decompressed = super.encode(frame);
        if (decompressed.readableBytes() == 0) {
            return ChannelBuffers.EMPTY_BUFFER;
        }

        ChannelBuffer compressed = ChannelBuffers.dynamicBuffer();
        setInput(decompressed);
        encode(compressed);
        return compressed;
    }
View Full Code Here

        // Get 16 bit nonce and base 64 encode it
        byte[] nonce = WebSocketUtil.randomBytes(16);
        String key = WebSocketUtil.base64(ChannelBuffers.wrappedBuffer(nonce));

        String acceptSeed = key + MAGIC_GUID;
        ChannelBuffer sha1 = WebSocketUtil.sha1(ChannelBuffers.copiedBuffer(acceptSeed, CharsetUtil.US_ASCII));
        expectedChallengeResponseString = WebSocketUtil.base64(sha1);

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("WS Version 07 Client Handshake key: %s. Expected response: %s.", key,
                    expectedChallengeResponseString));
View Full Code Here

                // This should never happen, anyway provide a fallback here
                reasonBytes = reasonText.getBytes();
            }
        }

        ChannelBuffer binaryData = ChannelBuffers.buffer(2 + reasonBytes.length);
        binaryData.writeShort(statusCode);
        if (reasonBytes.length > 0) {
            binaryData.writeBytes(reasonBytes);
        }

        binaryData.readerIndex(0);
        setBinaryData(binaryData);
    }
View Full Code Here

    /**
     * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If
     * a status code is set, -1 is returned.
     */
    public int getStatusCode() {
        ChannelBuffer binaryData = getBinaryData();
        if (binaryData == null || binaryData.capacity() == 0) {
            return -1;
        }

        binaryData.readerIndex(0);
        int statusCode = binaryData.readShort();
        binaryData.readerIndex(0);

        return statusCode;
    }
View Full Code Here

    /**
     * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason
     * text is not supplied, an empty string is returned.
     */
    public String getReasonText() {
        ChannelBuffer binaryData = getBinaryData();
        if (binaryData == null || binaryData.capacity() <= 2) {
            return "";
        }

        binaryData.readerIndex(2);
        String reasonText = binaryData.toString(CharsetUtil.UTF_8);
        binaryData.readerIndex(0);

        return reasonText;
    }
View Full Code Here

TOP

Related Classes of com.facebook.presto.jdbc.internal.netty.buffer.ChannelBuffer

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.