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


Java IOUtils.toString方法代码示例

本文整理汇总了Java中com.amazonaws.util.IOUtils.toString方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.toString方法的具体用法?Java IOUtils.toString怎么用?Java IOUtils.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.util.IOUtils的用法示例。


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

示例1: parse

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * Helper method that parses a JSON object from a resource on the classpath
 * as an instance of the provided type.
 *
 * @param resource
 *            the path to the resource (relative to this class)
 * @param clazz
 *            the type to parse the JSON into
 */
public static <T> T parse(String resource, Class<T> clazz)
		throws IOException {

	InputStream stream = TestUtils.class.getResourceAsStream(resource);
	try {
		if (clazz == S3Event.class) {
			String json = IOUtils.toString(stream);
			S3EventNotification event = S3EventNotification.parseJson(json);

			@SuppressWarnings("unchecked")
			T result = (T) new S3Event(event.getRecords());
			return result;

		} else if (clazz == SNSEvent.class) {
			return snsEventMapper.readValue(stream, clazz);
		} else if (clazz == DynamodbEvent.class) {
			return dynamodbEventMapper.readValue(stream, clazz);
		} else {
			return mapper.readValue(stream, clazz);
		}
	} finally {
		stream.close();
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:34,代码来源:TestUtils.java

示例2: parse

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * Helper method that parses a JSON object from a resource on the classpath
 * as an instance of the provided type.
 *
 * @param resource the path to the resource (relative to this class)
 * @param clazz the type to parse the JSON into
 */
public static <T> T parse(String resource, Class<T> clazz)
        throws IOException {

    InputStream stream = TestUtils.class.getResourceAsStream(resource);
    try {
        if (clazz == S3Event.class) {
            String json = IOUtils.toString(stream);
            S3EventNotification event = S3EventNotification.parseJson(json);

            @SuppressWarnings("unchecked")
            T result = (T) new S3Event(event.getRecords());
            return result;

        } else {
            return mapper.readValue(stream, clazz);
        }
    } finally {
        stream.close();
    } 
}
 
开发者ID:taichi,项目名称:sirusi,代码行数:28,代码来源:TestUtils.java

示例3: copyOneObject

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Test
public void copyOneObject() throws Exception {
  client.putObject("source", "data", inputData);

  Path sourceBaseLocation = new Path("s3://source/");
  Path replicaLocation = new Path("s3://target/");
  List<Path> sourceSubLocations = new ArrayList<>();
  S3S3Copier s3s3Copier = newS3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation);
  Metrics metrics = s3s3Copier.copy();
  assertThat(metrics.getBytesReplicated(), is(7L));
  assertThat(metrics.getMetrics().get(S3S3CopierMetrics.Metrics.TOTAL_BYTES_TO_REPLICATE.name()), is(7L));
  S3Object object = client.getObject("target", "data");
  String data = IOUtils.toString(object.getObjectContent());
  assertThat(data, is("bar foo"));
  assertThat(registry.getGauges().containsKey(RunningMetrics.S3S3_CP_BYTES_REPLICATED.name()), is(true));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:17,代码来源:S3S3CopierTest.java

示例4: copyMultipleObjects

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Test
public void copyMultipleObjects() throws Exception {
  // Making sure we only request 1 file at the time so we need to loop
  ListObjectsRequestFactory mockListObjectRequestFactory = Mockito.mock(ListObjectsRequestFactory.class);
  when(mockListObjectRequestFactory.newInstance()).thenReturn(new ListObjectsRequest().withMaxKeys(1));

  client.putObject("source", "bar/data1", inputData);
  client.putObject("source", "bar/data2", inputData);

  Path sourceBaseLocation = new Path("s3://source/bar/");
  Path replicaLocation = new Path("s3://target/foo/");
  List<Path> sourceSubLocations = new ArrayList<>();
  S3S3Copier s3s3Copier = new S3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation, s3ClientFactory,
      transferManagerFactory, mockListObjectRequestFactory, registry, s3S3CopierOptions);
  Metrics metrics = s3s3Copier.copy();
  assertThat(metrics.getBytesReplicated(), is(14L));

  S3Object object1 = client.getObject("target", "foo/data1");
  String data1 = IOUtils.toString(object1.getObjectContent());
  assertThat(data1, is("bar foo"));
  S3Object object2 = client.getObject("target", "foo/data2");
  String data2 = IOUtils.toString(object2.getObjectContent());
  assertThat(data2, is("bar foo"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:25,代码来源:S3S3CopierTest.java

示例5: handleErrorResponse

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
    String errorCode = null;

    // Parse the error stream returned from the service.
    if(errorStream != null) {
        String errorResponse = IOUtils.toString(errorStream);

        try {
            JsonNode node = Jackson.jsonNodeOf(errorResponse);
            JsonNode code = node.get("code");
            JsonNode message = node.get("message");
            if (code != null && message != null) {
                errorCode = code.asText();
                responseMessage = message.asText();
            }
        } catch (Exception exception) {
            LOG.debug("Unable to parse error stream");
        }
    }

    AmazonServiceException ase = new AmazonServiceException(responseMessage);
    ase.setStatusCode(statusCode);
    ase.setErrorCode(errorCode);
    throw ase;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:26,代码来源:EC2CredentialsUtils.java

示例6: getBaseProfile

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Override
protected Profile getBaseProfile(String name, String version, String outputFile) {
  try {
    return new Profile(name,
        version,
        outputFile,
        IOUtils.toString(profileRegistry.readProfile(getArtifact().getName(), version, name))
    );
  } catch (RetrofitError | IOException e) {
    throw new HalException(
        new ConfigProblemBuilder(FATAL,
            "Unable to retrieve profile \"" + name + "\": " + e.getMessage())
            .build(),
        e
    );
  }
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:18,代码来源:RegistryBackedProfileFactory.java

示例7: decryptFile

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc }
 */
@Override
public String decryptFile(
        final String encryptedFilename) {

    final KmsMasterKeyProvider provider
            = new KmsMasterKeyProvider(
                    new DefaultAWSCredentialsProviderChain());

    final AwsCrypto awsCrypto
            = new AwsCrypto();

    try (final FileInputStream fileInputStream
            = new FileInputStream(
                    encryptedFilename);

            final CryptoInputStream<?> decryptingStream
                    = awsCrypto
                            .createDecryptingStream(
                                    provider, 
                                    fileInputStream)) {

        return IOUtils.toString(
                decryptingStream);

    } catch (IOException exception) {
        throw new DecryptionException(exception);
    }
}
 
开发者ID:eonian-technologies,项目名称:secrets-locker,代码行数:32,代码来源:KmsDecryptionService.java

示例8: readFileFromS3

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * Reads a file from S3 into a String object
 * @param s3Uri (eg. s3://bucket/file.ext)
 * @return String containing the content of the file in S3
 * @throws IOException if error reading file
 */
public String readFileFromS3(String s3Uri) throws IOException {
    AmazonS3URI s3FileUri = new AmazonS3URI(s3Uri);
    S3Object s3object = amazonS3Client.getObject(new GetObjectRequest(s3FileUri.getBucket(), s3FileUri.getKey()));
    
    return IOUtils.toString(s3object.getObjectContent());
}
 
开发者ID:shinesolutions,项目名称:aem-orchestrator,代码行数:13,代码来源:AwsHelperService.java

示例9: copyOneObjectUsingKeys

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Test
public void copyOneObjectUsingKeys() throws Exception {
  client.putObject("source", "bar/data", inputData);

  Path sourceBaseLocation = new Path("s3://source/bar/");
  Path replicaLocation = new Path("s3://target/foo/");
  List<Path> sourceSubLocations = new ArrayList<>();
  S3S3Copier s3s3Copier = newS3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation);
  s3s3Copier.copy();
  S3Object object = client.getObject("target", "foo/data");
  String data = IOUtils.toString(object.getObjectContent());
  assertThat(data, is("bar foo"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:14,代码来源:S3S3CopierTest.java

示例10: copyOneObjectPartitioned

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Test
public void copyOneObjectPartitioned() throws Exception {
  client.putObject("source", "year=2016/data", inputData);

  Path sourceBaseLocation = new Path("s3://source/");
  Path replicaLocation = new Path("s3://target/foo/");
  List<Path> sourceSubLocations = Lists.newArrayList(new Path(sourceBaseLocation, "year=2016"));
  S3S3Copier s3s3Copier = newS3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation);
  Metrics metrics = s3s3Copier.copy();
  assertThat(metrics.getBytesReplicated(), is(7L));
  S3Object object = client.getObject("target", "foo/year=2016/data");
  String data = IOUtils.toString(object.getObjectContent());
  assertThat(data, is("bar foo"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:15,代码来源:S3S3CopierTest.java

示例11: copyOneObjectPartitionedSourceBaseNested

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Test
public void copyOneObjectPartitionedSourceBaseNested() throws Exception {
  client.putObject("source", "nested/year=2016/data", inputData);

  Path sourceBaseLocation = new Path("s3://source/nested");// no slash at the end
  Path replicaLocation = new Path("s3://target/foo/");
  List<Path> sourceSubLocations = Lists.newArrayList(new Path(sourceBaseLocation, "year=2016"));
  S3S3Copier s3s3Copier = newS3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation);
  s3s3Copier.copy();
  S3Object object = client.getObject("target", "foo/year=2016/data");
  String data = IOUtils.toString(object.getObjectContent());
  assertThat(data, is("bar foo"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:14,代码来源:S3S3CopierTest.java

示例12: copyOneObjectPartitionedHandlingS3ASchemes

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Test
public void copyOneObjectPartitionedHandlingS3ASchemes() throws Exception {
  client.putObject("source", "year=2016/data", inputData);

  Path sourceBaseLocation = new Path("s3a://source/");
  Path replicaLocation = new Path("s3a://target/foo/");
  List<Path> sourceSubLocations = Lists.newArrayList(new Path(sourceBaseLocation, "year=2016"));
  S3S3Copier s3s3Copier = newS3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation);
  s3s3Copier.copy();
  S3Object object = client.getObject("target", "foo/year=2016/data");
  String data = IOUtils.toString(object.getObjectContent());
  assertThat(data, is("bar foo"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:14,代码来源:S3S3CopierTest.java

示例13: contentToString

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private String contentToString(InputStream content, String idString) throws Exception {
    try {
        return IOUtils.toString(content);
    } catch (Exception e) {
        log.info(String.format("Unable to read input stream to string (%s)", idString), e);
        throw e;
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:9,代码来源:DefaultErrorResponseHandler.java

示例14: readResource

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
 * Connects to the given endpoint to read the resource
 * and returns the text contents.
 *
 * @param endpoint
 *            The service endpoint to connect to.
 *
 * @param retryPolicy
 *            The custom retry policy that determines whether a
 *            failed request should be retried or not.
 *
 * @return The text payload returned from the Amazon EC2 endpoint
 *         service for the specified resource path.
 *
 * @throws IOException
 *             If any problems were encountered while connecting to the
 *             service for the requested resource path.
 * @throws SdkClientException
 *             If the requested service is not found.
 */
public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy) throws IOException {
    int retriesAttempted = 0;
    InputStream inputStream = null;

    while (true) {
        try {
            HttpURLConnection connection = connectionUtils.connectToEndpoint(endpoint);

            int statusCode = connection.getResponseCode();

            if (statusCode == HttpURLConnection.HTTP_OK) {
                inputStream = connection.getInputStream();
                return IOUtils.toString(inputStream);
            } else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
                // This is to preserve existing behavior of EC2 Instance metadata service.
                throw new SdkClientException("The requested metadata is not found at " + connection.getURL());
            } else {
                if (!retryPolicy.shouldRetry(retriesAttempted++, CredentialsEndpointRetryParameters.builder().withStatusCode(statusCode).build())) {
                    inputStream = connection.getErrorStream();
                    handleErrorResponse(inputStream, statusCode, connection.getResponseMessage());
                }
            }
        } catch (IOException ioException) {
            if (!retryPolicy.shouldRetry(retriesAttempted++, CredentialsEndpointRetryParameters.builder().withException(ioException).build())) {
                throw ioException;
            }
            LOG.debug("An IOException occured when connecting to service endpoint: " + endpoint  + "\n Retrying to connect again.");
        } finally {
            IOUtils.closeQuietly(inputStream, LOG);
        }
    }

}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:54,代码来源:EC2CredentialsUtils.java

示例15: DummyResponseServerBehavior

import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
public DummyResponseServerBehavior(HttpResponse response) {
    this.response = response;
    try {
        this.content = IOUtils.toString(response.getEntity().getContent());
    } catch (Exception e) {
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:8,代码来源:MockServer.java


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