Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2013 JBoss, by Red Hat, Inc
  *
  * 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.core;
java.io.OutputStream implementation which buffers all the data until close() is called and then will try to send it in a blocking fashion with the provided io.undertow.websockets.core.StreamSinkFrameChannel.

Author(s):
Norman Maurer
public final class BinaryOutputStream extends OutputStream {
    private final StreamSinkFrameChannel sender;
    private boolean closed;
    public BinaryOutputStream(StreamSinkFrameChannel sender) {
        this. = sender;
    }
    @Override
    public void write(byte[] bint offint lenthrows IOException {
        checkClosed();
        Channels.writeBlocking(, ByteBuffer.wrap(bofflen));
    }
    @Override
    public void write(int bthrows IOException {
        checkClosed();
        Channels.writeBlocking(, ByteBuffer.wrap(new byte[]{(byteb}));
    }
    @Override
    public void flush() throws IOException {
        checkClosed();
        .flush();
    }
    @Override
    public void close() throws IOException {
        if (!) {
             = true;
            .shutdownWrites();
            Channels.flushBlocking();
        }
    }
    private void checkClosed() throws IOException {
        if () {
            throw ..streamIsClosed();
        }
    }
New to GrepCode? Check out our FAQ X