avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder ContainmentProfileBuilder.java
Date Fri, 22 Aug 2003 12:46:41 GMT
mcconnell    2003/08/22 05:46:41

  Modified:    merlin/composition/src/java/org/apache/avalon/composition/data/builder
                        ContainmentProfileBuilder.java
  Log:
  Update applied to composition profile builder to better handle potential input stream corruption
case.
  
  Revision  Changes    Path
  1.4       +14 -6     avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/ContainmentProfileBuilder.java
  
  Index: ContainmentProfileBuilder.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/ContainmentProfileBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ContainmentProfileBuilder.java	21 Aug 2003 19:37:42 -0000	1.3
  +++ ContainmentProfileBuilder.java	22 Aug 2003 12:46:41 -0000	1.4
  @@ -51,6 +51,8 @@
   package org.apache.avalon.composition.data.builder;
   
   import java.io.InputStream;
  +import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
   
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -96,9 +98,15 @@
        public ContainmentProfile createContainmentProfile( InputStream inputStream )
           throws Exception
       {
  -        byte[] buffer = new byte[1024*32];
  -        int read = inputStream.read( buffer );
  -        inputStream = new ByteArrayInputStream(buffer, 0, read );
  +        // we backup the inputstream content in a bytearray
  +        final byte[] buffer = new byte[1024];
  +        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +        for( int read = 0; read >= 0; )
  +        {
  +            baos.write( buffer, 0, read );
  +            read = inputStream.read( buffer );
  +        }
  +        inputStream = new ByteArrayInputStream( baos.toByteArray() );
           
           try
           {
  @@ -118,10 +126,10 @@
               // sooner or later we will need to update the serialized 
               // to return null if the source isn' a serialized source
   
  -            inputStream = new ByteArrayInputStream( buffer, 0, read );
  +            inputStream = new ByteArrayInputStream( baos.toByteArray() );
   
           }
  -
  +        
           return buildFromXMLDescriptor( inputStream );
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message