cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hu...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/reading ImageReader.java
Date Fri, 12 Dec 2003 09:41:33 GMT
huber       2003/12/12 01:41:33

  Modified:    src/java/org/apache/cocoon/reading ImageReader.java
  Log:
  use faster transformation iff java 1.4 is present
  fix Bugzilla Bug 25069, close inputStream in finally block
  
  Revision  Changes    Path
  1.4       +55 -9     cocoon-2.1/src/java/org/apache/cocoon/reading/ImageReader.java
  
  Index: ImageReader.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/reading/ImageReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ImageReader.java	24 Sep 2003 21:41:11 -0000	1.3
  +++ ImageReader.java	12 Dec 2003 09:41:33 -0000	1.4
  @@ -202,19 +202,31 @@
                   WritableRaster scaled = filter.createCompatibleDestRaster(original);
                   filter.filter(original, scaled);
   
  -                // JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
  -
  -                ByteArrayOutputStream bstream = new ByteArrayOutputStream();
  -                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bstream);
  -                encoder.encode(scaled);
  -                out.write(bstream.toByteArray());
  +                if (!handleJVMBug()) {
  +                    if (getLogger().isDebugEnabled()) {
  +                        getLogger().debug( "No need to handle JVM bug" );
  +                    }
  +                    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
  +                    encoder.encode(scaled);
  +                } else {
  +                    if (getLogger().isDebugEnabled()) {
  +                        getLogger().debug( "Need to handle JVM bug" );
  +                    }
  +                    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
  +                    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bstream);
  +                    encoder.encode(scaled);
  +                    out.write(bstream.toByteArray());
  +                }
   
                   out.flush();
               } catch (ImageFormatException e) {
                   throw new ProcessingException("Error reading the image. Note that only
JPEG images are currently supported.");
  +            } finally {
  +              // Bugzilla Bug 25069, close inputStream in finally block
  +              // this will close inputStream even if processStream throws
  +              // an exception
  +              inputStream.close();
               }
  -
  -            inputStream.close();
           } else {
               // only read the resource - no modifications requested
               if (getLogger().isDebugEnabled()) {
  @@ -237,5 +249,39 @@
           } else {
               return super.getKey();
           }
  +    }
  +
  +    /**
  +     * Determine if workaround for Bug Id 4502892 is neccessary.
  +     * This method assumes that Bug is present if 
  +     * java.version is undeterminable, and for java.version
  +     * 1.1, 1.2, 1.3, all other java.version do not need the Bug handling
  +     *
  +     * @return true if we should handle the JVM bug, else false
  +     */
  +    protected boolean handleJVMBug() {
  +        // java.version=1.4.0
  +        String java_version = System.getProperty( "java.version", "0.0.0" );
  +        boolean handleJVMBug = true;
  +        
  +        char major = java_version.charAt(0);
  +        char minor = java_version.charAt(2);
  +        
  +        // make 0.0, 1.1, 1.2, 1.3 handleJVMBug = true
  +        if (major == '0' || major == '1') {
  +            if (minor == '0' || minor == '1' || minor == '2' || minor == '3') {
  +                handleJVMBug = true;
  +            } else {
  +                handleJVMBug = false;
  +            }
  +        } else {
  +            handleJVMBug = true;
  +        }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug( "Running java.version " + String.valueOf(java_version) +

  +              " need to handle JVM bug " + String.valueOf(handleJVMBug) );
  +        }
  +        
  +        return handleJVMBug;
       }
   }
  
  
  

Mime
View raw message