本文整理了Java中com.amazonaws.util.IOUtils.toByteArray()
方法的一些代码示例,展示了IOUtils.toByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.toByteArray()
方法的具体详情如下:
包路径:com.amazonaws.util.IOUtils
类名称:IOUtils
方法名:toByteArray
[英]Reads and returns the rest of the given input stream as a byte array. Caller is responsible for closing the given input stream.
[中]以字节数组的形式读取并返回给定输入流的其余部分。调用者负责关闭给定的输入流。
代码示例来源:origin: aws/aws-sdk-java
/**
* Reads and returns the rest of the given input stream as a string.
* Caller is responsible for closing the given input stream.
*/
public static String toString(InputStream is) throws IOException {
return new String(toByteArray(is), StringUtils.UTF8);
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Static factory method to create a JsonContent object from the contents of the HttpResponse
* provided
*/
public static JsonContent createJsonContent(HttpResponse httpResponse,
JsonFactory jsonFactory) {
byte[] rawJsonContent = null;
try {
if (httpResponse.getContent() != null) {
rawJsonContent = IOUtils.toByteArray(httpResponse.getContent());
}
} catch (Exception e) {
LOG.debug("Unable to read HTTP response content", e);
}
return new JsonContent(rawJsonContent, new ObjectMapper(jsonFactory)
.configure(JsonParser.Feature.ALLOW_COMMENTS, true));
}
代码示例来源:origin: brianfrankcooper/YCSB
/**
* Download an object from S3.
*
* @param bucket
* The name of the bucket
* @param key
* The file key of the object to upload/update.
* @param result
* The Hash map where data from the object are written
*
*/
protected Status readFromStorage(String bucket, String key,
Map<String, ByteIterator> result, SSECustomerKey ssecLocal) {
try {
S3Object object = getS3ObjectAndMetadata(bucket, key, ssecLocal);
InputStream objectData = object.getObjectContent(); //consuming the stream
// writing the stream to bytes and to results
result.put(key, new ByteArrayByteIterator(IOUtils.toByteArray(objectData)));
objectData.close();
object.close();
} catch (Exception e){
System.err.println("Not possible to get the object "+key);
e.printStackTrace();
return Status.ERROR;
}
return Status.OK;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Creates a private key from the file given, either in RSA private key
* (.pem) or pkcs8 (.der) format. Other formats will cause an exception to
* be thrown.
*/
public static PrivateKey loadPrivateKey(File privateKeyFile) throws InvalidKeySpecException, IOException {
if ( StringUtils.lowerCase(privateKeyFile.getAbsolutePath()).endsWith(".pem") ) {
InputStream is = new FileInputStream(privateKeyFile);
try {
return PEM.readPrivateKey(is);
} finally {
try {is.close();} catch(IOException ignore) {}
}
} else if ( StringUtils.lowerCase(privateKeyFile.getAbsolutePath()).endsWith(".der") ) {
InputStream is = new FileInputStream(privateKeyFile);
try {
return RSA.privateKeyFromPKCS8(IOUtils.toByteArray(is));
} finally {
try {is.close();} catch(IOException ignore) {}
}
} else {
throw new AmazonClientException("Unsupported file type for private key");
}
}
代码示例来源:origin: aws/aws-sdk-java
public GetIntrospectionSchemaResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetIntrospectionSchemaResult getIntrospectionSchemaResult = new GetIntrospectionSchemaResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getIntrospectionSchemaResult.setSchema(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getIntrospectionSchemaResult;
}
代码示例来源:origin: aws/aws-sdk-java
public DeleteThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DeleteThingShadowResult deleteThingShadowResult = new DeleteThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
deleteThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return deleteThingShadowResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetThingShadowResult getThingShadowResult = new GetThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getThingShadowResult;
}
代码示例来源:origin: aws/aws-sdk-java
public UpdateThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
UpdateThingShadowResult updateThingShadowResult = new UpdateThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
updateThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return updateThingShadowResult;
}
代码示例来源:origin: Netflix/conductor
@Test
public void tesGetWorkflowById() throws Exception {
when(executionDAO.getWorkflow(any(), anyBoolean())).thenReturn(new Workflow());
Workflow workflow = executionDAOFacade.getWorkflowById("workflowId", true);
assertNotNull(workflow);
verify(indexDAO, never()).get(any(), any());
when(executionDAO.getWorkflow(any(), anyBoolean())).thenReturn(null);
InputStream stream = ExecutionDAOFacadeTest.class.getResourceAsStream("/test.json");
byte[] bytes = IOUtils.toByteArray(stream);
String jsonString = new String(bytes);
when(indexDAO.get(any(), any())).thenReturn(jsonString);
workflow = executionDAOFacade.getWorkflowById("workflowId", true);
assertNotNull(workflow);
verify(indexDAO, times(1)).get(any(), any());
}
代码示例来源:origin: aws/aws-sdk-java
public GetSdkResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetSdkResult getSdkResult = new GetSdkResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getSdkResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Disposition") != null) {
context.setCurrentHeader("Content-Disposition");
getSdkResult.setContentDisposition(context.getUnmarshaller(String.class).unmarshall(context));
}
}
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getSdkResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getSdkResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetExportResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetExportResult getExportResult = new GetExportResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getExportResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Disposition") != null) {
context.setCurrentHeader("Content-Disposition");
getExportResult.setContentDisposition(context.getUnmarshaller(String.class).unmarshall(context));
}
}
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getExportResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getExportResult;
}
代码示例来源:origin: aws/aws-sdk-java
public InvokeEndpointResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeEndpointResult invokeEndpointResult = new InvokeEndpointResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
invokeEndpointResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("x-Amzn-Invoked-Production-Variant") != null) {
context.setCurrentHeader("x-Amzn-Invoked-Production-Variant");
invokeEndpointResult.setInvokedProductionVariant(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amzn-SageMaker-Custom-Attributes") != null) {
context.setCurrentHeader("X-Amzn-SageMaker-Custom-Attributes");
invokeEndpointResult.setCustomAttributes(context.getUnmarshaller(String.class).unmarshall(context));
}
}
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
invokeEndpointResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return invokeEndpointResult;
}
代码示例来源:origin: aws/aws-sdk-java
public InvokeResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeResult invokeResult = new InvokeResult();
if (context.isStartOfDocument()) {
if (context.getHeader("X-Amz-Function-Error") != null) {
context.setCurrentHeader("X-Amz-Function-Error");
invokeResult.setFunctionError(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amz-Log-Result") != null) {
context.setCurrentHeader("X-Amz-Log-Result");
invokeResult.setLogResult(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amz-Executed-Version") != null) {
context.setCurrentHeader("X-Amz-Executed-Version");
invokeResult.setExecutedVersion(context.getUnmarshaller(String.class).unmarshall(context));
}
}
invokeResult.setStatusCode(context.getHttpResponse().getStatusCode());
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
invokeResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return invokeResult;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
/**
* Reads and returns the rest of the given input stream as a string, closing
* the input stream afterwards.
* @param is the input stream.
* @return the rest of the given input stream.
*/
public static String toString(InputStream is) throws IOException {
return new String(toByteArray(is), StringUtils.UTF8);
}
代码示例来源:origin: com.amazonaws/aws-java-sdk-core
/**
* Reads and returns the rest of the given input stream as a string.
* Caller is responsible for closing the given input stream.
*/
public static String toString(InputStream is) throws IOException {
return new String(toByteArray(is), StringUtils.UTF8);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
public UpdateThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
UpdateThingShadowResult updateThingShadowResult = new UpdateThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
updateThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils
.toByteArray(is)));
}
return updateThingShadowResult;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
public DeleteThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DeleteThingShadowResult deleteThingShadowResult = new DeleteThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
deleteThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils
.toByteArray(is)));
}
return deleteThingShadowResult;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
public GetThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetThingShadowResult getThingShadowResult = new GetThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
getThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils
.toByteArray(is)));
}
return getThingShadowResult;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void test() throws Exception {
PutEventsRequest putEventsRequest = new PutEventsRequest();
List<Event> events = new ArrayList<Event>();
events.add(createEvent());
events.add(createEvent());
putEventsRequest.setEvents(events);
PutEventsRequestMarshaller marshaller = new PutEventsRequestMarshaller();
Request<PutEventsRequest> request = marshaller.marshall(putEventsRequest);
assertEquals("content encoding", "gzip", request.getHeaders().get("Content-Encoding"));
byte[] content = IOUtils.toByteArray(request.getContent());
System.out.println(content.length);
assertEquals("content length", request.getHeaders().get("Content-Length"),
String.valueOf(content.length));
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(content));
String str = IOUtils.toString(gis);
assertTrue("data is compressed", content.length < str.length());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public InvokeResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeResult invokeResult = new InvokeResult();
if (context.getHeader("X-Amz-Function-Error") != null)
invokeResult.setFunctionError(context.getHeader("X-Amz-Function-Error"));
if (context.getHeader("X-Amz-Log-Result") != null)
invokeResult.setLogResult(context.getHeader("X-Amz-Log-Result"));
invokeResult.setStatusCode(context.getHttpResponse().getStatusCode());
ByteBuffer payload = EMPTY_BYTEBUFFER;
InputStream content = context.getHttpResponse().getContent();
if (content != null) {
payload = ByteBuffer.wrap(IOUtils.toByteArray(content));
}
invokeResult.setPayload(payload);
return invokeResult;
}
内容来源于网络,如有侵权,请联系作者删除!