cziegeler 01/07/23 06:02:14
Modified: . changes.xml
src/org/apache/cocoon/generation
ImageDirectoryGenerator.java
Log:
Submitted by: Stuart Roebuck ([EMAIL PROTECTED])
Revision Changes Path
1.22 +5 -1 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- changes.xml 2001/07/19 13:18:52 1.21
+++ changes.xml 2001/07/23 13:02:13 1.22
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.21 2001/07/19 13:18:52 cziegeler Exp $
+ $Id: changes.xml,v 1.22 2001/07/23 13:02:13 cziegeler Exp $
-->
<changes title="History of Changes">
@@ -26,6 +26,10 @@
</devs>
<release version="2.1-dev" date="@date@">
+ <action dev="CZ" type="add">
+ Added patch by Stuart Roebuck ([EMAIL PROTECTED])
+ fixing the byte handling of the ImageDirectoryGenerator.
+ </action>
<action dev="CZ" type="add">
When a resource is not found (ResourceNotFoundException) the
servlet sets only the status 404 and doesn't write to the output.
1.6 +24 -21
xml-cocoon2/src/org/apache/cocoon/generation/ImageDirectoryGenerator.java
Index: ImageDirectoryGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/ImageDirectoryGenerator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ImageDirectoryGenerator.java 2001/07/12 15:01:35 1.5
+++ ImageDirectoryGenerator.java 2001/07/23 13:02:13 1.6
@@ -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;
@@ -23,7 +26,7 @@
* files.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Donald A. Ball Jr.</a>
- * @version $Revision: 1.5 $ $Date: 2001/07/12 15:01:35 $
+ * @version $Revision: 1.6 $ $Date: 2001/07/23 13:02:13 $
*/
public class ImageDirectoryGenerator extends DirectoryGenerator {
@@ -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);}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]