All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gesellix.docker.rawstream.Frame Maven / Gradle / Ivy

There is a newer version: 2024-09-15T20-35-00
Show newest version
package de.gesellix.docker.rawstream;

import java.nio.charset.StandardCharsets;

public class Frame {

  private final StreamType streamType;
  private final byte[] payload;

  public Frame(StreamType streamType, byte[] payload) {
    this.streamType = streamType;
    this.payload = payload;
  }

  public StreamType getStreamType() {
    return streamType;
  }

  public byte[] getPayload() {
    return payload;
  }

  public String getPayloadAsString() {
    if (payload == null) {
      return null;
    }
    return new String(payload, StandardCharsets.UTF_8).trim();
  }

  @Override
  public String toString() {
    return "Frame{" +
           "streamType=" + streamType +
           ", payload=" + getPayloadAsString() +
           '}';
  }

  /**
   * STREAM_TYPE can be:
   * 
    *
  • 0: stdin (will be written on stdout)
  • *
  • 1: stdout
  • *
  • 2: stderr
  • *
  • 3: systemerr
  • *
* See the paragraph _Stream format_ at https://docs.docker.com/engine/api/v1.41/#operation/ContainerAttach. * Reference implementation: https://github.com/moby/moby/blob/master/pkg/stdcopy/stdcopy.go. * Docker client GoDoc: https://godoc.org/github.com/moby/moby/client#Client.ContainerAttach. */ public enum StreamType { // special case for `container.tty == false` RAW((byte) -1), STDIN((byte) 0), STDOUT((byte) 1), STDERR((byte) 2), SYSTEMERR((byte) 3); StreamType(Object streamTypeId) { this.streamTypeId = ((byte) (streamTypeId)); } public static StreamType valueOf(final byte b) { switch (b) { case 0: return STDIN; case 1: return STDOUT; case 2: return STDERR; case 3: return SYSTEMERR; default: throw new IllegalArgumentException("no enum value for " + String.valueOf(b) + " found."); } } public byte getStreamTypeId() { return streamTypeId; } private final byte streamTypeId; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy