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:38:46 UTC

svn commit: r596006 [2/2] - in /incubator/sanselan/trunk/src: main/java/org/apache/sanselan/ main/java/org/apache/sanselan/common/ main/java/org/apache/sanselan/common/byteSources/ main/java/org/apache/sanselan/formats/bmp/ main/java/org/apache/sansela...

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java Sat Nov 17 13:38:44 2007
@@ -26,7 +26,7 @@
 import java.util.Map;
 
 import org.apache.sanselan.ImageReadException;
-import org.apache.sanselan.common.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSource;
 import org.apache.sanselan.formats.tiff.fieldtypes.FieldType;
 
 public class TiffField

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java Sat Nov 17 13:38:44 2007
@@ -32,10 +32,10 @@
 import org.apache.sanselan.ImageParser;
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.ImageWriteException;
-import org.apache.sanselan.common.ByteSource;
-import org.apache.sanselan.common.ByteSourceArray;
-import org.apache.sanselan.common.ByteSourceFile;
 import org.apache.sanselan.common.IImageMetadata;
+import org.apache.sanselan.common.byteSources.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSourceArray;
+import org.apache.sanselan.common.byteSources.ByteSourceFile;
 import org.apache.sanselan.formats.tiff.TiffDirectory.ImageDataElement;
 import org.apache.sanselan.formats.tiff.datareaders.DataReader;
 import org.apache.sanselan.formats.tiff.datareaders.DataReaderStrips;

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReader.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReader.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReader.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReader.java Sat Nov 17 13:38:44 2007
@@ -24,8 +24,8 @@
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.common.BinaryConstants;
 import org.apache.sanselan.common.BitInputStream;
-import org.apache.sanselan.common.ByteSource;
 import org.apache.sanselan.common.PackBits;
+import org.apache.sanselan.common.byteSources.ByteSource;
 import org.apache.sanselan.common.mylzw.MyLZWDecompressor;
 import org.apache.sanselan.formats.tiff.TiffConstants;
 import org.apache.sanselan.formats.tiff.photometricinterpreters.PhotometricInterpreter;

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderStrips.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderStrips.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderStrips.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderStrips.java Sat Nov 17 13:38:44 2007
@@ -22,7 +22,7 @@
 
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.common.BitInputStream;
-import org.apache.sanselan.common.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSource;
 import org.apache.sanselan.formats.tiff.photometricinterpreters.PhotometricInterpreter;
 
 public class DataReaderStrips extends DataReader

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderTiled.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderTiled.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderTiled.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/datareaders/DataReaderTiled.java Sat Nov 17 13:38:44 2007
@@ -22,7 +22,7 @@
 
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.common.BitInputStream;
-import org.apache.sanselan.common.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSource;
 import org.apache.sanselan.formats.tiff.photometricinterpreters.PhotometricInterpreter;
 
 public class DataReaderTiled extends DataReader

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/icc/IccProfileParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/icc/IccProfileParser.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/icc/IccProfileParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/icc/IccProfileParser.java Sat Nov 17 13:38:44 2007
@@ -19,12 +19,14 @@
 import java.awt.color.ICC_Profile;
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.sanselan.common.BinaryFileParser;
-import org.apache.sanselan.common.ByteSource;
-import org.apache.sanselan.common.ByteSourceArray;
-import org.apache.sanselan.common.ByteSourceFile;
+import org.apache.sanselan.common.byteSources.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSourceArray;
+import org.apache.sanselan.common.byteSources.ByteSourceFile;
+import org.apache.sanselan.util.CachingInputStream;
 import org.apache.sanselan.util.Debug;
 
 public class IccProfileParser extends BinaryFileParser implements IccConstants
