io.fabric8.docker.client.impl.ContainerOutputHandle Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2016 Original Authors
*
* 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.fabric8.docker.client.impl;
import io.fabric8.docker.client.DockerClientException;
import io.fabric8.docker.dsl.OutputErrorHandle;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.Charset;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
public class ContainerOutputHandle extends WebSocketListener implements OutputErrorHandle {
private static final Logger LOGGER = LoggerFactory.getLogger(ContainerOutputHandle.class);
private final OutputStream out;
private final OutputStream err;
private final PipedInputStream output;
private final PipedInputStream error;
private final AtomicBoolean started = new AtomicBoolean(false);
protected final AtomicReference webSocketRef = new AtomicReference<>();
protected final ArrayBlockingQueue