@ DoesServiceRequest private synchronized void dispatchWrite ( final int writeLength ) throws IOException { if ( writeLength == 0 ) { return ; } Callable < Void > worker = null ; if ( this . outstandingRequests > this . options . getConcurrentRequestCount ( ) * 2 ) { this . waitForTaskToComplete ( ) ; } final ByteArrayInputStream bufferRef = new ByteArrayInputStream ( this . outBuffer . toByteArray ( ) ) ; final CloudFile fileRef = this . parentFileRef ; long tempOffset = this . currentOffset ; long tempLength = writeLength ; final long opWriteLength = tempLength ; final long opOffset = tempOffset ; this . currentOffset += writeLength ; worker = new Callable < Void > ( ) { @ Override public Void call ( ) { try { fileRef . uploadRange ( bufferRef , opOffset , opWriteLength , FileOutputStream . this . accessCondition , FileOutputStream . this . options , FileOutputStream . this . opContext ) ; } catch ( final IOException e ) { synchronized ( FileOutputStream . this . lastErrorLock ) { FileOutputStream . this . streamFaulted = true ; FileOutputStream . this . lastError = e ; } } catch ( final StorageException e ) { synchronized ( FileOutputStream . this . lastErrorLock ) { FileOutputStream . this . streamFaulted = true ; FileOutputStream . this . lastError = Utility . initIOException ( e ) ; } } catch ( URISyntaxException e ) { synchronized ( FileOutputStream . this . lastErrorLock ) { FileOutputStream . this . streamFaulted = true ; FileOutputStream . this . lastError = Utility . initIOException ( e ) ; } } return null ; } } ; // Do work and reset buffer. this . completionService . submit ( worker ) ; this . outstandingRequests ++ ; this . currentBufferedBytes = 0 ; this . outBuffer = new ByteArrayOutputStream ( ) ; }
Dispatches a write operation for a given length .