|
32 | 32 | import static com.aliyun.oss.internal.OSSConstants.DEFAULT_BUFFER_SIZE; |
33 | 33 | import static com.aliyun.oss.internal.OSSConstants.DEFAULT_CHARSET_NAME; |
34 | 34 | import static com.aliyun.oss.internal.OSSHeaders.OSS_SELECT_OUTPUT_RAW; |
35 | | -import static com.aliyun.oss.internal.OSSUtils.OSS_RESOURCE_MANAGER; |
36 | | -import static com.aliyun.oss.internal.OSSUtils.addDateHeader; |
37 | | -import static com.aliyun.oss.internal.OSSUtils.addHeader; |
38 | | -import static com.aliyun.oss.internal.OSSUtils.addStringListHeader; |
39 | | -import static com.aliyun.oss.internal.OSSUtils.determineInputStreamLength; |
40 | | -import static com.aliyun.oss.internal.OSSUtils.ensureBucketNameValid; |
41 | | -import static com.aliyun.oss.internal.OSSUtils.ensureObjectKeyValid; |
42 | | -import static com.aliyun.oss.internal.OSSUtils.ensureCallbackValid; |
43 | | -import static com.aliyun.oss.internal.OSSUtils.joinETags; |
44 | | -import static com.aliyun.oss.internal.OSSUtils.populateRequestMetadata; |
45 | | -import static com.aliyun.oss.internal.OSSUtils.populateResponseHeaderParameters; |
46 | | -import static com.aliyun.oss.internal.OSSUtils.populateRequestCallback; |
47 | | -import static com.aliyun.oss.internal.OSSUtils.removeHeader; |
48 | | -import static com.aliyun.oss.internal.OSSUtils.safeCloseResponse; |
49 | | -import static com.aliyun.oss.internal.RequestParameters.ENCODING_TYPE; |
50 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_ACL; |
51 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_DELETE; |
52 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_OBJECTMETA; |
53 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_SYMLINK; |
54 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_TAGGING; |
55 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_DIR; |
56 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_RENAME; |
57 | | -import static com.aliyun.oss.internal.RequestParameters.SUBRESOURCE_DIR_DELETE; |
| 35 | +import static com.aliyun.oss.internal.OSSUtils.*; |
| 36 | +import static com.aliyun.oss.internal.RequestParameters.*; |
58 | 37 | import static com.aliyun.oss.internal.ResponseParsers.appendObjectResponseParser; |
59 | 38 | import static com.aliyun.oss.internal.ResponseParsers.copyObjectResponseParser; |
60 | 39 | import static com.aliyun.oss.internal.ResponseParsers.deleteObjectsResponseParser; |
@@ -1312,6 +1291,76 @@ public AsyncProcessObjectResult asyncProcessObject(AsyncProcessObjectRequest asy |
1312 | 1291 | return doOperation(request, ResponseParsers.asyncProcessObjectResponseParser, bucketName, key, true); |
1313 | 1292 | } |
1314 | 1293 |
|
| 1294 | + public VoidResult writeGetObjectResponse(WriteGetObjectResponseRequest writeGetObjectResponseRequest) throws OSSException, ClientException { |
| 1295 | + |
| 1296 | + assertParameterNotNull(writeGetObjectResponseRequest, "writeGetObjectResponseRequest"); |
| 1297 | + assertParameterNotNull(writeGetObjectResponseRequest.getRoute(), "route"); |
| 1298 | + |
| 1299 | + ObjectMetadata metadata = writeGetObjectResponseRequest.getMetadata(); |
| 1300 | + Map<String, String> params = new HashMap<String, String>(); |
| 1301 | + params.put(WRITE_GET_OBJECT_RESPONSE, null); |
| 1302 | + |
| 1303 | + if (metadata == null) { |
| 1304 | + metadata = new ObjectMetadata(); |
| 1305 | + } |
| 1306 | + |
| 1307 | + Map<String, String> headers = writeGetObjectResponseRequest.getHeaders(); |
| 1308 | + addHeaderIfNotNull(headers, OSSHeaders.OSS_REQUEST_ROUTE, writeGetObjectResponseRequest.getRoute()); |
| 1309 | + addHeaderIfNotNull(headers, OSSHeaders.OSS_REQUEST_TOKEN, writeGetObjectResponseRequest.getToken()); |
| 1310 | + addHeaderIfNotNull(headers, OSSHeaders.OSS_FWD_STATUS, String.valueOf(writeGetObjectResponseRequest.getStatus())); |
| 1311 | + populateRequestMetadata(headers, metadata); |
| 1312 | + |
| 1313 | + |
| 1314 | + InputStream originalInputStream = writeGetObjectResponseRequest.getInputStream(); |
| 1315 | + InputStream repeatableInputStream = null; |
| 1316 | + if (writeGetObjectResponseRequest.getFile() != null) { |
| 1317 | + File toUpload = writeGetObjectResponseRequest.getFile(); |
| 1318 | + |
| 1319 | + if (!checkFile(toUpload)) { |
| 1320 | + getLog().info("Illegal file path: " + toUpload.getPath()); |
| 1321 | + throw new ClientException("Illegal file path: " + toUpload.getPath()); |
| 1322 | + } |
| 1323 | + |
| 1324 | + metadata.setContentLength(toUpload.length()); |
| 1325 | + |
| 1326 | + try { |
| 1327 | + repeatableInputStream = new RepeatableFileInputStream(toUpload); |
| 1328 | + } catch (IOException ex) { |
| 1329 | + logException("Cannot locate file to upload: ", ex); |
| 1330 | + throw new ClientException("Cannot locate file to upload: ", ex); |
| 1331 | + } |
| 1332 | + } else { |
| 1333 | + assertTrue(originalInputStream != null, "Please specify input stream or file to upload"); |
| 1334 | + try { |
| 1335 | + metadata.setContentLength(Long.valueOf(originalInputStream.available())); |
| 1336 | + repeatableInputStream = newRepeatableInputStream(originalInputStream); |
| 1337 | + } catch (IOException ex) { |
| 1338 | + logException("Cannot wrap to repeatable input stream: ", ex); |
| 1339 | + throw new ClientException("Cannot wrap to repeatable input stream: ", ex); |
| 1340 | + } |
| 1341 | + } |
| 1342 | + |
| 1343 | + Long contentLength = (Long) metadata.getRawMetadata().get(OSSHeaders.CONTENT_LENGTH); |
| 1344 | + contentLength = contentLength == null ? -1 : contentLength.longValue(); |
| 1345 | + |
| 1346 | + if (contentLength < 0 || !repeatableInputStream.markSupported()) { |
| 1347 | + contentLength = Long.valueOf(-1); |
| 1348 | + } |
| 1349 | + |
| 1350 | + RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(OSSUtils.toEndpointURI(writeGetObjectResponseRequest.getRoute(), this.client.getClientConfiguration().getProtocol().toString())) |
| 1351 | + .setMethod(HttpMethod.POST).setParameters(params).setHeaders(headers) |
| 1352 | + .setInputStream(repeatableInputStream).setInputSize(contentLength) |
| 1353 | + .setOriginalRequest(writeGetObjectResponseRequest).build(); |
| 1354 | + |
| 1355 | + return doOperation(request, requestIdResponseParser, null, null, true); |
| 1356 | + } |
| 1357 | + |
| 1358 | + private static void addHeaderIfNotNull(Map<String, String> headers, String header, String value) { |
| 1359 | + if (value != null) { |
| 1360 | + headers.put(header, value); |
| 1361 | + } |
| 1362 | + } |
| 1363 | + |
1315 | 1364 | private static void addDeleteObjectsRequiredHeaders(Map<String, String> headers, byte[] rawContent) { |
1316 | 1365 | headers.put(HttpHeaders.CONTENT_LENGTH, String.valueOf(rawContent.length)); |
1317 | 1366 |
|
|
0 commit comments