You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/07/23 15:01:13 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/generation ImageDirectoryGenerator.java
cziegeler 01/07/23 06:01:13
Modified: . Tag: cocoon_20_branch changes.xml
src/org/apache/cocoon/generation Tag: cocoon_20_branch
ImageDirectoryGenerator.java
Log:
Patch for fixing the byte handling of the ImageDirectoryGenerator.
Submitted by: Stuart Roebuck (stuart.roebuck@adolos.com)
Revision Changes Path
No revision
No revision
1.2.2.24 +3 -2 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.2.2.23
retrieving revision 1.2.2.24
diff -u -r1.2.2.23 -r1.2.2.24
--- changes.xml 2001/07/23 11:07:21 1.2.2.23
+++ changes.xml 2001/07/23 13:01:13 1.2.2.24
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.2.2.23 2001/07/23 11:07:21 cziegeler Exp $
+ $Id: changes.xml,v 1.2.2.24 2001/07/23 13:01:13 cziegeler Exp $
-->
<changes title="History of Changes">
@@ -27,7 +27,8 @@
<release version="2.0b2-dev" date="@date@">
<action dev="CZ" type="add">
- Just empty
+ Added patch by Stuart Roebuck (stuart.roebuck@adolos.com)
+ fixing the byte handling of the ImageDirectoryGenerator.
</action>
</release>
<release version="2.0b2" date="July 23, 2001">
No revision
No revision
1.4.2.2 +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.4.2.1
retrieving revision 1.4.2.2
diff -u -r1.4.2.1 -r1.4.2.2
--- ImageDirectoryGenerator.java 2001/07/12 15:03:04 1.4.2.1
+++ ImageDirectoryGenerator.java 2001/07/23 13:01:13 1.4.2.2
@@ -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:balld@webslingerZ.com">Donald A. Ball Jr.</a>
- * @version $Revision: 1.4.2.1 $ $Date: 2001/07/12 15:03:04 $
+ * @version $Revision: 1.4.2.2 $ $Date: 2001/07/23 13:01: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: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org