You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sanselan-commits@incubator.apache.org by cm...@apache.org on 2007/11/17 21:58:40 UTC

svn commit: r596008 [15/15] - in /incubator/sanselan/trunk/src: main/java/org/apache/sanselan/ main/java/org/apache/sanselan/color/ main/java/org/apache/sanselan/common/ main/java/org/apache/sanselan/common/byteSources/ main/java/org/apache/sanselan/co...

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageReadExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageReadExample.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageReadExample.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageReadExample.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cmc.sanselan.sampleUsage;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Transparency;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cmc.sanselan.ImageReadException;
+import org.cmc.sanselan.Sanselan;
+import org.cmc.sanselan.SanselanConstants;
+import org.cmc.sanselan.common.IBufferedImageFactory;
+
+public class ImageReadExample
+{
+	public static BufferedImage imageReadExample(File file)
+			throws ImageReadException, IOException
+	{
+		Map params = new HashMap();
+
+		// set optional parameters if you like
+		params.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
+				new ManagedImageBufferedImageFactory());
+
+		//		params.put(SanselanConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+		// read image
+		BufferedImage image = Sanselan.getBufferedImage(file, params);
+
+		return image;
+	}
+
+	public static class ManagedImageBufferedImageFactory
+			implements
+				IBufferedImageFactory
+	{
+
+		public BufferedImage getColorBufferedImage(int width, int height)
+		{
+			GraphicsEnvironment ge = GraphicsEnvironment
+					.getLocalGraphicsEnvironment();
+			GraphicsDevice gd = ge.getDefaultScreenDevice();
+			GraphicsConfiguration gc = gd.getDefaultConfiguration();
+			return gc.createCompatibleImage(width, height,
+					Transparency.TRANSLUCENT);
+		}
+
+		public BufferedImage getGrayscaleBufferedImage(int width, int height)
+		{
+			return getColorBufferedImage(width, height);
+		}
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageReadExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageWriteExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageWriteExample.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageWriteExample.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageWriteExample.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cmc.sanselan.sampleUsage;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cmc.sanselan.ImageFormat;
+import org.cmc.sanselan.ImageReadException;
+import org.cmc.sanselan.ImageWriteException;
+import org.cmc.sanselan.Sanselan;
+import org.cmc.sanselan.SanselanConstants;
+import org.cmc.sanselan.formats.tiff.TiffConstants;
+
+public class ImageWriteExample
+{
+	public static byte[] imageWriteExample(File file)
+			throws ImageReadException, ImageWriteException, IOException
+	{
+		// read image
+		BufferedImage image = Sanselan.getBufferedImage(file);
+
+		ImageFormat format = ImageFormat.IMAGE_FORMAT_TIFF;
+		Map params = new HashMap();
+
+		// set optional parameters if you like
+		params.put(SanselanConstants.PARAM_KEY_COMPRESSION, new Integer(
+				TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED));
+
+		byte bytes[] = Sanselan.writeImageToBytes(image, format, params);
+
+		return bytes;
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/ImageWriteExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/MetadataExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/MetadataExample.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/MetadataExample.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/MetadataExample.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cmc.sanselan.sampleUsage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+
+import org.cmc.sanselan.ImageReadException;
+import org.cmc.sanselan.Sanselan;
+import org.cmc.sanselan.common.IImageMetadata;
+import org.cmc.sanselan.common.RationalNumber;
+import org.cmc.sanselan.formats.jpeg.JpegImageMetadata;
+import org.cmc.sanselan.formats.tiff.TagInfo;
+import org.cmc.sanselan.formats.tiff.TiffConstants;
+import org.cmc.sanselan.formats.tiff.TiffField;
+
+public class MetadataExample
+{
+	public static void metadataExample(File file) throws ImageReadException,
+			IOException
+	{
+		//		get all metadata stored in EXIF format (ie. from JPEG or TIFF).
+		//			org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes);
+		IImageMetadata metadata = Sanselan.getMetadata(file);
+
+		//System.out.println(metadata);
+
+		if (metadata instanceof JpegImageMetadata)
+		{
+			JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+
+			// Jpeg EXIF metadata is stored in a TIFF-based directory structure
+			// and is identified with TIFF tags.
+			// Here we look for the "x resolution" tag, but
+			// we could just as easily search for any other tag.
+			//
+			// see the TiffConstants file for a list of TIFF tags.
+
+			System.out.println("file: " + file.getPath());
+
+			// print out various interesting EXIF tags.
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_XResolution);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DateTime);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DateTimeOriginal);
+			printTagValue(jpegMetadata,
+					TiffConstants.TIFF_TAG_DateTimeDigitized);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_ISOSpeedRatings);
+			printTagValue(jpegMetadata,
+					TiffConstants.TIFF_TAG_ShutterSpeedValue);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_ApertureValue);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_BrightnessValue);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_GPSLatitudeRef);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_GPSLatitude);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_GPSLongitudeRef);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_GPSLongitude);
+
+			System.out.println();
+
+			// more specific example of how to access GPS values.
+			TiffField gpsLatitudeRefField = jpegMetadata
+					.findEXIFValue(TiffConstants.TIFF_TAG_GPSLatitudeRef);
+			TiffField gpsLatitudeField = jpegMetadata
+					.findEXIFValue(TiffConstants.TIFF_TAG_GPSLatitude);
+			TiffField gpsLongitudeRefField = jpegMetadata
+					.findEXIFValue(TiffConstants.TIFF_TAG_GPSLongitudeRef);
+			TiffField gpsLongitudeField = jpegMetadata
+					.findEXIFValue(TiffConstants.TIFF_TAG_GPSLongitude);
+			if (gpsLatitudeRefField != null && gpsLatitudeField != null
+					&& gpsLongitudeRefField != null
+					&& gpsLongitudeField != null)
+			{
+				// all of these values are strings.
+				String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue();
+				RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField
+						.getValue());
+				String gpsLongitudeRef = (String) gpsLongitudeRefField
+						.getValue();
+				RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField
+						.getValue();
+
+				RationalNumber gpsLatitudeDegrees = gpsLatitude[0];
+				RationalNumber gpsLatitudeMinutes = gpsLatitude[1];
+				RationalNumber gpsLatitudeSeconds = gpsLatitude[2];
+
+				RationalNumber gpsLongitudeDegrees = gpsLongitude[0];
+				RationalNumber gpsLongitudeMinutes = gpsLongitude[1];
+				RationalNumber gpsLongitudeSeconds = gpsLongitude[2];
+
+				// This will format the gps info like so:
+				//
+				// gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S
+				// gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E
+
+				System.out.println("\t" + "GPS Latitude: "
+						+ gpsLatitudeDegrees.toDisplayString() + " degrees, "
+						+ gpsLatitudeMinutes.toDisplayString() + " minutes, "
+						+ gpsLatitudeSeconds.toDisplayString() + " seconds "
+						+ gpsLatitudeRef);
+				System.out.println("\t" + "GPS Longitude: "
+						+ gpsLongitudeDegrees.toDisplayString() + " degrees, "
+						+ gpsLongitudeMinutes.toDisplayString() + " minutes, "
+						+ gpsLongitudeSeconds.toDisplayString() + " seconds "
+						+ gpsLongitudeRef);
+
+			}
+
+			System.out.println();
+
+			Vector items = jpegMetadata.getItems();
+			for (int i = 0; i < items.size(); i++)
+			{
+				Object item = items.get(i);
+				System.out.println("\t" + "item: " + item);
+			}
+
+			System.out.println();
+		}
+	}
+
+	private static void printTagValue(JpegImageMetadata jpegMetadata,
+			TagInfo tagInfo) throws ImageReadException, IOException
+	{
+		TiffField field = jpegMetadata.findEXIFValue(tagInfo);
+		if (field == null)
+			System.out.println(tagInfo.name + ": " + "Not Found.");
+		else
+			System.out.println(tagInfo.name + ": "
+					+ field.getValueDescription());
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/MetadataExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/SampleUsage.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/SampleUsage.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/SampleUsage.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/SampleUsage.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cmc.sanselan.sampleUsage;
+
+import java.awt.Dimension;
+import java.awt.color.ICC_Profile;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.cmc.sanselan.FormatCompliance;
+import org.cmc.sanselan.ImageFormat;
+import org.cmc.sanselan.ImageInfo;
+import org.cmc.sanselan.Sanselan;
+import org.cmc.sanselan.common.IImageMetadata;
+
+public class SampleUsage
+{
+
+	public SampleUsage()
+	{
+
+		try
+		{
+			// <b>Code won't work unless these variables are properly initialized. 
+			// 		Sanselan works equally well with File, byte array or InputStream inputs.</b>
+			BufferedImage someImage = null;
+			byte someBytes[] = null;
+			File someFile = null;
+			InputStream someInputStream = null;
+			OutputStream someOutputStream = null;
+
+			// <b>The Sanselan class provides a simple interface to the library. </b>
+
+			// <b>how to read an image: </b>
+			byte imageBytes[] = someBytes;
+			BufferedImage image_1 = Sanselan.getBufferedImage(imageBytes);
+
+			// <b>methods of Sanselan usually accept files, byte arrays, or inputstreams as arguments. </b>
+			BufferedImage image_2 = Sanselan.getBufferedImage(imageBytes);
+			File file = someFile;
+			BufferedImage image_3 = Sanselan.getBufferedImage(file);
+			InputStream is = someInputStream;
+			BufferedImage image_4 = Sanselan.getBufferedImage(is);
+
+			// <b>Write an image. </b>
+			BufferedImage image = someImage;
+			File dst = someFile;
+			ImageFormat format = ImageFormat.IMAGE_FORMAT_PNG;
+			Map optional_params = new Hashtable();
+			Sanselan.writeImage(image, dst, format, optional_params);
+
+			OutputStream os = someOutputStream;
+			Sanselan.writeImage(image, os, format, optional_params);
+
+			// <b>get the image's embedded ICC Profile, if it has one. </b>
+			byte icc_profile_bytes[] = Sanselan.getICCProfileBytes(imageBytes);
+
+			ICC_Profile icc_profile = Sanselan.getICCProfile(imageBytes);
+
+			// <b>get the image's width and height. </b>
+			Dimension d = Sanselan.getImageSize(imageBytes);
+
+			// <b>get all of the image's info (ie. bits per pixel, size, transparency, etc.) </b>
+			ImageInfo image_info = Sanselan.getImageInfo(imageBytes);
+
+			if (image_info.getColorType() == ImageInfo.COLOR_TYPE_GRAYSCALE)
+				System.out.println("Grayscale image.");
+			if (image_info.getHeight() > 1000)
+				System.out.println("Large image.");
+
+			// <b>try to guess the image's format. </b>
+			ImageFormat image_format = Sanselan.guessFormat(imageBytes);
+			image_format.equals(ImageFormat.IMAGE_FORMAT_PNG);
+
+			// <b>get all metadata stored in EXIF format (ie. from JPEG or TIFF). </b>
+			// <b>org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes); </b>
+			IImageMetadata metdata = Sanselan.getMetadata(imageBytes);
+
+			// <b>print a dump of information about an image to stdout. </b>
+			Sanselan.dumpImageFile(imageBytes);
+
+			// <b>get a summary of format errors. </b>
+			FormatCompliance format_compliance = Sanselan
+					.getFormatCompliance(imageBytes);
+
+		}
+		catch (Exception e)
+		{
+
+		}
+	}
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/sampleUsage/SampleUsage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/CachingInputStream.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/CachingInputStream.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/CachingInputStream.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/CachingInputStream.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.cmc.sanselan.util;
+
+import java.io.*;
+
+public class CachingInputStream extends InputStream
+{
+	private final InputStream is;
+	private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+	public CachingInputStream(InputStream is)
+	{
+		this.is = is;
+	}
+
+	public byte[] getCache()
+	{
+		return baos.toByteArray();
+	}
+
+	public int read() throws IOException
+	{
+		int result = is.read();
+		baos.write(result);
+		return result;
+	}
+
+	public int available() throws IOException
+	{
+		return is.available();
+	}
+
+	public void close() throws IOException
+	{
+		is.close();
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/CachingInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/Debug.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/Debug.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/Debug.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/Debug.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,885 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cmc.sanselan.util;
+
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.color.ICC_Profile;
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Map;
+import java.util.Vector;
+
+public final class Debug
+{
+
+	public static void debug(String message)
+	{
+		System.out.println(message);
+	}
+
+	public static void debug(Object o)
+	{
+		System.out.println(o == null ? "null" : o.toString());
+	}
+
+	public static String getDebug(String message)
+	{
+		return message;
+	}
+
+	public static void debug()
+	{
+		newline();
+	}
+
+	public static void newline()
+	{
+		System.out.print(newline);
+	}
+
+	public static String getDebug(String message, int value)
+	{
+		return getDebug(message + ": " + (value));
+	}
+
+	public static String getDebug(String message, double value)
+	{
+		return getDebug(message + ": " + (value));
+	}
+
+	public static String getDebug(String message, String value)
+	{
+		return getDebug(message + " " + value);
+	}
+
+	public static String getDebug(String message, long value)
+	{
+		return getDebug(message + " " + Long.toString(value));
+	}
+
+	public static String getDebug(String message, int v[])
+	{
+		StringBuffer result = new StringBuffer();
+
+		if (v == null)
+			result.append(message + " (" + null + ")" + newline);
+		else
+		{
+			result.append(message + " (" + v.length + ")" + newline);
+			for (int i = 0; i < v.length; i++)
+				result.append("\t" + v[i] + newline);
+			result.append(newline);
+		}
+		return result.toString();
+	}
+
+	public static String getDebug(String message, byte v[])
+	{
+		final int max = 250;
+		return getDebug(message, v, max);
+	}
+
+	public static String getDebug(String message, byte v[], int max)
+	{
+
+		StringBuffer result = new StringBuffer();
+
+		if (v == null)
+			result.append(message + " (" + null + ")" + newline);
+		else
+		{
+			result.append(message + " (" + v.length + ")" + newline);
+			for (int i = 0; i < max && i < v.length; i++)
+			{
+				int b = 0xff & v[i];
+				result.append("\t" + i + ": " + b + " (" + (char) b + ", 0x"
+						+ Integer.toHexString(b) + ")" + newline);
+			}
+			if (v.length > max)
+				result.append("\t" + "..." + newline);
+
+			result.append(newline);
+		}
+		return result.toString();
+	}
+
+	public static String getDebug(String message, char v[])
+	{
+		StringBuffer result = new StringBuffer();
+
+		if (v == null)
+			result.append(getDebug(message + " (" + null + ")") + newline);
+		else
+		{
+			result.append(getDebug(message + " (" + v.length + ")") + newline);
+			for (int i = 0; i < v.length; i++)
+				result.append(getDebug("\t" + v[i] + " (" + (0xff & v[i]))
+						+ ")" + newline);
+			result.append(newline);
+		}
+		return result.toString();
+	}
+
+	private static long counter = 0;
+
+	public static String getDebug(String message, java.util.List v)
+	{
+		StringBuffer result = new StringBuffer();
+
+		String suffix = " [" + counter++ + "]";
+
+		result.append(getDebug(message + " (" + v.size() + ")" + suffix)
+				+ newline);
+		for (int i = 0; i < v.size(); i++)
+			result.append(getDebug("\t" + v.get(i).toString() + suffix)
+					+ newline);
+		result.append(newline);
+
+		return result.toString();
+	}
+
+	public static void debug(String message, Map map)
+	{
+		debug(getDebug(message, map));
+	}
+
+	public static String getDebug(String message, Map map)
+	{
+		StringBuffer result = new StringBuffer();
+
+		if (map == null)
+			return getDebug(message + " map: " + null);
+
+		Vector keys = new Vector(map.keySet());
+		result.append(getDebug(message + " map: " + keys.size()) + newline);
+		for (int i = 0; i < keys.size(); i++)
+		{
+			Object key = keys.get(i);
+			Object value = map.get(key);
+			result.append(getDebug("\t" + i + ": '" + key + "' -> '" + value
+					+ "'")
+					+ newline);
+		}
+
+		result.append(newline);
+
+		return result.toString();
+	}
+
+	public static boolean compare(String prefix, Map a, Map b)
+	{
+		return compare(prefix, a, b, null, null);
+	}
+
+	//	public static String newline = System.getProperty("line.separator");
+	public static String newline = "\r\n";
+
+	private static void log(StringBuffer buffer, String s)
+	{
+		Debug.debug(s);
+		if (buffer != null)
+			buffer.append(s + newline);
+	}
+
+	public static boolean compare(String prefix, Map a, Map b, Vector ignore,
+			StringBuffer buffer)
+	{
+		if ((a == null) && (b == null))
+		{
+			log(buffer, prefix + " both maps null");
+			return true;
+		}
+		if (a == null)
+		{
+			log(buffer, prefix + " map a: null, map b: map");
+			return false;
+		}
+		if (b == null)
+		{
+			log(buffer, prefix + " map a: map, map b: null");
+			return false;
+		}
+
+		Vector keys_a = new Vector(a.keySet());
+		Vector keys_b = new Vector(b.keySet());
+
+		if (ignore != null)
+		{
+			keys_a.removeAll(ignore);
+			keys_b.removeAll(ignore);
+		}
+
+		boolean result = true;
+
+		for (int i = 0; i < keys_a.size(); i++)
+		{
+			Object key = keys_a.get(i);
+			if (!keys_b.contains(key))
+			{
+				log(buffer, prefix + "b is missing key '" + key + "' from a");
+				result = false;
+			}
+			else
+			{
+				keys_b.remove(key);
+				Object value_a = a.get(key);
+				Object value_b = b.get(key);
+				if (!value_a.equals(value_b))
+				{
+					log(buffer, prefix + "key(" + key + ") value a: " + value_a
+							+ ") !=  b: " + value_b + ")");
+					result = false;
+				}
+			}
+		}
+		for (int i = 0; i < keys_b.size(); i++)
+		{
+			Object key = keys_b.get(i);
+
+			log(buffer, prefix + "a is missing key '" + key + "' from b");
+			result = false;
+		}
+
+		if (result)
+			log(buffer, prefix + "a is the same as  b");
+
+		return result;
+	}
+
+	private static final String byteQuadToString(int bytequad)
+	{
+		byte b1 = (byte) ((bytequad >> 24) & 0xff);
+		byte b2 = (byte) ((bytequad >> 16) & 0xff);
+		byte b3 = (byte) ((bytequad >> 8) & 0xff);
+		byte b4 = (byte) ((bytequad >> 0) & 0xff);
+
+		char c1 = (char) b1;
+		char c2 = (char) b2;
+		char c3 = (char) b3;
+		char c4 = (char) b4;
+		//		return new String(new char[] { c1, c2, c3, c4 });
+		StringBuffer fStringBuffer = new StringBuffer();
+		fStringBuffer.append(new String(new char[]{
+				c1, c2, c3, c4
+		}));
+		fStringBuffer.append(" bytequad: " + bytequad);
+		fStringBuffer.append(" b1: " + b1);
+		fStringBuffer.append(" b2: " + b2);
+		fStringBuffer.append(" b3: " + b3);
+		fStringBuffer.append(" b4: " + b4);
+
+		return fStringBuffer.toString();
+	}
+
+	public static String getDebug(String message, ICC_Profile value)
+	{
+
+		StringBuffer result = new StringBuffer();
+
+		result.append(getDebug("ICC_Profile " + message + ": "
+				+ ((value == null) ? "null" : value.toString()))
+				+ newline);
+		if (value != null)
+		{
+			result.append(getDebug("\t getProfileClass: "
+					+ byteQuadToString(value.getProfileClass()))
+					+ newline);
+			result.append(getDebug("\t getPCSType: "
+					+ byteQuadToString(value.getPCSType()))
+					+ newline);
+			result.append(getDebug("\t getColorSpaceType() : "
+					+ byteQuadToString(value.getColorSpaceType()))
+					+ newline);
+		}
+
+		return result.toString();
+
+	}
+
+	public static String getDebug(String message, boolean value)
+	{
+		return getDebug(message + " " + ((value) ? ("true") : ("false")));
+	}
+
+	public static String getDebug(String message, File file)
+	{
+		return getDebug(message + ": "
+				+ ((file == null) ? "null" : file.getPath()));
+	}
+
+	public static String getDebug(String message, Date value)
+	{
+		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+		return getDebug(message, (value == null) ? "null" : df.format(value));
+	}
+
+	public static String getDebug(String message, Calendar value)
+	{
+		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+		return getDebug(message, (value == null) ? "null" : df.format(value
+				.getTime()));
+	}
+
+	public static void debug(String message, Object value)
+	{
+		if (value == null)
+			debug(message, "null");
+		else if (value instanceof char[])
+			debug(message, (char[]) value);
+		else if (value instanceof byte[])
+			debug(message, (byte[]) value);
+		else if (value instanceof int[])
+			debug(message, (int[]) value);
+		else if (value instanceof String)
+			debug(message, (String) value);
+		else if (value instanceof java.util.List)
+			debug(message, (java.util.List) value);
+		else if (value instanceof Map)
+			debug(message, (Map) value);
+		//		else if (value instanceof Object)
+		//			debug(message, (Object) value);
+		else if (value instanceof ICC_Profile)
+			debug(message, (ICC_Profile) value);
+		else if (value instanceof File)
+			debug(message, (File) value);
+		else if (value instanceof Date)
+			debug(message, (Date) value);
+		else if (value instanceof Calendar)
+			debug(message, (Calendar) value);
+		else
+			debug(message, value.toString());
+	}
+
+	public static void debug(String message, Object value[])
+	{
+		if (value == null)
+			debug(message, "null");
+
+		debug(message, value.length);
+		final int max = 10;
+		for (int i = 0; i < value.length && i < max; i++)
+			debug("\t" + i, value[i]);
+		if (value.length > max)
+			debug("\t...");
+		debug();
+	}
+
+	public static String getDebug(String message, Object value)
+	{
+		if (value == null)
+			return getDebug(message, "null");
+		else if (value instanceof Calendar)
+			return getDebug(message, (Calendar) value);
+		else if (value instanceof Date)
+			return getDebug(message, (Date) value);
+		else if (value instanceof File)
+			return getDebug(message, (File) value);
+		else if (value instanceof ICC_Profile)
+			return getDebug(message, (ICC_Profile) value);
+		else if (value instanceof Map)
+			return getDebug(message, (Map) value);
+		else if (value instanceof Map)
+			return getDebug(message, (Map) value); //
+		//		else if (value instanceof Object) // getDebug(message, (Object) value);
+		else if (value instanceof String)
+			return getDebug(message, (String) value);
+		else if (value instanceof byte[])
+			return getDebug(message, (byte[]) value);
+		else if (value instanceof char[])
+			return getDebug(message, (char[]) value);
+		else if (value instanceof int[])
+			return getDebug(message, (int[]) value);
+		else if (value instanceof java.util.List)
+			return getDebug(message, (java.util.List) value);
+		else
+			return getDebug(message, value.toString());
+	}
+
+	public static String getType(Object value)
+	{
+		if (value == null)
+			return "null";
+		else if (value instanceof Object[])
+			return "[Object[]: " + ((Object[]) value).length + "]";
+		else if (value instanceof char[])
+			return "[char[]: " + ((char[]) value).length + "]";
+		else if (value instanceof byte[])
+			return "[byte[]: " + ((byte[]) value).length + "]";
+		else if (value instanceof short[])
+			return "[short[]: " + ((short[]) value).length + "]";
+		else if (value instanceof int[])
+			return "[int[]: " + ((int[]) value).length + "]";
+		else if (value instanceof long[])
+			return "[long[]: " + ((long[]) value).length + "]";
+		else if (value instanceof float[])
+			return "[float[]: " + ((float[]) value).length + "]";
+		else if (value instanceof double[])
+			return "[double[]: " + ((double[]) value).length + "]";
+		else if (value instanceof boolean[])
+			return "[boolean[]: " + ((boolean[]) value).length + "]";
+		else
+			return value.getClass().getName();
+	}
+
+	public static boolean isArray(Object value)
+	{
+		if (value == null)
+			return false;
+		else if (value instanceof Object[])
+			return true;
+		else if (value instanceof char[])
+			return true;
+		else if (value instanceof byte[])
+			return true;
+		else if (value instanceof short[])
+			return true;
+		else if (value instanceof int[])
+			return true;
+		else if (value instanceof long[])
+			return true;
+		else if (value instanceof float[])
+			return true;
+		else if (value instanceof double[])
+			return true;
+		else if (value instanceof boolean[])
+			return true;
+		else
+			return false;
+	}
+
+	public static String getDebug(String message, Object value[])
+	{
+		StringBuffer result = new StringBuffer();
+
+		if (value == null)
+			result.append(getDebug(message, "null") + newline);
+
+		result.append(getDebug(message, value.length));
+		final int max = 10;
+		for (int i = 0; i < value.length && i < max; i++)
+			result.append(getDebug("\t" + i, value[i]) + newline);
+		if (value.length > max)
+			result.append(getDebug("\t...") + newline);
+		result.append(newline);
+
+		return result.toString();
+	}
+
+	public static String getDebug(Class fClass, Throwable e)
+	{
+		return getDebug(fClass == null ? "[Unknown]" : fClass.getName(), e);
+	}
+
+	public static void debug(Class fClass, Throwable e)
+	{
+		debug(fClass.getName(), e);
+	}
+
+	private static final SimpleDateFormat timestamp = new SimpleDateFormat(
+			"yyyy-MM-dd kk:mm:ss:SSS");
+
+	public static void debug(String message, boolean value)
+	{
+		debug(message + " " + ((value) ? ("true") : ("false")));
+	}
+
+	public static void debug(String message, byte v[])
+	{
+		debug(getDebug(message, v));
+	}
+
+	public static void debug(String message, char v[])
+	{
+		debug(getDebug(message, v));
+	}
+
+	public static void debug(String message, Calendar value)
+	{
+		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+		debug(message, (value == null) ? "null" : df.format(value.getTime()));
+	}
+
+	public static void debug(String message, Date value)
+	{
+		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+		debug(message, (value == null) ? "null" : df.format(value));
+	}
+
+	public static void debug(String message, double value)
+	{
+		debug(message + ": " + (value));
+	}
+
+	public static void debug(String message, File file)
+	{
+		debug(message + ": " + ((file == null) ? "null" : file.getPath()));
+	}
+
+	//	public static void debug(String message, Object value)
+	//	{
+	//		debug("Unknown Object " + message + ": "
+	//				+ ((value == null) ? "null" : value.toString()));
+	//	}
+
+	public static void debug(String message, ICC_Profile value)
+	{
+		debug("ICC_Profile " + message + ": "
+				+ ((value == null) ? "null" : value.toString()));
+		if (value != null)
+		{
+			debug("\t getProfileClass: "
+					+ byteQuadToString(value.getProfileClass()));
+			debug("\t getPCSType: " + byteQuadToString(value.getPCSType()));
+			debug("\t getColorSpaceType() : "
+					+ byteQuadToString(value.getColorSpaceType()));
+		}
+	}
+
+	public static void debug(String message, int value)
+	{
+		debug(message + ": " + (value));
+	}
+
+	public static void debug(String message, int v[])
+	{
+		debug(getDebug(message, v));
+	}
+
+	public static void debug(String message, byte v[], int max)
+	{
+		debug(getDebug(message, v, max));
+	}
+
+	public static void debug(String message, java.util.List v)
+	{
+		String suffix = " [" + counter++ + "]";
+
+		debug(message + " (" + v.size() + ")" + suffix);
+		for (int i = 0; i < v.size(); i++)
+			debug("\t" + v.get(i).toString() + suffix);
+		debug();
+	}
+
+	public static void debug(String message, long value)
+	{
+		debug(message + " " + Long.toString(value));
+	}
+
+	public static void debug(String prefix, Point p)
+	{
+		System.out.println(prefix + ": "
+				+ ((p == null) ? "null" : (p.x + ", " + p.y)));
+	}
+
+	public static void debug(String prefix, Rectangle r)
+	{
+		debug(getDebug(prefix, r));
+	}
+
+	public static void debug(String message, String value)
+	{
+		debug(message + " " + value);
+	}
+
+	public static void debug(String message, Throwable e)
+	{
+		debug(getDebug(message, e));
+	}
+
+	public static void debug(Throwable e)
+	{
+		debug(getDebug(e));
+	}
+
+	public static void debug(Throwable e, int value)
+	{
+		debug(getDebug(e, value));
+	}
+
+	public static void dumpStack()
+	{
+		debug(getStackTrace(new Exception("Stack trace"), -1, 1));
+	}
+
+	public static void dumpStack(int limit)
+	{
+		debug(getStackTrace(new Exception("Stack trace"), limit, 1));
+	}
+
+	public static String getDebug(String message, Throwable e)
+	{
+		return message + newline + getDebug(e);
+	}
+
+	public static String getDebug(Throwable e)
+	{
+		return getDebug(e, -1);
+	}
+
+	public static String getDebug(Throwable e, int max)
+	{
+		StringBuffer result = new StringBuffer();
+
+		String datetime = timestamp.format(new Date()).toLowerCase();
+
+		result.append(newline);
+		result.append("Throwable: "
+				+ ((e == null) ? "" : ("(" + e.getClass().getName() + ")"))
+				+ ":" + datetime + newline);
+		result.append("Throwable: "
+				+ ((e == null) ? "null" : e.getLocalizedMessage()) + newline);
+		result.append(newline);
+
+		result.append(getStackTrace(e, max));
+
+		result.append("Caught here:" + newline);
+		result.append(getStackTrace(new Exception(), max, 1));
+		//		Debug.dumpStack();
+		result.append(newline);
+		return result.toString();
+	}
+
+	public static String getStackTrace(Throwable e)
+	{
+		return getStackTrace(e, -1);
+	}
+
+	public static String getStackTrace(Throwable e, int limit)
+	{
+		return getStackTrace(e, limit, 0);
+	}
+
+	public static String getStackTrace(Throwable e, int limit, int skip)
+	{
+		StringBuffer result = new StringBuffer();
+
+		if (e != null)
+		{
+			StackTraceElement stes[] = e.getStackTrace();
+			if (stes != null)
+			{
+				for (int i = skip; i < stes.length && (limit < 0 || i < limit); i++)
+				{
+					StackTraceElement ste = stes[i];
+
+					result.append("\tat " + ste.getClassName() + "."
+							+ ste.getMethodName() + "(" + ste.getFileName()
+							+ ":" + ste.getLineNumber() + ")" + newline);
+				}
+				if (limit >= 0 && stes.length > limit)
+					result.append("\t..." + newline);
+			}
+
+			//			e.printStackTrace(System.out);
+			result.append(newline);
+		}
+
+		return result.toString();
+	}
+
+	public static void debugByteQuad(String message, int i)
+	{
+		int alpha = (i >> 24) & 0xff;
+		int red = (i >> 16) & 0xff;
+		int green = (i >> 8) & 0xff;
+		int blue = (i >> 0) & 0xff;
+
+		System.out.println(message + ": " + "alpha: " + alpha + ", " + "red: "
+				+ red + ", " + "green: " + green + ", " + "blue: " + blue);
+	}
+
+	public static void debugIPQuad(String message, int i)
+	{
+		int b1 = (i >> 24) & 0xff;
+		int b2 = (i >> 16) & 0xff;
+		int b3 = (i >> 8) & 0xff;
+		int b4 = (i >> 0) & 0xff;
+
+		System.out.println(message + ": " + "b1: " + b1 + ", " + "b2: " + b2
+				+ ", " + "b3: " + b3 + ", " + "b4: " + b4);
+	}
+
+	public static void debugIPQuad(String message, byte bytes[])
+	{
+		System.out.print(message + ": ");
+		if (bytes == null)
+			System.out.print("null");
+		else
+		{
+			for (int i = 0; i < bytes.length; i++)
+			{
+				if (i > 0)
+					System.out.print(".");
+				System.out.print(0xff & bytes[i]);
+			}
+		}
+		System.out.println();
+	}
+
+	public static String getDebug(String prefix, Dimension r)
+	{
+		String s_ar1 = "null";
+		String s_ar2 = "null";
+
+		if (r != null)
+		{
+			double aspect_ratio = ((double) r.width) / ((double) r.height);
+			double aspect_ratio2 = 1.0 / aspect_ratio;
+
+			s_ar1 = "" + aspect_ratio;
+			s_ar2 = "" + aspect_ratio2;
+
+			if (s_ar1.length() > 7)
+				s_ar1 = s_ar1.substring(0, 7);
+			if (s_ar2.length() > 7)
+				s_ar2 = s_ar2.substring(0, 7);
+		}
+
+		return (prefix + ": "
+				+ ((r == null) ? "null" : (r.width + "x" + r.height))
+				+ " aspect_ratio: " + s_ar1 + " (" + s_ar2 + ")");
+	}
+
+	public static void debug(String prefix, Dimension r)
+	{
+		debug(getDebug(prefix, r));
+	}
+
+	public static String getDebug(String prefix, Rectangle r)
+	{
+		String s_ar1 = "null";
+		String s_ar2 = "null";
+
+		if (r != null)
+		{
+			double aspect_ratio = ((double) r.width) / ((double) r.height);
+			double aspect_ratio2 = 1.0 / aspect_ratio;
+
+			s_ar1 = "" + aspect_ratio;
+			s_ar2 = "" + aspect_ratio2;
+
+			if (s_ar1.length() > 7)
+				s_ar1 = s_ar1.substring(0, 7);
+			if (s_ar2.length() > 7)
+				s_ar2 = s_ar2.substring(0, 7);
+		}
+
+		return (prefix
+				+ ": "
+				+ ((r == null) ? "null" : (r.x + "x" + r.y + "," + r.width
+						+ "x" + r.height)) + " aspect_ratio: " + s_ar1 + " ("
+				+ s_ar2 + ")");
+	}
+
+	public static String getDebug(String prefix, Point p)
+	{
+		return (prefix + ": " + ((p == null) ? "null" : (p.x + ", " + p.y)));
+	}
+
+	public static void dump(String prefix, Object value)
+	{
+		if (value == null)
+			debug(prefix, "null");
+		else if (value instanceof Object[])
+		{
+			Object[] array = (Object[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				dump(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof int[])
+		{
+			int[] array = (int[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				debug(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof char[])
+		{
+			char[] array = (char[]) value;
+			debug(prefix, "[" + new String(array) + "]");
+		}
+		else if (value instanceof long[])
+		{
+			long[] array = (long[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				debug(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof boolean[])
+		{
+			boolean[] array = (boolean[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				debug(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof byte[])
+		{
+			byte[] array = (byte[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				debug(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof float[])
+		{
+			float[] array = (float[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				debug(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof byte[])
+		{
+			double[] array = (double[]) value;
+			debug(prefix, array);
+			for (int i = 0; i < array.length; i++)
+				debug(prefix + "\t" + i + ": ", array[i]);
+		}
+		else if (value instanceof java.util.List)
+		{
+			java.util.List list = (java.util.List) value;
+			debug(prefix, "list");
+			for (int i = 0; i < list.size(); i++)
+				dump(prefix + "\t" + "list: " + i + ": ", list.get(i));
+		}
+		else if (value instanceof Map)
+		{
+			java.util.Map map = (java.util.Map) value;
+			debug(prefix, "map");
+			Vector keys = new Vector(map.keySet());
+			Collections.sort(keys);
+			for (int i = 0; i < keys.size(); i++)
+			{
+				Object key = keys.get(i);
+				dump(prefix + "\t" + "map: " + key + " -> ", map.get(key));
+			}
+		}
+		//		else if (value instanceof String)
+		//			debug(prefix, value);
+		else
+		{
+			debug(prefix, value.toString());
+			debug(prefix + "\t", value.getClass().getName());
+		}
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/Debug.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugInputStream.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugInputStream.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugInputStream.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugInputStream.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.cmc.sanselan.util;
+
+import java.io.*;
+
+public class DebugInputStream extends InputStream
+{
+	private final InputStream is;
+
+	public DebugInputStream(InputStream is)
+	{
+		this.is = is;
+	}
+
+	private long bytes_read = 0;
+
+	public int read() throws IOException
+	{
+		int result = is.read();
+		bytes_read++;
+		return result;
+	}
+
+	public long skip(long n) throws IOException
+	{
+		long result = is.skip(n);
+		bytes_read += n;
+		return result;
+	}
+
+	public int available() throws IOException
+	{
+		return is.available();
+	}
+
+	public void close() throws IOException
+	{
+		is.close();
+	}
+
+	public long getBytesRead()
+	{
+		return bytes_read;
+	}
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugOutputStream.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugOutputStream.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugOutputStream.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.cmc.sanselan.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class DebugOutputStream extends OutputStream
+{
+	private final OutputStream os;
+	private long count = 0;
+
+	public DebugOutputStream(final OutputStream os)
+	{
+		super();
+		this.os = os;
+	}
+
+	public void write(int b) throws IOException
+	{
+		os.write(b);
+		count++;
+	}
+
+	public void write(byte b[]) throws IOException
+	{
+		os.write(b);
+		count += b.length;
+	}
+
+	public void write(byte b[], int off, int len) throws IOException
+	{
+		os.write(b, off, len);
+		count += len;
+	}
+
+	public void flush() throws IOException
+	{
+		os.flush();
+	}
+
+	public void close() throws IOException
+	{
+		os.close();
+	}
+
+	public long count()
+	{
+		return count;
+	}
+}

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/DebugOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/IOUtils.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/IOUtils.java?rev=596008&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/IOUtils.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/IOUtils.java Sat Nov 17 13:58:22 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cmc.sanselan.util;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.cmc.sanselan.SanselanConstants;
+
+public class IOUtils implements SanselanConstants
+{
+
+	/** 
+	 * Reads an InputStream to the end.
+	 * <p>
+	 * @param  is The InputStream to read.
+	 * @return A byte array containing the contents of the InputStream
+	 * @see InputStream
+	 */
+	public static byte[] getInputStreamBytes(InputStream is) throws IOException
+	{
+		ByteArrayOutputStream os = null;
+
+		try
+		{
+			os = new ByteArrayOutputStream(4096);
+
+			is = new BufferedInputStream(is);
+
+			int count;
+			byte[] buffer = new byte[4096];
+			while ((count = is.read(buffer, 0, 4096)) > 0)
+			{
+				os.write(buffer, 0, count);
+			}
+
+			os.flush();
+
+			return os.toByteArray();
+		}
+		finally
+		{
+			try
+			{
+				if (os != null)
+					os.close();
+			}
+			catch (IOException e)
+			{
+				Debug.debug(e);
+			}
+		}
+	}
+
+	/** 
+	 * Reads a File into memory.
+	 * <p>
+	 * @param  is The File to read.
+	 * @return A byte array containing the contents of the File
+	 * @see InputStream
+	 */
+	public static byte[] getFileBytes(File file) throws IOException
+	{
+		InputStream is = null;
+
+		try
+		{
+			is = new FileInputStream(file);
+
+			return getInputStreamBytes(is);
+		}
+		finally
+		{
+			try
+			{
+				if (is != null)
+					is.close();
+			}
+			catch (IOException e)
+			{
+				Debug.debug(e);
+			}
+		}
+	}
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/cmc/sanselan/util/IOUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native