protected void doGet()

in wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/LatencyServlet.java [57:126]


    protected void doGet( final HttpServletRequest req, final HttpServletResponse resp )
        throws ServletException, IOException
    {
        if ( latencyMs < 0 )
        {
            logger.info( "Starting infinite wait." );
            synchronized ( this )
            {
                try
                {
                    wait();
                }
                catch ( InterruptedException e )
                {
                    // ignore
                }
            }

            return;
        }

        String path = req.getPathInfo();

        // ignore the servlet's path here, since the servlet path is really only to provide a
        // binding for the servlet.
        String realPath = getServletContext().getRealPath( path );
        File f = new File( realPath );

        FileInputStream in = null;
        long total = 0;
        long start = System.currentTimeMillis();
        try
        {
            in = new FileInputStream( f );
            OutputStream out = resp.getOutputStream();

            logger.info( "Starting high-latency transfer. This should take about "
                + ( ( f.length() / BUFFER_SIZE * latencyMs / 1000 ) + ( latencyMs / 1000 ) ) + " seconds." );

            int read;
            byte[] buf = new byte[BUFFER_SIZE];
            while ( ( read = in.read( buf ) ) > -1 )
            {
                try
                {
                    Thread.sleep( latencyMs );
                }
                catch ( InterruptedException e )
                {
                    e.printStackTrace();
                }

                logger.info( "Writing bytes " + total + "-" + ( total + read - 1 ) + " of " + f.length()
                    + ". Elapsed time so far: " + ( ( System.currentTimeMillis() - start ) / 1000 ) + " seconds" );

                out.write( buf, 0, read );

                total += read;
            }

            in.close();
            in = null;
        }
        finally
        {
            IOUtil.close( in );
        }

        logger.info( "High-latency transfer done in " + ( System.currentTimeMillis() - start ) + "ms" );
    }