当前位置: 首页>>代码示例>>Java>>正文


Java FileEntity类代码示例

本文整理汇总了Java中org.apache.http.entity.FileEntity的典型用法代码示例。如果您正苦于以下问题:Java FileEntity类的具体用法?Java FileEntity怎么用?Java FileEntity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileEntity类属于org.apache.http.entity包,在下文中一共展示了FileEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: should_download

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
@Test
public void should_download() throws Exception {
    CloseableHttpResponse tokenResponse = mock(CloseableHttpResponse.class);
    when(tokenResponse.getEntity()).thenReturn(new StringEntity("validToken","UTF-8"));

    CloseableHttpResponse fileResponse = mock(CloseableHttpResponse.class);
    when(fileResponse.getEntity()).thenReturn(new FileEntity(new File(getClass().getResource("/tomtom/download/test.metalink").toURI())));

    when(client.execute(any(HttpPost.class))).thenReturn(tokenResponse, fileResponse);

    Metalink download = metalinkDownloader.download();

    assertThat(download.getUrls()).isEqualTo(newArrayList(
            new MetalinkParser.MetalinkUrl("test-shpd-mn-and-and.7z.001", "test", "and", "d", "mn", "and", "http://test.com/and.7z.001"),
            new MetalinkParser.MetalinkUrl("test-shpd-mn-and-ax.7z.001", "test", "and", "d", "mn", "ax", "http://test.com/ax.7z.001")
    ));
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:18,代码来源:MetalinkDownloaderTest.java

示例2: upload

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
protected void upload(final UploadPluginExtension ext, final File artifact) throws ClientProtocolException, IOException {
  final HttpEntity entity = new FileEntity(artifact);

  final StringBuilder url = new StringBuilder();
  url.append(ext.getUrl()).append('/').append(ext.getRepository()).append('/').append(ext.getFolder()).append('/').append(artifact.getName());
  logger.debug("Uploading {} to {}", artifact.getName(), url.toString());

  credentialsProvider.setCredentials(
      new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
      new UsernamePasswordCredentials(ext.getUsername(), ext.getPassword()));

  final HttpPut request = new HttpPut(url.toString());
  request.setEntity(entity);

  final HttpResponse response = client.execute(request);

  if (response.getStatusLine().getStatusCode() != 201) {
    EntityUtils.consume(response.getEntity());
    throw new GradleException("Unable to upload artifact. Response from artifactory was " + response.getStatusLine());
  }

  EntityUtils.consume(response.getEntity());
  logger.debug("Uploaded {} successfully!", artifact.getName());
}
 
开发者ID:LibraryOfCongress,项目名称:simple-artifact-uploader,代码行数:25,代码来源:UploadTask.java

示例3: canCreateInstance

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void canCreateInstance() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_CREATED, "Created");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/instances/created.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    Instance instance = new Instance()
            .setName("some_name")
            .setPackageId(new UUID(12L, 24L))
            .setImage(new UUID(8L, 16L))
            .setTags(Collections.singletonMap(TEST_TAG_KEY, TEST_TAG));

    try (CloudApiConnectionContext context = createMockContext(response)) {
        final Instance created = instanceApi.create(context, instance);
        assertNotNull(created);
        assertNotNull(created.getId());
    }
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:20,代码来源:InstancesTest.java

示例4: errorsCorrectlyWhenDeletingUnknownInstance

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void errorsCorrectlyWhenDeletingUnknownInstance() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not Found");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/error/not_found.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    boolean thrown = false;

    try (CloudApiConnectionContext context = createMockContext(response)) {
        UUID instanceId = new UUID(512L, 1024L);
        instanceApi.delete(context, instanceId);
    } catch (CloudApiResponseException e) {
        thrown = true;
        assertTrue(e.getMessage().contains("VM not found"),
                   "Unexpected message on exception");
    }

    assertTrue(thrown, "CloudApiResponseException never thrown");
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:21,代码来源:InstancesTest.java

示例5: canWaitForStateChangeWhenItAlreadyChanged

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void canWaitForStateChangeWhenItAlreadyChanged() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/domain/instance.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    final UUID instanceId = UUID.fromString("c872d3bf-cbaa-4165-8e18-f6e3e1d94da9");
    final String stateToChangeFrom = "provisioning";

    try (CloudApiConnectionContext context = createMockContext(response)) {
        final Instance running = instanceApi.waitForStateChange(
                context, instanceId, stateToChangeFrom, 0L, 0L);

        assertEquals(running.getId(), instanceId, "ids should match");
        assertNotEquals(running.getState(), stateToChangeFrom,
                "shouldn't be in [" + stateToChangeFrom + "] state");
        assertEquals(running.getState(), "running", "should be in running state");
    }
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:21,代码来源:InstancesTest.java

