huber       2002/08/04 11:31:25

  Modified:    src/java/org/apache/cocoon/environment/commandline
                        LinkSamplingEnvironment.java
  Log:
  explicityl close BufferedReader at the end of processing the links
  
  Revision  Changes    Path
  1.9       +49 -47    
xml-cocoon2/src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
  
  Index: LinkSamplingEnvironment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LinkSamplingEnvironment.java      31 Jul 2002 13:13:28 -0000      1.8
  +++ LinkSamplingEnvironment.java      4 Aug 2002 18:31:25 -0000       1.9
  @@ -1,36 +1,36 @@
   /*
  -
  + 
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  -
  + 
    Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  -
  + 
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  -
  + 
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  -
  + 
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  -
  + 
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  -
  + 
    4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
       used to  endorse or promote  products derived from  this software without
       prior written permission. For written permission, please contact
       [EMAIL PROTECTED]
  -
  + 
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  -
  + 
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,13 +41,13 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  + 
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  + 
  + */
   package org.apache.cocoon.environment.commandline;
   
   import org.apache.avalon.framework.logger.Logger;
  @@ -68,18 +68,16 @@
    * @version CVS $Id$
    */
   
  -public class LinkSamplingEnvironment extends AbstractCommandLineEnvironment
  -{
  -
  +public class LinkSamplingEnvironment extends AbstractCommandLineEnvironment {
  +    
       private boolean skip = false;
  -
  +    
       public LinkSamplingEnvironment( String uri,
  -                                    File contextFile,
  -                                    Map attributes,
  -                                    Map parameters,
  -                                    Logger log )
  -    throws MalformedURLException, IOException
  -    {
  +    File contextFile,
  +    Map attributes,
  +    Map parameters,
  +    Logger log )
  +    throws MalformedURLException, IOException {
           super( uri, Constants.LINK_VIEW, contextFile, new ByteArrayOutputStream(), 
log );
           if (getLogger().isDebugEnabled()) {
               this.getLogger().debug( "LinkSamplingEnvironment: uri = " + uri );
  @@ -87,41 +85,45 @@
           this.objectModel.put( ObjectModelHelper.REQUEST_OBJECT, new 
CommandLineRequest( this, null, uri, null, attributes, parameters ) );
           this.objectModel.put( ObjectModelHelper.RESPONSE_OBJECT, new 
CommandLineResponse() );
       }
  -
  +    
       /**
        * Set the ContentType
        */
  -    public void setContentType( String contentType )
  -    {
  -        if ( ! Constants.LINK_CONTENT_TYPE.equals( contentType ) )
  -        {
  +    public void setContentType( String contentType ) {
  +        if ( ! Constants.LINK_CONTENT_TYPE.equals( contentType ) ) {
               this.skip = true;
           }
       }
  -
  +    
       /**
        * Indicates if other links are present.
        */
  -    public Collection getLinks() throws IOException
  -    {
  +    public Collection getLinks() throws IOException {
           ArrayList list = new ArrayList();
  -        if ( !skip )
  -        {
  -            BufferedReader buffer = new BufferedReader(
  -                                        new InputStreamReader(
  -                                            new ByteArrayInputStream(
  -                                                ( ( ByteArrayOutputStream ) 
super.stream ).toByteArray()
  -                                            )
  -                                        )
  -                                    );
  -            while ( true )
  -            {
  -                String line = buffer.readLine();
  -                if ( line == null )
  -                    break;
  -                list.add( line );
  +        if ( !skip ) {
  +            BufferedReader buffer = null;
  +            try {
  +                buffer = new BufferedReader(
  +                new InputStreamReader(
  +                new ByteArrayInputStream(
  +                ( ( ByteArrayOutputStream ) super.stream ).toByteArray())));
  +                
  +                while ( true ) {
  +                    String line = buffer.readLine();
  +                    if ( line == null )
  +                        break;
  +                    list.add( line );
  +                }
  +            } finally {
  +                // explictly close the input
  +                if (buffer != null) {
  +                    try {
  +                        buffer.close();
  +                        buffer = null;
  +                    } catch (IOException ignored) {}
  +                }
               }
           }
  -        return list;
  +        return list;        
       }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to