vgritsenko    2002/08/16 21:00:56

  Modified:    src/java/org/apache/cocoon/environment/commandline Tag:
                        cocoon_2_0_3_branch LinkSamplingEnvironment.java
  Log:
  sync with head (explicitly close reader)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.1   +38 -35    
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.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- LinkSamplingEnvironment.java      22 Feb 2002 07:03:50 -0000      1.7
  +++ LinkSamplingEnvironment.java      17 Aug 2002 04:00:55 -0000      1.7.2.1
  @@ -67,33 +67,29 @@
    * @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
  -    {
  -        super( uri, Constants.LINK_VIEW, contextFile, new ByteArrayOutputStream(), 
log );
  +    public LinkSamplingEnvironment(String uri,
  +                                   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 );
  +            this.getLogger().debug("LinkSamplingEnvironment: uri = " + uri);
           }
  -        this.objectModel.put( ObjectModelHelper.REQUEST_OBJECT, new 
CommandLineRequest( this, null, uri, null, attributes, parameters ) );
  -        this.objectModel.put( ObjectModelHelper.RESPONSE_OBJECT, new 
CommandLineResponse() );
  +        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;
           }
       }
  @@ -101,24 +97,31 @@
       /**
        * 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;
  
  
  

----------------------------------------------------------------------
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