public void writeTo()

in wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java [192:244]


        public void writeTo( final OutputStream output )
            throws IOException
        {
            if ( output == null )
            {
                throw new NullPointerException( "output cannot be null" );
            }
            TransferEvent transferEvent =
                new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
            transferEvent.setTimestamp( System.currentTimeMillis() );

            try ( ReadableByteChannel input = ( this.source != null )
                    ? new RandomAccessFile( this.source, "r" ).getChannel()
                    : Channels.newChannel( stream ) )
            {
                ByteBuffer buffer = ByteBuffer.allocate( getBufferCapacityForTransfer( this.length ) );
                int halfBufferCapacity = buffer.capacity() / 2;

                long remaining = this.length < 0L ? Long.MAX_VALUE : this.length;
                while ( remaining > 0L )
                {
                    int read = input.read( buffer );
                    if ( read == -1 )
                    {
                        // EOF, but some data has not been written yet.
                        if ( ( (Buffer) buffer ).position() != 0 )
                        {
                            ( (Buffer) buffer ).flip();
                            fireTransferProgress( transferEvent, buffer.array(), ( (Buffer) buffer ).limit() );
                            output.write( buffer.array(), 0, ( (Buffer) buffer ).limit() );
                            ( (Buffer) buffer ).clear();
                        }

                        break;
                    }

                    // Prevent minichunking/fragmentation: when less than half the buffer is utilized,
                    // read some more bytes before writing and firing progress.
                    if ( ( (Buffer) buffer ).position() < halfBufferCapacity )
                    {
                        continue;
                    }

                    ( (Buffer) buffer ).flip();
                    fireTransferProgress( transferEvent, buffer.array(), ( (Buffer) buffer ).limit() );
                    output.write( buffer.array(), 0, ( (Buffer) buffer ).limit() );
                    remaining -= ( (Buffer) buffer ).limit();
                    ( (Buffer) buffer ).clear();

                }
                output.flush();
            }
        }