Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.undertow.websockets.spi;
 
 

Author(s):
Stuart Douglas
    private final OutputStream out;
    private final InputStream in;
    public BlockingWebSocketHttpServerExchange(final HttpServerExchange exchange) {
        super(exchange);
         = exchange.getOutputStream();
         = exchange.getInputStream();
    }
    @Override
    public IoFuture<VoidsendData(final ByteBuffer data) {
        try {
            while (data.hasRemaining()) {
                .write(data.get());
            }
            return new FinishedIoFuture<Void>(null);
        } catch (IOException e) {
            final FutureResult<VoidioFuture = new FutureResult<Void>();
            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<byte[]>(data.toByteArray());
        } catch (IOException e) {
            final FutureResult<byte[]> ioFuture = new FutureResult<byte[]>();
            ioFuture.setException(e);
            return ioFuture.getIoFuture();
        }
    }
New to GrepCode? Check out our FAQ X