public void writeTo()

in common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java [896:948]


        public void writeTo( final OutputStream outstream )
            throws IOException
        {
            long completed = 0;
            if ( outstream == null )
            {
                throw new IllegalArgumentException( "Output stream may not be null" );
            }
            FileInputStream stream = new FileInputStream( this.file );
            transferInitiated( this.url );
            this.startTime = System.currentTimeMillis();
            try
            {
                byte[] buffer = new byte[BUFFER_SIZE];

                int l;
                if ( this.length < 0 )
                {
                    // until EOF
                    while ( ( l = stream.read( buffer ) ) != -1 )
                    {
                        transferProgressed( completed += buffer.length, -1 );
                        outstream.write( buffer, 0, l );
                    }
                }
                else
                {
                    // no need to consume more than length
                    long remaining = this.length;
                    while ( remaining > 0 )
                    {
                        int transferSize = (int) Math.min( BUFFER_SIZE, remaining );
                        completed += transferSize;
                        l = stream.read( buffer, 0, transferSize );
                        if ( l == -1 )
                        {
                            break;
                        }

                        outstream.write( buffer, 0, l );
                        remaining -= l;
                        transferProgressed( completed, this.length );
                    }
                }
                transferSucceeded( completed );
            }
            finally
            {
                stream.close();
                out.println();
            }
            // end transfer
        }