DockerCloudUtils { @Nonnull public static String readUTF8String(@Nonnull InputStream inputStream) throws IOException { return readUTF8String(inputStream, -1); }  @Nonnull static T requireNonNull(T obj, @Nonnull String msg); @Nonnull static T requireNonNull(T obj, @Nonnull Supplier<String> msgSupplier); @Nullable static UUID getClientId(@Nonnull AgentDescription agentDescription); @Nullable static UUID getImageId(@Nonnull AgentDescription agentDescription); @Nullable static UUID getInstanceId(@Nonnull AgentDescription agentDescription); @Nullable static UUID tryParseAsUUID(@Nullable String value); @Nonnull static String toShortId(@Nonnull String id); @Nonnull static Logger getLogger(@Nonnull Class<?> cls); @Nullable static String getEnvParameter(@Nonnull AgentDescription agentDescription, @Nonnull String name); @Nonnull static String readUTF8String(@Nonnull InputStream inputStream); @Nonnull static String readUTF8String(@Nonnull InputStream inputStream, int maxByteLength); static boolean hasImageTag(@Nonnull String image); static long toUnsignedLong(int value); @Nonnull static String getStackTrace(@Nullable Throwable throwable); @Nonnull static Map<String, String> extractTCPluginParams(@Nonnull HttpServletRequest request); static boolean isDebugEnabled(); static boolean isDefaultDockerSocketAvailable(); static boolean isDefaultDockerNamedPipeAvailable(); static boolean isWindowsHost(); @Nonnull @SafeVarargs static Map<K,V> immutableMapOf(@Nonnull Pair<K,V>... pairs); @Nonnull @SafeVarargs static Map<K,V> mapOf(@Nonnull Pair<K,V>... pairs); @Nonnull static Pair<K,V> pair(@Nonnull K key, @Nonnull V value); static final String NS; static final String NS_PREFIX; static final String CLIENT_ID_LABEL; static final String INSTANCE_ID_LABEL; static final String SOURCE_IMAGE_ID_LABEL; static final String TEST_INSTANCE_ID_LABEL; static final String CLOUD_TYPE_PARAM; static final String CLIENT_UUID_PARAM; static final String SERVER_URL_PARAM; static final String IMAGES_PARAM; static final String TEST_IMAGE_PARAM; static final String USE_DEFAULT_UNIX_SOCKET_PARAM; static final String USE_DEFAULT_WIN_NAMED_PIPE_PARAM; static final String INSTANCE_URI; static final String USE_TLS; static final String AGENT_RUNTIME_ID_AGENT_CONF; static final URI DOCKER_DEFAULT_SOCKET_URI; static final URI DOCKER_DEFAULT_NAMED_PIPE_URI; static final DockerAPIVersion DOCKER_API_TARGET_VERSION; static final DockerAPIVersion DOCKER_API_MIN_VERSION; static final String DEBUG_SYSPROP; static final String ENV_PREFIX; static final String ENV_CLIENT_ID; static final String ENV_IMAGE_ID; static final String ENV_INSTANCE_ID; static final String ENV_AGENT_PARAMS; static final String ENV_TEST_INSTANCE_ID; static final String ENV_SERVER_URL; static final String TC_PROPERTY_PREFIX; }
@Test public void readUTF8String() throws IOException { String bigText = bigAsciiText(); TestInputStream stream = TestInputStream.withUTF8String(bigText); stream.mark(0); assertThat(DockerCloudUtils.readUTF8String(stream)).isEqualTo(bigText); stream.reset(); assertThat(DockerCloudUtils.readUTF8String(stream, -1)).isEqualTo(bigText); }
@Test public void readUTF8AsciiStringWithLengthCap() throws IOException { String bigText = bigAsciiText(); TestInputStream stream = TestInputStream.withUTF8String(bigText); assertThat(DockerCloudUtils.readUTF8String(stream, 5)). isEqualTo(bigText.substring(0, 5)); }
@Test public void readUTF8AsciiStringWithLengthCapAndTextUnderflow() throws IOException { TestInputStream stream = TestInputStream.withUTF8String("ABC"); assertThat(DockerCloudUtils.readUTF8String(stream, 1000)).isEqualTo("ABC"); assertThat(DockerCloudUtils.readUTF8String(TestInputStream.empty(), 1000)).isEqualTo(""); }
@Test public void readUTF8MultiByteStringWithLengthCap() throws IOException { String textWithTwoBytesChars = "πππππ"; TestInputStream stream = TestInputStream.withUTF8String(textWithTwoBytesChars); assertThat(DockerCloudUtils.readUTF8String(stream, 5)).isEqualTo(textWithTwoBytesChars.substring(0, 2) + "�"); }
@Test public void readUTF8StringShouldNotCloseStream() throws IOException { TestInputStream stream = TestInputStream.empty(); DockerCloudUtils.readUTF8String(stream); assertThat(stream.isClosed()).isFalse(); }
@Test public void readUTF8StringInvalidCap() throws IOException { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> DockerCloudUtils.readUTF8String (TestInputStream.withUTF8String("hello"), -2)); }
@Test public void readUTF8StringWithNullInput() throws IOException { assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> DockerCloudUtils.readUTF8String(null)); assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> DockerCloudUtils.readUTF8String(null, -1)); }