You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2003/04/04 15:59:58 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/content NodeRevisionContent.java

juergen     2003/04/04 05:59:58

  Modified:    src/share/org/apache/slide/content NodeRevisionContent.java
  Log:
  read via a buffer to avoid reading single characters.
  
  Revision  Changes    Path
  1.11      +66 -55    jakarta-slide/src/share/org/apache/slide/content/NodeRevisionContent.java
  
  Index: NodeRevisionContent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeRevisionContent.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- NodeRevisionContent.java	25 Apr 2002 21:30:13 -0000	1.10
  +++ NodeRevisionContent.java	4 Apr 2003 13:59:57 -0000	1.11
  @@ -63,11 +63,18 @@
   
   package org.apache.slide.content;
   
  -import java.io.*;
  -import java.util.Date;
  -import java.util.List;
  +import java.io.BufferedInputStream;
  +import java.io.BufferedReader;
  +import java.io.ByteArrayInputStream;
  +import java.io.CharArrayReader;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.InputStreamReader;
  +import java.io.Reader;
  +import java.io.Serializable;
   import java.util.ArrayList;
  -import org.apache.slide.common.*;
  +import java.util.List;
  +import org.apache.slide.common.ObjectValidationFailedException;
   import org.apache.slide.util.Messages;
   
   /**
  @@ -78,39 +85,39 @@
    * @version $Revision$
    */
   public final class NodeRevisionContent implements Serializable {
  -    
  -    
  +
  +
       // -------------------------------------------------------------- Constants
  -    
  -    
  +
  +
       private static final int CHUNK = 1024*4;
  -    
  -    
  +
  +
       // ----------------------------------------------------- Instance Variables
  -    
  -    
  +
  +
       /**
        * Content.
        */
       private char[] content = null;
       private byte[] contentBytes = null;
  -    
  -    
  +
  +
       /**
        * Reader.
        */
       private transient Reader reader = null;
  -    
  -    
  +
  +
       /**
        * Input stream.
        */
       private transient InputStream inputStream = null;
  -    
  -    
  +
  +
       // ------------------------------------------------------------- Properties
  -    
  -    
  +
  +
       /**
        * Content accessor.
        *
  @@ -152,7 +159,7 @@
           }
           return result;
       }
  -    
  +
       /**
        * Content accessor.
        *
  @@ -194,9 +201,9 @@
           }
           return result;
       }
  -    
  -    
  -    
  +
  +
  +
       /**
        * Content accessor.
        *
  @@ -225,8 +232,8 @@
           }
           return result;
       }
  -    
  -    
  +
  +
       /**
        * Content accessor.
        *
  @@ -258,8 +265,8 @@
           }
           return result;
       }
  -    
  -    
  +
  +
       /**
        * Content mutator.
        *
  @@ -271,7 +278,7 @@
           this.inputStream = null;
           this.content = null;
       }
  -    
  +
       /**
        * Content mutator.
        *
  @@ -283,8 +290,8 @@
           this.inputStream = null;
           this.contentBytes = null;
       }
  -    
  -    
  +
  +
       /**
        * Content mutator.
        *
  @@ -296,8 +303,8 @@
           this.content = null;
           this.contentBytes = null;
       }
  -    
  -    
  +
  +
       /**
        * Content mutator.
        *
  @@ -309,27 +316,27 @@
           this.content = null;
           this.contentBytes = null;
       }
  -    
  -    
  +
  +
       // TODO : Add real serialization support
   
  -    
  +
       /**
        * Validate.
        */
       public void validate() {
  -        
  +
           if ((content == null) && (contentBytes == null) && (reader == null) && (inputStream == null))
               throw new ObjectValidationFailedException
                   (Messages.message
                    (NodeRevisionContent.class.getName() + ".noContent"));
  -        
  +
       }
  -    
  -    
  +
  +
       // -------------------------------------------------------- Private Methods
  -    
  -    
  +
  +
       /**
        * Read the data from the stream and return the result in a byte array.
        * Return null in case of an error.
  @@ -343,7 +350,8 @@
           int i;
           int max;
           int ofs;
  -        
  +
  +        inputStream = new BufferedInputStream(inputStream);
           allLen = 0;
           chunk = new byte[CHUNK];
           chunkLen = inputStream.read(chunk);
  @@ -352,6 +360,8 @@
               chunks.add(new Integer(chunkLen));
               chunks.add(chunk);
               allLen += chunkLen;
  +//            if (chunkLen < 100) System.out.println("######## " + chunkLen);
  +//            if (allLen > 400000) System.out.println("#### " + allLen);
               chunk = new byte[CHUNK];
               chunkLen = inputStream.read(chunk);
           }
  @@ -367,10 +377,10 @@
           }
           return all;
       }
  -    
  -    
  -    
  -    
  +
  +
  +
  +
       /**
        * Read the data from the reader and return the result in a char array.
        * Return null in case of an error.
  @@ -384,7 +394,8 @@
           int i;
           int max;
           int ofs;
  -        
  +
  +        reader = new BufferedReader(reader);
           allLen = 0;
           chunk = new char[CHUNK];
           chunkLen = reader.read(chunk);
  @@ -396,7 +407,7 @@
               chunk = new char[CHUNK];
               chunkLen = reader.read(chunk);
           }
  -        
  +
           all = new char[allLen];
           ofs = 0;
           max = chunks.size();
  @@ -408,6 +419,6 @@
           }
           return all;
       }
  -    
  -    
  +
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org