示例6: canFindRunningInstanceById

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void canFindRunningInstanceById() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/domain/instance.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    final UUID instanceId = UUID.fromString("c872d3bf-cbaa-4165-8e18-f6e3e1d94da9");

    try (CloudApiConnectionContext context = createMockContext(response)) {
        Instance found = instanceApi.findById(context, instanceId);

        assertNotNull(found, "expecting instance to be found");
        assertEquals(found.getId(), instanceId, "expecting ids to match");
    }
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:17,代码来源:InstancesTest.java

示例7: canAddAdditionalTagsToAnInstance

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void canAddAdditionalTagsToAnInstance() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/instances/additional_tags.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    final UUID instanceId = UUID.fromString("c872d3bf-cbaa-4165-8e18-f6e3e1d94da9");

    try (CloudApiConnectionContext context = createMockContext(response)) {
        Map<String, String> tags = instanceApi.addTags(context, instanceId,
                ImmutableMap.of("additional_1", "val1", "additional_2", "val2"));

        assertEquals(tags.size(), 3, "Expecting 3 tags");
        assertEquals(tags.get("name"), "value");
        assertEquals(tags.get("additional_1"), "val1");
        assertEquals(tags.get("additional_2"), "val2");
    }
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:20,代码来源:InstancesTest.java

示例8: canReplaceTagsOnAnInstance

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void canReplaceTagsOnAnInstance() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/instances/replace_tags.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    final UUID instanceId = UUID.fromString("c872d3bf-cbaa-4165-8e18-f6e3e1d94da9");

    try (CloudApiConnectionContext context = createMockContext(response)) {
        Map<String, String> tags = instanceApi.replaceTags(context, instanceId,
                ImmutableMap.of("additional_1", "val1", "additional_2", "val2"));

        assertEquals(tags.size(), 2, "Expecting 2 tags");
        assertEquals(tags.get("additional_1"), "val1");
        assertEquals(tags.get("additional_2"), "val2");
    }
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:19,代码来源:InstancesTest.java

示例9: canFindTheSmallestMemoryPackages

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void canFindTheSmallestMemoryPackages() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/packages/packages.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    try (CloudApiConnectionContext context = createMockContext(response)) {
        Collection<Package> packages = packagesApi.smallestMemory(context);
        assertFalse(packages.isEmpty(), "This should not be an empty collection");
        assertEquals(packages.size(), 1);

        final Package pkg = packages.iterator().next();
        assertEquals(pkg.getName(), "t4-standard-128M",
                "Package name is unexpected. Actual package:\n" + pkg);
    }
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:18,代码来源:PackagesTest.java

示例10: constructOctetStreamEntity

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
/**
 * Constructs octet-stream entity based upon the specified value or the file and its mimetype (ie. request
 * parameter).
 * 
 * @param requestParam
 *            request parameter
 * @return request octet-stream entity for the service
 */
