Search in sources :

Example 1 with Attach

use of io.kubernetes.client.Attach in project java by kubernetes-client.

the class AttachExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    Attach attach = new Attach();
    final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);
    new Thread(new Runnable() {

        public void run() {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            OutputStream output = result.getStandardInputStream();
            try {
                while (true) {
                    String line = in.readLine();
                    output.write(line.getBytes());
                    output.write('\n');
                    output.flush();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    new Thread(new Runnable() {

        public void run() {
            try {
                ByteStreams.copy(result.getStandardOutputStream(), System.out);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    Thread.sleep(10 * 1000);
    result.close();
    System.exit(0);
}
Also used : InputStreamReader(java.io.InputStreamReader) Attach(io.kubernetes.client.Attach) OutputStream(java.io.OutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient)

Aggregations

ApiClient (io.kubernetes.client.ApiClient)1 Attach (io.kubernetes.client.Attach)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1