这就是我写 InputStream 的方法
public OutputStream getOutputStream(@Nonnull final String uniqueId) throws PersistenceException {
final PipedOutputStream outputStream = new PipedOutputStream();
final PipedInputStream inputStream;
try {
inputStream = new PipedInputStream(outputStream);
new Thread(
new Runnable() {
@Override
public void run() {
PutObjectRequest putObjectRequest = new PutObjectRequest("haritdev.sunrun", "sample.file.key", inputStream, new ObjectMetadata());
PutObjectResult result = amazonS3Client.putObject(putObjectRequest);
LOGGER.info("result - " + result.toString());
try {
inputStream.close();
} catch (IOException e) {
}
}
}
).start();
} catch (AmazonS3Exception e) {
throw new PersistenceException("could not generate output stream for " + uniqueId, e);
} catch (IOException e) {
throw new PersistenceException("could not generate input stream for S3 for " + uniqueId, e);
}
try {
return new GZIPOutputStream(outputStream);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new PersistenceException("Failed to get output stream for " + uniqueId + ": " + e.getMessage(), e);
}
}
在下面的方法中,我看到我的进程死了
protected <X extends AmazonWebServiceRequest> Request<X> createRequest(String bucketName, String key, X originalRequest, HttpMethodName httpMethod) { Request<X> request = new DefaultRequest<X>(originalRequest, Constants.S3_SERVICE_NAME); request.setHttpMethod(httpMethod); if (bucketNameUtils.isDNSBucketName(bucketName)) { request.setEndpoint(convertToVirtualHostEndpoint(bucketName)); request.setResourcePath(ServiceUtils.urlEncode(key)); } else { request.setEndpoint(endpoint); if (bucketName != null) { /* * We don't URL encode the bucket name, since it shouldn't * contain any characters that need to be encoded based on * Amazon S3's naming restrictions. */ request.setResourcePath(bucketName + "/" + (key != null ? ServiceUtils.urlEncode(key) : "")); } } return request; }
该过程在request.setResourcePath(ServiceUtils.urlEncode(key))上失败;因此我什至无法调试,即使密钥是有效名称并且不是NULL
有人可以帮忙吗?
这是request
临死前的样子
request = {com.amazonaws.DefaultRequest@1931}"PUT https://my.bucket.s3.amazonaws.com / "
resourcePath = null
parameters = {java.util.HashMap@1959} size = 0
headers = {java.util.HashMap@1963} size = 0
endpoint = {java.net.URI@1965}"https://my.bucket.s3.amazonaws.com"
serviceName = {java.lang.String@1910}"Amazon S3"
originalRequest = {com.amazonaws.services.s3.model.PutObjectRequest@1285}
httpMethod = {com.amazonaws.http.HttpMethodName@1286}"PUT"
content = null