Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * JBoss, Home of Professional Open Source.
  * Copyright 2014 Red Hat, Inc., and individual contributors
  * as indicated by the @author tags.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package io.undertow.websockets.spi;

Author(s):
Stuart Douglas
    private final OutputStream out;
    private final InputStream in;
    public BlockingWebSocketHttpServerExchange(final HttpServerExchange exchangeSet<WebSocketChannelpeerConnections) {
        super(exchangepeerConnections);
         = exchange.getOutputStream();
         = exchange.getInputStream();
    }
    @Override
    public IoFuture<VoidsendData(final ByteBuffer data) {
        try {
            while (data.hasRemaining()) {
                .write(data.get());
            }
            return new FinishedIoFuture<>(null);
        } catch (IOException e) {
            final FutureResult<VoidioFuture = new FutureResult<>();
            ioFuture.setException(e);
            return ioFuture.getIoFuture();
        }
    }
    @Override
    public IoFuture<byte[]> readRequestData() {
        final ByteArrayOutputStream data = new ByteArrayOutputStream();
        try {
            byte[] buf = new byte[1024];
            int r;
            while ((r = .read(buf)) != -1) {
                data.write(buf, 0, r);
            }
            return new FinishedIoFuture<>(data.toByteArray());
        } catch (IOException e) {
            final FutureResult<byte[]> ioFuture = new FutureResult<>();
            ioFuture.setException(e);
            return ioFuture.getIoFuture();
        }
    }
New to GrepCode? Check out our FAQ X