本文整理汇总了Java中com.amazonaws.util.StringInputStream类的典型用法代码示例。如果您正苦于以下问题:Java StringInputStream类的具体用法?Java StringInputStream怎么用?Java StringInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringInputStream类属于com.amazonaws.util包,在下文中一共展示了StringInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toTriple
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
/**
* This method converts a string (in n-triples format) into a Jena triple
*
* @param string containing single n-triples triple
* @return Triple
*/
public static Triple toTriple(final String string) {
// Create Jena model
Model inputModel = createDefaultModel();
try {
// Load model with arg string (expecting n-triples)
inputModel = inputModel.read(new StringInputStream(string), null, strLangNTriples);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
// Since there is only one statement, get it
final Statement stmt = inputModel.listStatements().nextStatement();
// Return the Jena triple which the statement represents
return stmt.asTriple();
}
示例2: testStoreValue
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Test
public void testStoreValue()
throws BinaryStoreException, UnsupportedEncodingException {
String valueToStore = "value-to-store";
expect(s3Client.doesObjectExist(eq(BUCKET), isA(String.class))).andReturn(false);
Capture<ObjectMetadata> objMetaCapture = Capture.newInstance();
expect(s3Client.putObject(eq(BUCKET), isA(String.class),
isA(InputStream.class), capture(objMetaCapture)))
.andReturn(null);
replayAll();
s3BinaryStore.storeValue(new StringInputStream(valueToStore), false);
ObjectMetadata objMeta = objMetaCapture.getValue();
assertEquals(String.valueOf(false),
objMeta.getUserMetadata().get(s3BinaryStore.UNUSED_KEY));
}
示例3: testStoreValueExisting
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Test
public void testStoreValueExisting() throws BinaryStoreException, IOException {
String valueToStore = "value-to-store";
expect(s3Client.doesObjectExist(eq(BUCKET), isA(String.class))).andReturn(true);
expect(s3Client.getObjectMetadata(eq(BUCKET), isA(String.class)))
.andReturn(new ObjectMetadata());
ObjectMetadata objMeta = new ObjectMetadata();
Map<String, String> userMeta = new HashMap<>();
userMeta.put(s3BinaryStore.UNUSED_KEY, String.valueOf(true));
objMeta.setUserMetadata(userMeta);
Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance();
expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null);
replayAll();
s3BinaryStore.storeValue(new StringInputStream(valueToStore), true);
ObjectMetadata newObjMeta = copyRequestCapture.getValue().getNewObjectMetadata();
assertEquals(String.valueOf(true),
newObjMeta.getUserMetadata().get(s3BinaryStore.UNUSED_KEY));
}
示例4: main
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// create the AWS S3 Client
AmazonS3 s3 = AWSS3Factory.getS3Client();
// retrieve the object key and new object value from user
System.out.println( "Enter the object key:" );
String key = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
System.out.println( "Enter new object content:" );
String content = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
// update the object in the demo bucket
PutObjectRequest updateRequest = new PutObjectRequest(AWSS3Factory.S3_BUCKET, key,
new StringInputStream(content), null);
s3.putObject(updateRequest);
// print out object key/value for validation
System.out.println( String.format("update object [%s/%s] with new content: [%s]",
AWSS3Factory.S3_BUCKET, key, content));
}
示例5: getObject
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Override
public S3Object getObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException {
assertEquals("mycamelbucket", bucketName);
assertEquals("key", key);
S3Object s3Object = new S3Object();
s3Object.setBucketName(bucketName);
s3Object.setKey(key);
try {
s3Object.setObjectContent(new StringInputStream("Camel rocks!"));
} catch (UnsupportedEncodingException e) {
// noop
}
return s3Object;
}
示例6: createUploadDocumentsRequest
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
private List<UploadDocumentsRequest> createUploadDocumentsRequest(List<Document> docs) {
List<String> parts = chunkedJson(docs);
List<UploadDocumentsRequest> uploadDocumentRequests = new ArrayList<>(parts.size());
for (String part : parts) {
try (StringInputStream documents = new StringInputStream(part)) {
UploadDocumentsRequest uploadDocumentsRequest = new UploadDocumentsRequest(). //
withDocuments(documents). //
withContentLength((long) part.length()). //
withContentType(Applicationjson);
if (progressListener != null) {
uploadDocumentsRequest.setGeneralProgressListener(progressListener);
}
uploadDocumentRequests.add(uploadDocumentsRequest);
} catch (IOException e) {
log.warn("this should never happen", e);
}
}
return uploadDocumentRequests;
}
示例7: cloneCurrentModel
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
private Deployment cloneCurrentModel(){
//need to clone the model
JsonCodec jsonCodec=new JsonCodec();
ByteArrayOutputStream baos=new ByteArrayOutputStream();
jsonCodec.save(currentModel,baos);
Deployment targetModel=new Deployment();
try {
String aString = new String(baos.toByteArray(),"UTF-8");
InputStream is = new StringInputStream(aString);
targetModel = (Deployment) jsonCodec.load(is);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return targetModel;
}
示例8: assignContent
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
private void assignContent(Request request, Object representation) {
String contentString = new JSONObject(representation).toString();
if (contentString == null) {
throw new AmazonClientException("Unable to marshall representation to JSON: " + representation);
}
try {
byte[] contentBytes = contentString.getBytes("UTF-8");
request.setContent(new StringInputStream(contentString));
request.addHeader("Content-Length", Integer.toString(contentBytes.length));
request.addHeader("Content-Type", "application/json");
} catch(Throwable t) {
throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
}
}
示例9: storeObject
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
public static void storeObject(String contentType,
String content,
String destBucket,
String destKey) throws UnsupportedEncodingException {
AmazonS3 s3Client = AmazonS3Provider.getS3Client();
ObjectMetadata metadata = prepareObjectMetadata(contentType, content);
s3Client.putObject(
destBucket,
destKey,
new StringInputStream(content),
metadata);
}
示例10: adapt
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Override
public InputStream adapt(String source) {
if (source == null) {
return null;
}
try {
return new StringInputStream(source);
} catch (UnsupportedEncodingException e) {
throw new SdkClientException(e);
}
}
示例11: query_params_in_uri_for_post_request_with_payload
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Test
public void query_params_in_uri_for_post_request_with_payload() throws IOException, URISyntaxException {
final Request<Object> request = newDefaultRequest(HttpMethodName.POST);
request.withParameter("foo", "bar");
final String payload = "dummy string stream";
request.setContent(new StringInputStream(payload));
HttpRequestBase requestBase = requestFactory.create(request, settings);
Assert.assertThat(requestBase, Matchers.instanceOf(HttpPost
.class));
Assert.assertEquals("foo=bar", requestBase.getURI().getQuery());
Assert.assertThat(requestBase, Matchers.instanceOf(HttpPost
.class));
Assert.assertEquals(payload, IOUtils.toString(((HttpPost)requestBase).getEntity().getContent()));
}
示例12: request_has_default_content_type_set_when_not_explicitly_set
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Test
public void request_has_default_content_type_set_when_not_explicitly_set() throws IOException,
URISyntaxException {
final Request<Object> request = newDefaultRequest(HttpMethodName.POST);
request.setContent(new StringInputStream("dummy string stream"));
HttpRequestBase requestBase = requestFactory.create(request, settings);
assertContentTypeContains("application/x-www-form-urlencoded",
requestBase.getHeaders(CONTENT_TYPE));
}
示例13: apache_request_has_content_type_set_when_not_explicitly_set
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Test
public void apache_request_has_content_type_set_when_not_explicitly_set() throws IOException,
URISyntaxException {
final Request<Object> request = newDefaultRequest(HttpMethodName.POST);
final String testContentype = "testContentType";
request.addHeader(HttpHeaders.CONTENT_TYPE, testContentype);
request.setContent(new StringInputStream("dummy string stream"));
HttpRequestBase requestBase = requestFactory.create(request, settings);
assertContentTypeContains(testContentype,
requestBase.getHeaders(CONTENT_TYPE));
}
示例14: setEntity
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
private static void setEntity(HttpResponse response, String content) {
try {
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new StringInputStream(content));
response.setEntity(entity);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
示例15: setup
import com.amazonaws.util.StringInputStream; //导入依赖的package包/类
@Before
public void setup() throws UnsupportedEncodingException {
MockitoAnnotations.initMocks(this);
when(errorCodeParser
.parseErrorCode((HttpResponse) anyObject(), (JsonContent) anyObject()))
.thenReturn(ERROR_CODE);
httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null);
httpResponse.setContent(new StringInputStream("{}"));
responseHandler = new JsonErrorResponseHandler(Arrays.asList(unmarshaller), errorCodeParser,
JsonErrorMessageParser.DEFAULT_ERROR_MESSAGE_PARSER,
new JsonFactory());
}