private static HttpEntity constructOctetStreamEntity(ExecutionBodyParam requestParam) {
    if (requestParam == null) {
        return null;
    }
    if (requestParam.getValue() != null) {
        return new StringEntity(requestParam.getValue(), TEXTPLAIN);
    }
    if (requestParam.getFileValue() != null) {
        try {
            ContentType contentType = ContentType.create(requestParam.getFileValue().getMimetype());
            return new FileEntity(requestParam.getFileValue().getFile(), contentType);
        } catch (IllegalArgumentException e) {
            return new FileEntity(requestParam.getFileValue().getFile());
        }
    }
    return null;
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:26,代码来源:RestServiceCallerUtils.java

示例11: handle

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public void handle(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {

    String target = request.getRequestLine().getUri();
    final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
    HttpCoreContext coreContext = HttpCoreContext.adapt(context);
    HttpConnection conn = coreContext.getConnection(HttpConnection.class);
    response.setStatusCode(HttpStatus.SC_OK);
    FileEntity body = new FileEntity(file, ContentType.create("text/html", (Charset) null));
    response.setEntity(body);
    System.out.println(conn + ": serving file " + file.getPath());

    new Thread() {
        @Override
        public void run() {
            System.out.println("Stopping HTTP Server...");
            server.stop();
        }
    }.start();
}
 
开发者ID:njfox,项目名称:Java-Deserialization-Exploit,代码行数:23,代码来源:HttpFileServer.java

示例12: uploadConfiguration

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
private void uploadConfiguration() throws IOException {
    System.out.print(ImplMessages.getMessage("PROVISIONER_UPLOADING_CONFIG_MSG"));
    // String url = "https://"+hostname+":"+6143+"/geoevent/admin/configuration/install/.json";
    String url = "https://" + hostName + ":" + 6143 + "/geoevent/admin/configuration/.json";

    File configAsFile = new File(configFile);

    CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(getSSLSocketFactory()).build();
    FileEntity file = new FileEntity(configAsFile, ContentType.APPLICATION_XML);
    HttpUriRequest post = RequestBuilder.put().setUri(url).addHeader("GeoEventAuthorization", token).addHeader("referer", referer).setEntity(file).build();

    HttpResponse response = httpClient.execute(post);
    HttpEntity entity = response.getEntity();
    ObjectMapper mapper = new ObjectMapper();
    @SuppressWarnings("unused")
    JsonNode jsonResponse = mapper.readTree(entity.getContent());
    sleep(10 * 1000);
    System.out.println(ImplMessages.getMessage("DONE"));
}
 
开发者ID:Esri,项目名称:performance-test-harness-for-geoevent,代码行数:20,代码来源:GeoEventProvisioner.java

示例13: upload

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
@Override
public void upload(final File src, final URL dest, final CopyProgressListener listener, final TimeoutConstraint timeoutConstraint) throws IOException {
    final int connectionTimeout = (timeoutConstraint == null || timeoutConstraint.getConnectionTimeout() < 0) ? 0 : timeoutConstraint.getConnectionTimeout();
    final int readTimeout = (timeoutConstraint == null || timeoutConstraint.getReadTimeout() < 0) ? 0 : timeoutConstraint.getReadTimeout();
    final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(readTimeout)
            .setConnectTimeout(connectionTimeout)
            .setAuthenticationEnabled(hasCredentialsConfigured(dest))
            .setTargetPreferredAuthSchemes(getAuthSchemePreferredOrder())
            .setProxyPreferredAuthSchemes(getAuthSchemePreferredOrder())
            .setExpectContinueEnabled(true)
            .build();
    final HttpPut put = new HttpPut(normalizeToString(dest));
    put.setConfig(requestConfig);
    put.setEntity(new FileEntity(src));
    try (final CloseableHttpResponse response = this.httpClient.execute(put)) {
        validatePutStatusCode(dest, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
    }
}
 
开发者ID:apache,项目名称:ant-ivy,代码行数:19,代码来源:HttpClientHandler.java

示例14: setJobState

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
public String setJobState(String uri, String jobState) throws IOException {
	File templateFile = new File(jobStateTemplate);
	String job_id = uri.substring(uri.lastIndexOf("/"), uri.length());
	File outputFile = new File(basedir + "/result/" + job_id + "_JobState.xml");
	
	Template t = new Template(templateFile);
	t.setValue("state", jobState);
	t.export(new FileOutputStream(outputFile));

	FileEntity entity = new FileEntity(outputFile, ContentType.create("text/xml", "UTF-8"));
	HttpResponseObj resp = null;
	try {
		App.logInfo("Settting Job State URL: " + uri);
		Header h = new Header();
		h.addHeader("X-SFDC-Session", session_id);
		h.addHeader("Content-Type", "text/csv");
		resp = wa.doPost(uri, h.getAllHeaders(), entity);
	} catch (Exception e) {
		e.printStackTrace();
	}
	App.logInfo("Job State Response:\n" + resp.getContent());
	printSFJobInformation(resp.getContent());
	String status = parseXMLResponse(resp.getContent(), "state");
	App.logInfo("Job Status: " + status);
	return status;
}
 
开发者ID:sunand85,项目名称:DF14_Demo,代码行数:27,代码来源:SfdcBulkOperationImpl.java

示例15: submitUploadText

import org.apache.http.entity.FileEntity; //导入依赖的package包/类
private CloseableHttpResponse submitUploadText() throws ClientProtocolException, IOException {
	CloseableHttpClient httpclient = HttpClients.createDefault();

	HttpPost httppost = new HttpPost("http://localhost/upload.txt");
	File file = new File("x.txt");
	FileEntity entity = new FileEntity(file, ContentType.create("text/plain", "UTF-8"));
	httppost.setEntity(entity);
	CloseableHttpResponse response = null;
	try {
		response = httpclient.execute(httppost);
	} finally {
		response.close();
	}

	return response;
}
 
开发者ID:victorbucutea,项目名称:httpserver,代码行数:17,代码来源:HttpUploadTest.java


注:本文中的org.apache.http.entity.FileEntity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。