@@ -60,24 +62,17 @@
 
 	public IccProfileInfo getICCProfileInfo(ByteSource byteSource)
 	{
-		//		if (debug)
-		//			Debug.debug("getICCProfileInfo" + ": " + file.getName());
 
 		InputStream is = null;
 
 		try
 		{
-			//			is = byteSource.getInputStream();
-			//
-			//			IccProfileInfo result = getICCProfileInfo(byteSource.getAll(), is,
-			//					byteSource.getLength());
 
 			IccProfileInfo result;
 			{
-				byte bytes[] = byteSource.getAll();
-				is = new ByteArrayInputStream(bytes);
+				is = byteSource.getInputStream();
 
-				result = getICCProfileInfo(bytes, is, bytes.length);
+				result = readICCProfileInfo(is);
 			}
 
 			if (result == null)
@@ -123,31 +118,33 @@
 		return null;
 	}
 
-	private IccProfileInfo getICCProfileInfo(byte data[], InputStream is,
-			long length)
+	private IccProfileInfo readICCProfileInfo(InputStream is)
 	{
+		CachingInputStream cis = new CachingInputStream(is);
+		is = cis;
+
 		if (debug)
 			Debug.debug();
 
 		//				setDebug(true);
 
-		if (debug)
-			Debug.debug("length: " + length);
+		//		if (debug)
+		//			Debug.debug("length: " + length);
 
 		try
 		{
 			int ProfileSize = read4Bytes("ProfileSize", is,
 					"Not a Valid ICC Profile");
 
-			if (length != ProfileSize)
-			{
-				//				Debug.debug("Unexpected Length data expected: " + Integer.toHexString((int) length)
-				//						+ ", encoded: " + Integer.toHexString(ProfileSize));
-				//				Debug.debug("Unexpected Length data: " + length
-				//						+ ", length: " + ProfileSize);
-				//				throw new Error("asd");
-				return null;
-			}
+			//			if (length != ProfileSize)
+			//			{
+			//				//				Debug.debug("Unexpected Length data expected: " + Integer.toHexString((int) length)
+			//				//						+ ", encoded: " + Integer.toHexString(ProfileSize));
+			//				//				Debug.debug("Unexpected Length data: " + length
+			//				//						+ ", length: " + ProfileSize);
+			//				//				throw new Error("asd");
+			//				return null;
+			//			}
 
 			int CMMTypeSignature = read4Bytes("Signature", is,
 					"Not a Valid ICC Profile");
@@ -267,6 +264,17 @@
 				//				tags .add(tag);
 			}
 
+			{
+				// read stream to end, filling cache.
+				while (is.read() >= 0)
+					;
+			}
+
+			byte data[] = cis.getCache();
+
+			if (data.length < ProfileSize)
+				throw new IOException("Couldn't read ICC Profile.");
+
 			IccProfileInfo result = new IccProfileInfo(data, ProfileSize,
 					CMMTypeSignature, ProfileVersion,
 					ProfileDeviceClassSignature, ColorSpace,
@@ -330,18 +338,18 @@
 
 			//			setDebug(true);
 
-			long length = byteSource.getLength();
-
-			if (debug)
-				Debug.debug("length: " + length);
+			//			long length = byteSource.getLength();
+			//
+			//			if (debug)
+			//				Debug.debug("length: " + length);
 
 			InputStream is = byteSource.getInputStream();
 
 			int ProfileSize = read4Bytes("ProfileSize", is,
 					"Not a Valid ICC Profile");
 
-			if (length != ProfileSize)
-				return null;
+			//			if (length != ProfileSize)
+			//				return null;
 
 			this.skipBytes(is, 4 * 5);
 

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/CachingInputStream.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/CachingInputStream.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/CachingInputStream.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/CachingInputStream.java Sat Nov 17 13:38:44 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.apache.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/apache/sanselan/util/CachingInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugInputStream.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugInputStream.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugInputStream.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugInputStream.java Sat Nov 17 13:38:44 2007
@@ -1,10 +1,20 @@
 /*
- * 
- * www.digilabs.biz
- * 
- * Created on Dec 31, 2005
+ * 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.apache.sanselan.util;
 

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugOutputStream.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugOutputStream.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/DebugOutputStream.java Sat Nov 17 13:38:44 2007
@@ -1,10 +1,20 @@
 /*
- * 
-
- * 
- * Created on Dec 31, 2005
+ * 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.apache.sanselan.util;
 

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/IOUtils.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/IOUtils.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/IOUtils.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/util/IOUtils.java Sat Nov 17 13:38:44 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.apache.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.apache.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/apache/sanselan/util/IOUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/AppTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/AppTest.java?rev=596006&r1=596005&r2=596006&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/AppTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/AppTest.java Sat Nov 17 13:38:44 2007
@@ -1,3 +1,20 @@
+/*
+ * 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.apache.sanselan;
 
 import junit.framework.Test;
@@ -7,32 +24,31 @@
 /**
  * Unit test for simple App.
  */
-public class AppTest 
-    extends TestCase
+public class AppTest extends TestCase
 {
-    /**
-     * Create the test case
-     *
-     * @param testName name of the test case
-     */
-    public AppTest( String testName )
-    {
-        super( testName );
-    }
+	/**
+	 * Create the test case
+	 *
+	 * @param testName name of the test case
+	 */
+	public AppTest(String testName)
+	{
+		super(testName);
+	}
 
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite()
-    {
-        return new TestSuite( AppTest.class );
-    }
+	/**
+	 * @return the suite of tests being tested
+	 */
+	public static Test suite()
+	{
+		return new TestSuite(AppTest.class);
+	}
 
-    /**
-     * Rigourous Test :-)
-     */
-    public void testApp()
-    {
-        assertTrue( true );
-    }
+	/**
+	 * Rigourous Test :-)
+	 */
+	public void testApp()
+	{
+		assertTrue(true);
+	}
 }

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java Sat Nov 17 13:38:44 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.apache.sanselan;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.sanselan.test.util.FSTraversal;
+import org.apache.sanselan.util.Debug;
+
+public abstract class SanselanTest extends TestCase
+{
+	public SanselanTest(String name)
+	{
+		super(name);
+	}
+	
+	public void compareByteArrays(byte a[], byte b[])
+	{
+		assertTrue(a.length == b.length);
+		for (int i = 0; i < b.length; i++)
+			assertTrue(b[i] == a[i]);
+	}
+
+	protected void purgeMemory()
+	{
+		try
+		{
+			System.gc();
+			Thread.sleep(50);
+			System.runFinalization();
+			Thread.sleep(50);
+		}
+		catch (Exception e)
+		{
+			Debug.debug(e);
+		}
+	}
+
+	protected List getAllTestImages()
+	{
+		File srcFolder = new File(".", "src");
+		File testFolder = new File(srcFolder, "test");
+		File dataFolder = new File(testFolder, "data");
+		File imagesFolder = new File(dataFolder, "images");
+
+		final List result = new ArrayList();
+
+		FSTraversal.Visitor visitor = new FSTraversal.Visitor()
+		{
+			public boolean visit(File file, double progressEstimate)
+			{
+				if (Sanselan.hasImageFileExtension(file))
+					result.add(file);
+				return false;
+			}
+		};
+		new FSTraversal().traverseFiles(imagesFolder, visitor);
+
+		return result;
+	}
+	
+	protected File getTestImage()
+	{
+		List images = getAllTestImages();
+		if(images.size()<1)
+			return null;
+		return (File) images.get(0);
+	}
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java Sat Nov 17 13:38:44 2007
@@ -0,0 +1,160 @@
+/*
+ * 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.apache.sanselan.common.byteSources;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.sanselan.util.Debug;
+import org.apache.sanselan.util.IOUtils;
+
+public class ByteSourceDataTest extends ByteSourceTest
+{
+	public ByteSourceDataTest()
+	{
+		super(ByteSourceDataTest.class.getName());
+	}
+
+	/**
+	 * @return the suite of tests being tested
+	 */
+	public static Test suite()
+	{
+		return new TestSuite(ByteSourceDataTest.class);
+	}
+
+	private interface ByteSourceFactory
+	{
+		public ByteSource getByteSource(byte src[]) throws IOException;
+	}
+
+	private class ByteSourceFileFactory implements ByteSourceFactory
+	{
+		public ByteSource getByteSource(byte src[]) throws IOException
+		{
+			File file = createTempFile(src);
+
+			// test that all bytes written to file.
+			assertTrue(src.length == file.length());
+
+			ByteSource byteSource = new ByteSourceFile(file);
+			return byteSource;
+		}
+	}
+
+	private class ByteSourceInputStreamFileFactory implements ByteSourceFactory
+	{
+		public ByteSource getByteSource(byte src[]) throws IOException
+		{
+			File file = createTempFile(src);
+
+			FileInputStream is = new FileInputStream(file);
+
+			ByteSource byteSource = new ByteSourceInputStream(is, null);
+			return byteSource;
+		}
+	}
+
+	private class ByteSourceInputStreamRawFactory implements ByteSourceFactory
+	{
+		public ByteSource getByteSource(byte src[]) throws IOException
+		{
+			ByteArrayInputStream is = new ByteArrayInputStream(src);
+
+			ByteSource byteSource = new ByteSourceInputStream(is, null);
+			return byteSource;
+		}
+
+	}
+
+	protected void writeAndReadBytes(ByteSourceFactory byteSourceFactory,
+			byte src[]) throws IOException
+	{
+		ByteSource byteSource = byteSourceFactory.getByteSource(src);
+
+		// test cache during interrupted read cache by reading only first N bytes.
+		{
+			InputStream is = byteSource.getInputStream();
+			byte prefix[] = new byte[256];
+			int read = is.read(prefix);
+
+			assertTrue(read <= src.length);
+			for (int i = 0; i < read; i++)
+				assertTrue(src[i] == prefix[i]);
+		}
+
+		// test cache by completely reading InputStream N times.
+		for (int j = 0; j < 5; j++)
+		{
+			InputStream is = byteSource.getInputStream();
+			byte dst[] = IOUtils.getInputStreamBytes(is);
+
+			compareByteArrays(src, dst);
+		}
+
+		{
+			// test getAll() method.
+			byte all[] = byteSource.getAll();
+			compareByteArrays(src, all);
+		}
+
+		if (src.length > 2)
+		{
+			// test optional start param to getInputStream()
+
+			int start = src.length / 2;
+
+			InputStream is = byteSource.getInputStream(start);
+			byte dst[] = IOUtils.getInputStreamBytes(is);
+
+			assertTrue(src.length == dst.length + start);
+			for (int i = 0; i < dst.length; i++)
+				assertTrue(dst[i] == src[i + start]);
+		}
+
+	}
+
+	public void test() throws IOException
+	{
+		ByteSourceFactory byteSourceFactories[] = {
+				new ByteSourceFileFactory(),
+				new ByteSourceInputStreamFileFactory(),
+				new ByteSourceInputStreamRawFactory(),
+		};
+
+		byte testByteArrays[][] = getTestByteArrays();
+
+		for (int i = 0; i < testByteArrays.length; i++)
+		{
+			byte testByteArray[] = testByteArrays[i];
+
+			for (int j = 0; j < byteSourceFactories.length; j++)
+			{
+				ByteSourceFactory byteSourceFactory = byteSourceFactories[j];
+
+				writeAndReadBytes(byteSourceFactory, testByteArray);
+			}
+		}
+	}
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java Sat Nov 17 13:38:44 2007
@@ -0,0 +1,185 @@
+/*
+ * 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.apache.sanselan.common.byteSources;
+
+import java.awt.Dimension;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.sanselan.ImageFormat;
+import org.apache.sanselan.ImageInfo;
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.util.Debug;
+import org.apache.sanselan.util.IOUtils;
+
+public class ByteSourceImageTest extends ByteSourceTest
+{
+	public ByteSourceImageTest()
+	{
+		super(ByteSourceImageTest.class.getName());
+	}
+
+	/**
+	 * @return the suite of tests being tested
+	 */
+	public static Test suite()
+	{
+		return new TestSuite(ByteSourceImageTest.class);
+	}
+
+	public void test() throws IOException, ImageReadException,
+			IllegalAccessException, IllegalArgumentException,
+			InvocationTargetException
+	{
+		File imageFile = getTestImage();
+		Debug.debug("imageFile", imageFile);
+		assertTrue(imageFile != null);
+
+		byte imageFileBytes[] = IOUtils.getFileBytes(imageFile);
+		assertTrue(imageFileBytes != null);
+		assertTrue(imageFileBytes.length == imageFile.length());
+
+		checkGuessFormat(imageFile, imageFileBytes);
+
+		checkGetICCProfileBytes(imageFile, imageFileBytes);
+
+		checkGetImageInfo(imageFile, imageFileBytes);
+
+		checkGetImageSize(imageFile, imageFileBytes);
+
+		checkGetBufferedImage(imageFile, imageFileBytes);
+	}
+
+	public void checkGetBufferedImage(File file, byte[] bytes)
+			throws IOException, ImageReadException
+	{
+		BufferedImage imageFile = Sanselan.getBufferedImage(file);
+		assertTrue(imageFile != null);
+		assertTrue(imageFile.getWidth() > 0);
+		assertTrue(imageFile.getHeight() > 0);
+
+		BufferedImage imageBytes = Sanselan.getBufferedImage(bytes);
+		assertTrue(imageBytes != null);
+		assertTrue(imageFile.getWidth() == imageBytes.getWidth());
+		assertTrue(imageFile.getHeight() == imageBytes.getHeight());
+	}
+
+	public void checkGetImageSize(File imageFile, byte[] imageFileBytes)
+			throws IOException, ImageReadException
+	{
+		Dimension imageSizeFile = Sanselan.getImageSize(imageFile);
+		assertTrue(imageSizeFile != null);
+		assertTrue(imageSizeFile.width > 0);
+		assertTrue(imageSizeFile.height > 0);
+
+		Dimension imageSizeBytes = Sanselan.getImageSize(imageFileBytes);
+		assertTrue(imageSizeBytes != null);
+		assertTrue(imageSizeFile.width == imageSizeBytes.width);
+		assertTrue(imageSizeFile.height == imageSizeBytes.height);
+	}
+
+	public void checkGuessFormat(File imageFile, byte[] imageFileBytes)
+			throws IOException, ImageReadException
+	{
+		// check guessFormat()
+		ImageFormat imageFormatFile = Sanselan.guessFormat(imageFile);
+		assertTrue(imageFormatFile != null);
+		assertTrue(imageFormatFile != ImageFormat.IMAGE_FORMAT_UNKNOWN);
+		//		Debug.debug("imageFormatFile", imageFormatFile);
+
+		ImageFormat imageFormatBytes = Sanselan.guessFormat(imageFileBytes);
+		assertTrue(imageFormatBytes != null);
+		assertTrue(imageFormatBytes != ImageFormat.IMAGE_FORMAT_UNKNOWN);
+		//		Debug.debug("imageFormatBytes", imageFormatBytes);
+
+		assertTrue(imageFormatBytes == imageFormatFile);
+	}
+
+	public void checkGetICCProfileBytes(File imageFile, byte[] imageFileBytes)
+			throws IOException, ImageReadException
+	{
+		// check guessFormat()
+		byte iccBytesFile[] = Sanselan.getICCProfileBytes(imageFile);
+
+		byte iccBytesBytes[] = Sanselan.getICCProfileBytes(imageFileBytes);
+
+		assertTrue((iccBytesFile != null) == (iccBytesBytes != null));
+
+		if (iccBytesFile == null)
+			return;
+
+		compareByteArrays(iccBytesFile, iccBytesBytes);
+	}
+
+	public void checkGetImageInfo(File imageFile, byte[] imageFileBytes)
+			throws IOException, ImageReadException, IllegalAccessException,
+			IllegalArgumentException, InvocationTargetException
+	{
+		// check guessFormat()
+		ImageInfo imageInfoFile = Sanselan.getImageInfo(imageFile);
+
+		ImageInfo imageInfoBytes = Sanselan.getImageInfo(imageFileBytes);
+
+		assertTrue(imageInfoFile != null);
+		assertTrue(imageInfoBytes != null);
+
+		Method methods[] = ImageInfo.class.getMethods();
+		for (int i = 0; i < methods.length; i++)
+		{
+			Method method = methods[i];
+			method.getModifiers();
+			if (!Modifier.isPublic(method.getModifiers()))
+				continue;
+			if (!method.getName().startsWith("get"))
+				continue;
+			if (method.getName().equals("getClass"))
+				continue;
+			if (method.getGenericParameterTypes().length > 0)
+				continue;
+
+			Object valueFile = method.invoke(imageInfoFile, null);
+			Object valueBytes = method.invoke(imageInfoBytes, null);
+
+			assertTrue(valueFile.equals(valueBytes));
+		}
+
+		// only have to test values from imageInfoFile; we already know values match.
+		assertTrue(imageInfoFile.getBitsPerPixel() > 0);
+
+		assertTrue(imageInfoFile.getFormat() != null);
+		assertTrue(imageInfoFile.getFormat() != ImageFormat.IMAGE_FORMAT_UNKNOWN);
+
+		assertTrue(imageInfoFile.getFormatName() != null);
+
+		assertTrue(imageInfoFile.getWidth() > 0);
+		assertTrue(imageInfoFile.getHeight() > 0);
+
+		assertTrue(imageInfoFile.getMimeType() != null);
+
+		assertTrue(imageInfoFile.getNumberOfImages() > 0);
+
+	}
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java Sat Nov 17 13:38:44 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.apache.sanselan.common.byteSources;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.sanselan.SanselanTest;
+
+public abstract class ByteSourceTest extends SanselanTest
+{
+	public ByteSourceTest(String name)
+	{
+		super(name);
+	}
+
+
+
+	protected File createTempFile(byte src[]) throws IOException
+	{
+		// make temp file directory
+		File tmp = new File(".", "tmp");
+		tmp.mkdirs();
+
+		// create temp file.
+		File file = File.createTempFile("raw_", ".bin", tmp);
+		file.deleteOnExit();
+
+		// write test bytes to file.
+		OutputStream os = new FileOutputStream(file);
+		os = new BufferedOutputStream(os);
+		os.write(src);
+		os.close();
+
+		// test that all bytes written to file.
+		assertTrue(src.length == file.length());
+
+		return file;
+	}
+
+	protected byte[][] getTestByteArrays()
+	{
+		byte emptyArray[] = (new byte[0]);
+
+		byte single[] = new byte[1];
+		for (int i = 0; i < single.length; i++)
+			single[i] = (byte) i;
+
+		byte simple[] = new byte[256];
+		for (int i = 0; i < simple.length; i++)
+			simple[i] = (byte) i;
+
+		byte zeroes[] = new byte[256];
+		for (int i = 0; i < zeroes.length; i++)
+			zeroes[i] = 0;
+
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		for (int i = 0; i < 256 * 256; i++)
+		{
+			baos.write(0xff & i);
+			baos.write(0xff & (i >> 8));
+		}
+		byte longArray[] = (baos.toByteArray());
+
+		return new byte[][]{
+				emptyArray, single, simple, zeroes, longArray,
+		};
+	}
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java Sat Nov 17 13:38:44 2007
@@ -0,0 +1,133 @@
+/*
+ * 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.apache.sanselan.formats.png;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sanselan.ImageFormat;
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.SanselanTest;
+import org.apache.sanselan.util.Debug;
+
+public class PngWriteReadTest extends SanselanTest
+{
+	public PngWriteReadTest(String name)
+	{
+		super(name);
+	}
+
+	private int[][] getSimpleRawData(int width, int height, int value)
+	{
+		int[][] result = new int[height][width];
+		for (int y = 0; y < height; y++)
+			for (int x = 0; x < width; x++)
+				result[y][x] = value;
+		return result;
+	}
+
+	public void test() throws IOException, ImageReadException,
+			ImageWriteException
+	{
+		int[][] singleBlackPixels = getSimpleRawData(256, 256, 0);
+		int[][] singleBlackPixel = getSimpleRawData(1, 1, 0);
+
+		int[][][] testData = {
+				singleBlackPixels, singleBlackPixel,
+		};
+		
+		for (int i = 0; i < testData.length; i++)
+		{
+			int rawData[][] = testData[i];
+			writeAndReadImageData(rawData);
+		}
+	}
+
+	private BufferedImage imageDataToBufferedImage(int[][] rawData)
+	{
+		int width = rawData[0].length;
+		int height = rawData.length;
+		BufferedImage image = new BufferedImage(width, height,
+				BufferedImage.TYPE_INT_ARGB);
+		for (int y = 0; y < height; y++)
+			for (int x = 0; x < width; x++)
+			{
+				image.setRGB(x, y, rawData[y][x]);
+			}
+		return image;
+	}
+
+	private int[][] bufferedImageToImageData(BufferedImage image)
+	{
+		int width = image.getWidth();
+		int height = image.getHeight();
+		int[][] result = new int[height][width];
+
+		for (int y = 0; y < height; y++)
+			for (int x = 0; x < width; x++)
+			{
+				result[y][x] = image.getRGB(x, y);
+			}
+		return result;
+	}
+
+	private void writeAndReadImageData(int[][] rawData) throws IOException,
+			ImageReadException, ImageWriteException
+	{
+		BufferedImage srcImage = imageDataToBufferedImage(rawData);
+
+		Map writeParams = new HashMap();
+		//		writeParams.put(SanselanConstants.PARAM_KEY_FORMAT, ImageFormat.IMAGE_FORMAT_PNG);
+		//		writeParams.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
+		//				Boolean.TRUE);
+
+		byte bytes[] = Sanselan.writeImageToBytes(srcImage,
+				ImageFormat.IMAGE_FORMAT_PNG, writeParams);
+
+		Debug.debug("bytes", bytes);
+
+		BufferedImage dstImage = Sanselan.getBufferedImage(bytes);
+		assertTrue(null != dstImage);
+		assertTrue(srcImage.getWidth() == dstImage.getWidth());
+		assertTrue(srcImage.getHeight() == dstImage.getHeight());
+
+		int dstData[][] = bufferedImageToImageData(dstImage);
+		compare(rawData, dstData);
+	}
+
+	private void compare(int[][] a, int[][] b)
+	{
+		assertTrue(null != a);
+		assertTrue(null != b);
+		assertTrue(a.length == b.length);
+
+		for (int y = 0; y < a.length; y++)
+		{
+			assertTrue(a[y].length == b[y].length);
+			// make sure row lengths consistent.
+			assertTrue(a[0].length == b[y].length);
+			for (int x = 0; x < a[y].length; x++)
+				assertTrue(a[y][x] == b[y][x]);
+		}
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/test/util/FSTraversal.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/test/util/FSTraversal.java?rev=596006&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/test/util/FSTraversal.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/test/util/FSTraversal.java Sat Nov 17 13:38:44 2007
@@ -0,0 +1,191 @@
+/*
+ * 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.apache.sanselan.test.util;
+
+import java.io.File;
+
+import org.apache.sanselan.util.Debug;
+
+public class FSTraversal
+{
+
+	public static final int MODE_FILES = 1;
+	public static final int MODE_FOLDERS = 2;
+	public static final int MODE_FILES_AND_FOLDERS = 3;
+	public static final int MODE_ALL = 4;
+
+	public interface Visitor
+	{
+		public boolean visit(File file, double progressEstimate);
+	}
+
+	public boolean traverseFiles(File file, Visitor visitor)
+	{
+
+		return traverse(file, MODE_FILES, visitor);
+	}
+
+	public boolean traverseFolders(File file, Visitor visitor)
+	{
+
+		return traverse(file, MODE_FOLDERS, visitor);
+	}
+
+	public boolean traverseAll(File file, Visitor visitor)
+	{
+
+		return traverse(file, MODE_FILES_AND_FOLDERS, visitor);
+	}
+
+	public boolean traverse(File file, int mode, Visitor visitor)
+	{
+		return traverse(file, mode, visitor, 0, 1);
+	}
+
+	private boolean traverse(File file, int mode, Visitor visitor,
+			double estimate, double estimateIncrement)
+	{
+
+		if (file.isFile())
+		{
+			if ((mode == MODE_FILES) || (mode == MODE_FILES_AND_FOLDERS)
+					|| (mode == MODE_ALL))
+			{
+				if (!visitor.visit(file, estimate))
+					return false;
+			}
+		}
+		else if (file.isDirectory())
+		{
+			File files[] = file.listFiles();
+			if (files != null)
+			{
+				for (int i = 0; i < files.length; i++)
+				{
+					File child = files[i];
+					if (ON_MAC_OS_X && child.isDirectory())
+					{
+						String name = child.getName();
+						if (name.equalsIgnoreCase("automount")
+								|| name.equalsIgnoreCase("private")
+								|| name.equalsIgnoreCase("Network")
+								|| name.equalsIgnoreCase("Volumes"))
+						{
+							continue;
+							//							return true;
+						}
+					}
+
+					if (!traverse(child, mode, visitor, estimate
+							+ estimateIncrement * i / files.length,
+							estimateIncrement / files.length))
+						return false;
+				}
+			}
+
+			if ((mode == MODE_FOLDERS) || (mode == MODE_FILES_AND_FOLDERS)
+					|| (mode == MODE_ALL))
+			{
+				if (!visitor.visit(file, estimate))
+					return false;
+			}
+		}
+		else
+		{
+			if (mode == MODE_ALL)
+			{
+				if (!visitor.visit(file, estimate))
+					return false;
+			}
+		}
+
+		return true;
+	}
+
+	public boolean traverseFiles(Visitor visitor)
+	{
+
+		return traverse(MODE_FILES, visitor);
+	}
+
+	public boolean traverseFolders(Visitor visitor)
+	{
+
+		return traverse(MODE_FOLDERS, visitor);
+	}
+
+	public boolean traverseAll(Visitor visitor)
+	{
+
+		return traverse(MODE_FILES_AND_FOLDERS, visitor);
+	}
+
+	public boolean traverse(int mode, Visitor visitor)
+	{
+		return traverse(mode, visitor, 0, 1);
+	}
+
+	private static boolean ON_MAC_OS_X;
+
+	static
+	{
+		try
+		{
+			ON_MAC_OS_X = (System.getProperty("mrj.version") != null);
+		}
+		catch (Exception e)
+		{
+			Debug.debug(e);
+
+			ON_MAC_OS_X = false;
+		}
+	}
+
+	private boolean traverse(int mode, Visitor visitor, double estimate,
+			double estimateIncrement)
+	{
+		File roots[] = File.listRoots();
+
+		if (ON_MAC_OS_X)
+		{
+			File Volumes = new File("/Volumes/");
+			roots = Volumes.listFiles();
+		}
+		else
+			roots = File.listRoots();
+
+		if (roots == null)
+			return false;
+
+		for (int i = 0; i < roots.length; i++)
+		{
+			File root = roots[i];
+
+			if (root == null || !root.exists())
+				continue;
+
+			if (!traverse(roots[i], mode, visitor, estimate
+					+ estimateIncrement * i / roots.length, estimateIncrement
+					/ roots.length))
+				return false;
+		}
+
+		return true;
+	}
+
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/test/util/FSTraversal.java
------------------------------------------------------------------------------
    svn:eol-style = native