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 ) ; // 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 .