/** * Initialize this channel object for writing. * * @throws IOException */ public void initialize() throws IOException { // Create a pipe such that its one end is connected to the input stream used by // the uploader and the other end is the write channel used by the caller. PipedInputStream pipeSource = new PipedInputStream(pipeBufferSize); OutputStream pipeSink = new PipedOutputStream(pipeSource); pipeSinkChannel = Channels.newChannel(pipeSink); // Connect pipe-source to the stream used by uploader. InputStreamContent objectContentStream = new InputStreamContent(contentType, pipeSource); // Indicate that we do not know length of file in advance. objectContentStream.setLength(-1); objectContentStream.setCloseInputStream(false); T request = createRequest(objectContentStream); request.setDisableGZipContent(true); HttpHeaders headers = clientRequestHelper.getRequestHeaders(request); // Legacy check. Will be phased out. if (limitFileSizeTo250Gb) { headers.set("X-Goog-Upload-Max-Raw-Size", UPLOAD_MAX_SIZE); } // Change chunk size from default value (10MB) to one that yields higher performance. clientRequestHelper.setChunkSize(request, uploadChunkSize); // Given that the two ends of the pipe must operate asynchronous relative // to each other, we need to start the upload operation on a separate thread. uploadOperation = threadPool.submit(new UploadOperation(request, pipeSource)); isInitialized = true; }
/** * Initialize this channel object for writing. * * @throws IOException */ public void initialize() throws IOException { // Create a pipe such that its one end is connected to the input stream used by // the uploader and the other end is the write channel used by the caller. PipedInputStream pipeSource = new PipedInputStream(pipeBufferSize); OutputStream pipeSink = new PipedOutputStream(pipeSource); pipeSinkChannel = Channels.newChannel(pipeSink); // Connect pipe-source to the stream used by uploader. InputStreamContent objectContentStream = new InputStreamContent(contentType, pipeSource); // Indicate that we do not know length of file in advance. objectContentStream.setLength(-1); objectContentStream.setCloseInputStream(false); T request = createRequest(objectContentStream); request.setDisableGZipContent(true); HttpHeaders headers = clientRequestHelper.getRequestHeaders(request); // Legacy check. Will be phased out. if (limitFileSizeTo250Gb) { headers.set("X-Goog-Upload-Max-Raw-Size", UPLOAD_MAX_SIZE); } // Change chunk size from default value (10MB) to one that yields higher performance. clientRequestHelper.setChunkSize(request, uploadChunkSize); // Given that the two ends of the pipe must operate asynchronous relative // to each other, we need to start the upload operation on a separate thread. uploadOperation = threadPool.submit(new UploadOperation(request, pipeSource)); isInitialized = true; }
contentChunk = new InputStreamContent( mediaContent.getType(), limitInputStream).setRetrySupported(true) .setLength(blockSize).setCloseInputStream(false); mediaContentLengthStr = String.valueOf(getMediaContentLength()); } else {