DockerConnector { public void putResource(String container, String targetPath, InputStream sourceStream, boolean noOverwriteDirNonDir) throws IOException { File tarFile; long length; try (InputStream sourceData = sourceStream) { Path tarFilePath = Files.createTempFile("compressed-resources", ".tar"); tarFile = tarFilePath.toFile(); length = Files.copy(sourceData, tarFilePath, StandardCopyOption.REPLACE_EXISTING); } List<Pair<String, ?>> headers = Arrays.asList(Pair.of("Content-Type", ExtMediaType.APPLICATION_X_TAR), Pair.of("Content-Length", length)); try (InputStream tarStream = new BufferedInputStream(new FileInputStream(tarFile)); DockerConnection connection = openConnection(dockerDaemonUri).method("PUT") .path("/containers/" + container + "/archive") .query("path", targetPath) .query("noOverwriteDirNonDir", noOverwriteDirNonDir ? 0 : 1) .headers(headers) .entity(tarStream)) { final DockerResponse response = connection.request(); final int status = response.getStatus(); if (status != OK.getStatusCode()) { throw new DockerException(getDockerExceptionMessage(response), status); } } finally { FileCleaner.addFile(tarFile); } } DockerConnector(InitialAuthConfig initialAuthConfig);  DockerConnector(URI dockerDaemonUri,
                           DockerCertificates dockerCertificates,
                           InitialAuthConfig initialAuthConfig); @Inject private  DockerConnector(DockerConnectorConfiguration connectorConfiguration); org.eclipse.che.plugin.docker.client.json.SystemInfo getSystemInfo(); Version getVersion(); Image[] listImages(); String buildImage(String repository, ProgressMonitor progressMonitor, AuthConfigs authConfigs, File... files); ImageInfo inspectImage(String image); void removeImage(String image, boolean force); void tag(String image, String repository, String tag); void push(String repository,
                     String tag,
                     String registry,
                     final ProgressMonitor progressMonitor); void pull(String image,
                     String tag,
                     String registry,
                     ProgressMonitor progressMonitor); ContainerCreated createContainer(ContainerConfig containerConfig, String containerName); void startContainer(String container, HostConfig hostConfig); void stopContainer(String container, long timeout, TimeUnit timeunit); void killContainer(String container, int signal); void killContainer(String container); void removeContainer(String container, boolean force, boolean removeVolumes); int waitContainer(String container); ContainerInfo inspectContainer(String container); void attachContainer(String container, MessageProcessor<LogMessage> containerLogsProcessor, boolean stream); String commit(String container, String repository, String tag, String comment, String author); @Deprecated void copy(String container, String path, File hostPath); Exec createExec(String container, boolean detach, String... cmd); void startExec(String execId, MessageProcessor<LogMessage> execOutputProcessor); ExecInfo getExecInfo(String execId); ContainerProcesses top(String container, String... psArgs); InputStream getResource(String container, String sourcePath); void putResource(String container,
                            String targetPath,
                            InputStream sourceStream,
                            boolean noOverwriteDirNonDir); void getEvents(long sinceSecond,
                          long untilSecond,
                          Filters filters,
                          MessageProcessor<Event> messageProcessor); static final String UNIX_SOCKET_SCHEME; static final String UNIX_SOCKET_PATH; static final URI UNIX_SOCKET_URI; static final String DOCKER_CERT_PATH_PROPERTY; static final String DOCKER_TLS_VERIFY_PROPERTY; static final String DOCKER_HOST_PROPERTY; static final URI DEFAULT_DOCKER_MACHINE_URI; static final String DEFAULT_DOCKER_MACHINE_CERTS_DIR; }
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Error response from docker API, status: 500, message: Error") public void shouldProduceAnErrorWhenPutsResourcesIntoContainer() throws IOException { String msg = "Error"; when(dockerResponse.getStatus()).thenReturn(500); when(dockerResponse.getInputStream()) .thenReturn(new ByteArrayInputStream(msg.getBytes())); InputStream source = new CloseConnectionInputStream(new ByteArrayInputStream(msg.getBytes()), dockerConnection); dockerConnector.putResource("id", "path", source, false); }
@Test public void shouldPutResourcesIntoContainer() throws IOException { String file = "stream data"; when(dockerResponse.getStatus()).thenReturn(200); InputStream source = new CloseConnectionInputStream(new ByteArrayInputStream(file.getBytes()), dockerConnection); dockerConnector.putResource("id", "path", source, false); }