The ImageDirectoryGenerator uses characters to read in the graphics files, and (on my system at least) this seems to default to reading 2 byte unicode and mucks up the functionality. Here's a patch to use bytes which seems to work fine on my system. Stuart.
Index: src/org/apache/cocoon/generation/ImageDirectoryGenerator.java =================================================================== RCS file: /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/generation/ImageDirectoryGenerator.java,v retrieving revision 1.5 diff -u -r1.5 ImageDirectoryGenerator.java --- src/org/apache/cocoon/generation/ImageDirectoryGenerator.java 2001/07/12 15:01:35 1.5 +++ src/org/apache/cocoon/generation/ImageDirectoryGenerator.java 2001/07/23 +12:30:28 @@ -7,10 +7,13 @@ *****************************************************************************/ package org.apache.cocoon.generation; +import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; import java.io.IOException; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.log.Hierarchy; @@ -42,6 +45,7 @@ } try { int dim[] = getSize(path); + getLogger().debug("getSize(path) = " + dim); attributes.addAttribute("",IMAGE_WIDTH_ATTR_NAME,IMAGE_WIDTH_ATTR_NAME,"CDATA",""+dim[0]); attributes.addAttribute("",IMAGE_HEIGHT_ATTR_NAME,IMAGE_HEIGHT_ATTR_NAME,"CDATA",""+dim[1]); } catch (RuntimeException e) {getLogger().debug("ImageDirectoryGenerator.setNodeAttributes", e);} @@ -66,15 +70,15 @@ // returns width as first element, height as second public static int[] getJpegSize(File file) throws FileNotFoundException, IOException { - BufferedReader in = null; + BufferedInputStream in = null; try { - in = new BufferedReader(new FileReader(file)); + in = new BufferedInputStream(new FileInputStream(file)); // check for "magic" header - char[] buf = new char[2]; + byte[] buf = new byte[2]; int count = in.read(buf, 0, 2); if(count < 2) throw new RuntimeException("Not a valid Jpeg file!"); - if((buf[0]) != 0xFF - || (buf[1]) != 0xD8 ) + if((buf[0]) != (byte)0xFF + || (buf[1]) != (byte)0xD8 ) throw new RuntimeException("Not a valid Jpeg file!"); int width = 0; @@ -124,15 +128,15 @@ // returns width as first element, height as second public static int[] getGifSize(File file) throws FileNotFoundException, IOException { - BufferedReader in = null; + BufferedInputStream in = null; try { - in = new BufferedReader(new FileReader(file)); - char[] buf = new char[10]; + in = new BufferedInputStream(new FileInputStream(file)); + byte[] buf = new byte[10]; int count = in.read(buf, 0, 10); if(count < 10) throw new RuntimeException("Not a valid GIF file!"); - if((buf[0]) != 'G' - || (buf[1]) != 'I' - || (buf[2]) != 'F' ) + if((buf[0]) != (byte)'G' + || (buf[1]) != (byte)'I' + || (buf[2]) != (byte)'F' ) throw new RuntimeException("Not a valid GIF file!"); int w1 = ((int)buf[6] & 0xff) | (buf[6] & 0x80); @@ -153,23 +157,22 @@ // returns "gif", "jpeg" or NULL public static String getFileType(File file) throws FileNotFoundException, IOException { - BufferedReader in = null; + BufferedInputStream in = null; try { - in = new BufferedReader(new FileReader(file)); - char[] buf = new char[3]; + in = new BufferedInputStream(new FileInputStream(file)); + byte[] buf = new byte[3]; int count = in.read(buf, 0, 3); if(count < 3) return null; - if((buf[0]) == 'G' - && (buf[1]) == 'I' - && (buf[2]) == 'F' ) + if((buf[0]) == (byte)'G' + && (buf[1]) == (byte)'I' + && (buf[2]) == (byte)'F' ) return "gif"; - if((buf[0]) == 0xFF - && (buf[1]) == 0xD8 ) + if((buf[0]) == (byte)0xFF + && (buf[1]) == (byte)0xD8 ) return "jpeg"; return null; - } finally { if(in != null) try { in.close(); } catch(Exception e) {Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").debug("Close stream", e);} }
------------------------------------------------------------------------- Stuart Roebuck [EMAIL PROTECTED] Lead Developer Java, XML, MacOS X, XP, etc. ADOLOS <http://www.adolos.com/>