public VoidResult writeGetObjectResponse()

in src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java [1292:1354]


    public VoidResult writeGetObjectResponse(WriteGetObjectResponseRequest writeGetObjectResponseRequest) throws OSSException, ClientException {

        assertParameterNotNull(writeGetObjectResponseRequest, "writeGetObjectResponseRequest");
        assertParameterNotNull(writeGetObjectResponseRequest.getRoute(), "route");

        ObjectMetadata metadata = writeGetObjectResponseRequest.getMetadata();
        Map<String, String> params = new HashMap<String, String>();
        params.put(WRITE_GET_OBJECT_RESPONSE, null);

        if (metadata == null) {
            metadata = new ObjectMetadata();
        }

        Map<String, String> headers = writeGetObjectResponseRequest.getHeaders();
        addHeaderIfNotNull(headers, OSSHeaders.OSS_REQUEST_ROUTE, writeGetObjectResponseRequest.getRoute());
        addHeaderIfNotNull(headers, OSSHeaders.OSS_REQUEST_TOKEN, writeGetObjectResponseRequest.getToken());
        addHeaderIfNotNull(headers, OSSHeaders.OSS_FWD_STATUS, String.valueOf(writeGetObjectResponseRequest.getStatus()));
        populateRequestMetadata(headers, metadata);


        InputStream originalInputStream = writeGetObjectResponseRequest.getInputStream();
        InputStream repeatableInputStream = null;
        if (writeGetObjectResponseRequest.getFile() != null) {
            File toUpload = writeGetObjectResponseRequest.getFile();

            if (!checkFile(toUpload)) {
                getLog().info("Illegal file path: " + toUpload.getPath());
                throw new ClientException("Illegal file path: " + toUpload.getPath());
            }

            metadata.setContentLength(toUpload.length());

            try {
                repeatableInputStream = new RepeatableFileInputStream(toUpload);
            } catch (IOException ex) {
                logException("Cannot locate file to upload: ", ex);
                throw new ClientException("Cannot locate file to upload: ", ex);
            }
        } else {
            assertTrue(originalInputStream != null, "Please specify input stream or file to upload");
            try {
                metadata.setContentLength(Long.valueOf(originalInputStream.available()));
                repeatableInputStream = newRepeatableInputStream(originalInputStream);
            } catch (IOException ex) {
                logException("Cannot wrap to repeatable input stream: ", ex);
                throw new ClientException("Cannot wrap to repeatable input stream: ", ex);
            }
        }

        Long contentLength = (Long) metadata.getRawMetadata().get(OSSHeaders.CONTENT_LENGTH);
        contentLength = contentLength == null ? -1 : contentLength.longValue();

        if (contentLength < 0 || !repeatableInputStream.markSupported()) {
            contentLength = Long.valueOf(-1);
        }

        RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(OSSUtils.toEndpointURI(writeGetObjectResponseRequest.getRoute(), this.client.getClientConfiguration().getProtocol().toString()))
                .setMethod(HttpMethod.POST).setParameters(params).setHeaders(headers)
                .setInputStream(repeatableInputStream).setInputSize(contentLength)
                .setOriginalRequest(writeGetObjectResponseRequest).build();

        return doOperation(request, requestIdResponseParser, null, null, true);
    }