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 2008/07/27 19:42:40 UTC

svn commit: r680169 - in /incubator/sanselan/trunk: ./ src/main/java/org/apache/sanselan/formats/png/ src/main/java/org/apache/sanselan/formats/png/chunks/ src/test/java/org/apache/sanselan/common/byteSources/ src/test/java/org/apache/sanselan/formats/...

Author: cmchen
Date: Sun Jul 27 12:42:40 2008
New Revision: 680169

URL: http://svn.apache.org/viewvc?rev=680169&view=rev
Log:
* Improved handling of tEXt and zTXt PNG text blocks.
 * Added XMP XML extraction for the following formats: PNG.

Added:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkiTXt.java   (with props)
Modified:
    incubator/sanselan/trunk/RELEASE_NOTES
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunktEXt.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkzTXt.java
    incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java
    incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
    incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
    incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java

Modified: incubator/sanselan/trunk/RELEASE_NOTES
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/RELEASE_NOTES?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/RELEASE_NOTES (original)
+++ incubator/sanselan/trunk/RELEASE_NOTES Sun Jul 27 12:42:40 2008
@@ -15,6 +15,8 @@
 Release 0.95
 ------------
 
+ * Improved handling of tEXt and zTXt PNG text blocks.
+ * Added XMP XML extraction for the following formats: GIF (untested), JPEG, TIFF, PNG.
  * Added RELEASE_NOTES file (this file).
  * Added Apache license header to bin.xml and src.xml Maven assembly descriptors.
  * Added Javadocs to the binary distribution

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java Sun Jul 27 12:42:40 2008
@@ -57,7 +57,11 @@
 	public final static int gAMA = PngImageParser.CharsToQuad('g', 'A', 'M',
 			'A');
 	public final static int sRGB = PngImageParser.CharsToQuad('s', 'R', 'G',
-			'B');
+	'B');
+	
+	// XMP chunk type.
+	public final static int iTXt = PngImageParser.CharsToQuad('i', 'T', 'X',
+	't');
 
 	public static final byte PNG_Signature[] = {
 			(byte) 137, 80, 78, 71, 13, 10, 26, 10,
@@ -101,4 +105,7 @@
 	 Time 	The time when the PNG image was last modified.
 	 Transparency 	Alpha information that allows the reference image to be reconstructed when the alpha channel is not retained in the PNG image.
 	 */
+	
+	public final String XMP_KEYWORD = 	"XML:com.adobe.xmp";
+
 }
\ No newline at end of file

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageParser.java?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageParser.java Sun Jul 27 12:42:40 2008
@@ -30,6 +30,7 @@
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.zip.InflaterInputStream;
 
@@ -48,6 +49,7 @@
 import org.apache.sanselan.formats.png.chunks.PNGChunkPLTE;
 import org.apache.sanselan.formats.png.chunks.PNGChunkgAMA;
 import org.apache.sanselan.formats.png.chunks.PNGChunkiCCP;
+import org.apache.sanselan.formats.png.chunks.PNGChunkiTXt;
 import org.apache.sanselan.formats.png.chunks.PNGChunkpHYs;
 import org.apache.sanselan.formats.png.chunks.PNGChunktEXt;
 import org.apache.sanselan.formats.png.chunks.PNGChunkzTXt;
@@ -58,7 +60,6 @@
 import org.apache.sanselan.formats.transparencyfilters.TransparencyFilterTrueColor;
 import org.apache.sanselan.icc.IccProfileParser;
 import org.apache.sanselan.util.Debug;
-import org.apache.sanselan.util.IOUtils;
 import org.apache.sanselan.util.ParamMap;
 
 public class PngImageParser extends ImageParser implements PngConstants
@@ -96,22 +97,22 @@
 
 	// private final static int tRNS = CharsToQuad('t', 'R', 'N', 's');
 
-	private boolean keepChunk(int ChunkType, int ChunkTypes[])
+	private boolean keepChunk(int ChunkType, int chunkTypes[])
 	{
 		// System.out.println("keepChunk: ");
-		if (ChunkTypes == null)
+		if (chunkTypes == null)
 			return true;
 
-		for (int i = 0; i < ChunkTypes.length; i++)
+		for (int i = 0; i < chunkTypes.length; i++)
 		{
-			if (ChunkTypes[i] == ChunkType)
+			if (chunkTypes[i] == ChunkType)
 				return true;
 		}
 		return false;
 	}
 
-	private ArrayList readChunks(InputStream is, int ChunkTypes[],
-			boolean return_after_first) throws ImageReadException, IOException
+	private ArrayList readChunks(InputStream is, int chunkTypes[],
+			boolean returnAfterFirst) throws ImageReadException, IOException
 	{
 		ArrayList result = new ArrayList();
 
@@ -128,7 +129,7 @@
 				printCharQuad("ChunkType", chunkType);
 				debugNumber("Length", length, 4);
 			}
-			boolean keep = keepChunk(chunkType, ChunkTypes);
+			boolean keep = keepChunk(chunkType, chunkTypes);
 
 			byte bytes[] = null;
 			if (keep)
@@ -162,10 +163,12 @@
 					result.add(new PNGChunkIDAT(length, chunkType, CRC, bytes));
 				else if (chunkType == gAMA)
 					result.add(new PNGChunkgAMA(length, chunkType, CRC, bytes));
+				else if (chunkType == iTXt)
+					result.add(new PNGChunkiTXt(length, chunkType, CRC, bytes));
 				else
 					result.add(new PNGChunk(length, chunkType, CRC, bytes));
 
-				if (return_after_first)
+				if (returnAfterFirst)
 					return result;
 			}
 
@@ -186,8 +189,8 @@
 
 	}
 
-	private ArrayList readChunks(ByteSource byteSource, int ChunkTypes[],
-			boolean return_after_first) throws ImageReadException, IOException
+	private ArrayList readChunks(ByteSource byteSource, int chunkTypes[],
+			boolean returnAfterFirst) throws ImageReadException, IOException
 	{
 		InputStream is = null;
 
@@ -198,7 +201,7 @@
 			ArrayList chunks = null;
 
 			readSignature(is);
-			chunks = readChunks(is, ChunkTypes, return_after_first);
+			chunks = readChunks(is, chunkTypes, returnAfterFirst);
 			return chunks;
 		} finally
 		{
@@ -530,12 +533,12 @@
 			for (int i = 0; i < tEXts.size(); i++)
 			{
 				PNGChunktEXt pngChunktEXt = (PNGChunktEXt) tEXts.get(i);
-				Comments.add(pngChunktEXt.Keyword + ": " + pngChunktEXt.Text);
+				Comments.add(pngChunktEXt.keyword + ": " + pngChunktEXt.text);
 			}
 			for (int i = 0; i < zTXts.size(); i++)
 			{
 				PNGChunkzTXt pngChunkzTXt = (PNGChunkzTXt) zTXts.get(i);
-				Comments.add(pngChunkzTXt.Keyword + ": " + pngChunkzTXt.Text);
+				Comments.add(pngChunkzTXt.keyword + ": " + pngChunkzTXt.text);
 			}
 
 			int BitsPerPixel = pngChunkIHDR.bitDepth
@@ -845,7 +848,7 @@
 	{
 		new PngWriter(params).writeImage(src, os, params);
 	}
-	
+
 	/**
 	 * Extracts embedded XML metadata as XML string.
 	 * <p>
@@ -854,11 +857,31 @@
 	 *            File containing image data.
 	 * @param params
 	 *            Map of optional parameters, defined in SanselanConstants.
-	 * @return Xmp Xml as String, if present.  Otherwise, returns null..
+	 * @return Xmp Xml as String, if present. Otherwise, returns null..
 	 */
 	public String getXmpXml(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException {
-		// TODO: implement.
-		return null;
+			throws ImageReadException, IOException
+	{
+
+		List chunks = readChunks(byteSource, new int[] { iTXt, }, false);
+
+		if ((chunks == null) || (chunks.size() < 1))
+			return null;
+
+		List xmpChunks = new ArrayList();
+		for (int i = 0; i < chunks.size(); i++)
+		{
+			PNGChunkiTXt chunk = (PNGChunkiTXt) chunks.get(i);
+			if (!chunk.getKeyword().equals(XMP_KEYWORD))
+				continue;
+			xmpChunks.add(chunk);
+		}
+
+		if (xmpChunks.size() < 1)
+			return null;
+
+		PNGChunkiTXt chunk = (PNGChunkiTXt) xmpChunks.get(0);
+		return chunk.getText();
 	}
+
 }

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkiTXt.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkiTXt.java?rev=680169&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkiTXt.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkiTXt.java Sun Jul 27 12:42:40 2008
@@ -0,0 +1,122 @@
+/*
+ * 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.chunks;
+
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.common.ZLibInflater;
+import org.apache.sanselan.formats.png.PngConstants;
+
+public class PNGChunkiTXt extends PNGTextChunk
+{
+	public final String keyword, text;
+
+	/*
+	 * The language tag defined in [RFC-3066] indicates the human language used
+	 * by the translated keyword and the text. Unlike the keyword, the language
+	 * tag is case-insensitive. It is an ISO 646.IRV:1991 [ISO 646] string
+	 * consisting of hyphen-separated words of 1-8 alphanumeric characters each
+	 * (for example cn, en-uk, no-bok, x-klingon, x-KlInGoN). If the first word
+	 * is two or three letters long, it is an ISO language code [ISO-639]. If
+	 * the language tag is empty, the language is unspecified.
+	 */
+	public final String languageTag;
+
+	public final String translatedKeyword;
+
+	public PNGChunkiTXt(int length, int chunkType, int crc, byte bytes[])
+			throws ImageReadException, IOException
+	{
+		super(length, chunkType, crc, bytes);
+		{
+			int terminator = findNull(bytes);
+			if (terminator < 0)
+				throw new ImageReadException(
+						"PNG iTXt chunk keyword is not terminated.");
+
+			keyword = new String(bytes, 0, terminator, "ISO-8859-1");
+			int index = terminator + 1;
+
+			int compressionFlag = bytes[index++];
+			if (compressionFlag != 0 && compressionFlag != 1)
+				throw new ImageReadException(
+						"PNG iTXt chunk has invalid compression flag: "
+								+ compressionFlag);
+
+			boolean compressed = compressionFlag == 1;
+
+			int compressionMethod = bytes[index++];
+			if (compressed)
+				if (compressionMethod != PngConstants.COMPRESSION_DEFLATE_INFLATE)
+					throw new ImageReadException(
+							"PNG iTXt chunk has unexpected compression method: "
+									+ compressionMethod);
+				else if (compressionMethod != 0)
+					throw new ImageReadException(
+							"PNG iTXt chunk has unexpected compression method: "
+									+ compressionMethod);
+
+			terminator = findNull(bytes, index);
+			if (terminator < 0)
+				throw new ImageReadException(
+						"PNG iTXt chunk language tag is not terminated.");
+
+			languageTag = new String(bytes, index, terminator - index,
+					"ISO-8859-1");
+			index = terminator + 1;
+
+			terminator = findNull(bytes, index);
+			if (terminator < 0)
+				throw new ImageReadException(
+						"PNG iTXt chunk translated keyword is not terminated.");
+
+			translatedKeyword = new String(bytes, index, terminator - index,
+					"utf-8");
+			index = terminator + 1;
+
+			if (compressed)
+			{
+				int compressedTextLength = bytes.length - index;;
+				byte compressedText[] = new byte[compressedTextLength];
+				System.arraycopy(bytes, index, compressedText, 0,
+						compressedTextLength);
+
+				text = new String(new ZLibInflater()
+						.zlibInflate(compressedText), "utf-8");
+
+			} else
+				text = new String(bytes, index, bytes.length - index, "utf-8");
+		}
+	}
+
+	/**
+	 * @return Returns the keyword.
+	 */
+	public String getKeyword()
+	{
+		return keyword;
+	}
+
+	/**
+	 * @return Returns the text.
+	 */
+	public String getText()
+	{
+		return text;
+	}
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkiTXt.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunktEXt.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunktEXt.java?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunktEXt.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunktEXt.java Sun Jul 27 12:42:40 2008
@@ -22,40 +22,26 @@
 
 public class PNGChunktEXt extends PNGTextChunk
 {
-	//		public final int Length;
-	//		public final int ChunkType;
-	//		public final int CRC;
-	//		public final byte bytes[];
-	public final String Keyword, Text;
+	public final String keyword, text;
 
-	//		public final int CompressionMethod;
-
-	public PNGChunktEXt(int Length, int ChunkType, int CRC, byte bytes[])
+	public PNGChunktEXt(int length, int chunkType, int crc, byte bytes[])
 			throws ImageReadException, IOException
 	{
-		super(Length, ChunkType, CRC, bytes);
-
+		super(length, chunkType, crc, bytes);
 		{
-			//				debug_ByteArray("PNGChunktEXt", bytes);
-
 			int index = findNull(bytes);
 			if (index < 0)
-				throw new ImageReadException("PNGChunktEXt: No Profile Name");
-			byte name_bytes[] = new byte[index];
-			System.arraycopy(bytes, 0, name_bytes, 0, index);
-			Keyword = new String(name_bytes);
-
-			//				CompressionMethod = bytes[index + 1];
-
-			int TextLength = bytes.length - (index + 1);
-			byte Text_bytes[] = new byte[TextLength];
-			System.arraycopy(bytes, index + 1, Text_bytes, 0, TextLength);
-			Text = new String(Text_bytes);
+				throw new ImageReadException("PNG tEXt chunk keyword is not terminated.");
+
+			keyword = new String(bytes, 0, index, "ISO-8859-1");
+
+			int textLength = bytes.length - (index + 1);
+			text = new String(bytes, index + 1, textLength, "ISO-8859-1");
 
 			if (getDebug())
 			{
-				System.out.println("Keyword: " + Keyword);
-				System.out.println("Text: " + Text);
+				System.out.println("Keyword: " + keyword);
+				System.out.println("Text: " + text);
 			}
 
 		}
@@ -66,7 +52,7 @@
 	 */
 	public String getKeyword()
 	{
-		return Keyword;
+		return keyword;
 	}
 
 	/**
@@ -74,6 +60,6 @@
 	 */
 	public String getText()
 	{
-		return Text;
+		return text;
 	}
 }
\ No newline at end of file

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkzTXt.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkzTXt.java?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkzTXt.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/chunks/PNGChunkzTXt.java Sun Jul 27 12:42:40 2008
@@ -20,48 +20,39 @@
 
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.common.ZLibInflater;
+import org.apache.sanselan.formats.png.PngConstants;
 
 public class PNGChunkzTXt extends PNGTextChunk
 {
 
-	//	private final PngImageParser parser;
-	public final String Keyword, Text;
+	public final String keyword, text;
 
-	public PNGChunkzTXt(
-	//			PngImageParser parser, 
-			int Length, int ChunkType, int CRC, byte bytes[])
+	public PNGChunkzTXt(int length, int chunkType, int crc, byte bytes[])
 			throws ImageReadException, IOException
 	{
-		super(Length, ChunkType, CRC, bytes);
-		//		this.parser = parser;
+		super(length, chunkType, crc, bytes);
 
 		{
 			int index = findNull(bytes);
 			if (index < 0)
-				throw new ImageReadException("PNGChunkiCCP: No Profile Name");
-			byte Keyword_bytes[] = new byte[index];
-			System.arraycopy(bytes, 0, Keyword_bytes, 0, index);
-			Keyword = new String(Keyword_bytes);
-
-			//			int CompressionMethod = bytes[index + 1];
-
-			int CompressedTextLength = bytes.length - (index + 1 + 1);
-			byte CompressedText[] = new byte[CompressedTextLength];
-			System.arraycopy(bytes, index + 1 + 1, CompressedText, 0,
-					CompressedTextLength);
-
-			if (getDebug())
-			{
-				System.out.println("Keyword: " + Keyword);
-			}
-
-			Text = new String(new ZLibInflater().zlibInflate(CompressedText));
-
-			if (getDebug())
-			{
-				System.out.println("Text: " + Text);
-			}
+				throw new ImageReadException(
+						"PNG zTXt chunk keyword is unterminated.");
 
+			keyword = new String(bytes, 0, index, "ISO-8859-1");
+
+			int compressionMethod = bytes[index + 1];
+			if (compressionMethod != PngConstants.COMPRESSION_DEFLATE_INFLATE)
+				throw new ImageReadException(
+						"PNG zTXt chunk has unexpected compression method: "
+								+ compressionMethod);
+
+			int compressedTextLength = bytes.length - (index + 1 + 1);
+			byte compressedText[] = new byte[compressedTextLength];
+			System.arraycopy(bytes, index + 1 + 1, compressedText, 0,
+					compressedTextLength);
+
+			text = new String(new ZLibInflater().zlibInflate(compressedText),
+					"ISO-8859-1");
 		}
 	}
 
@@ -70,7 +61,7 @@
 	 */
 	public String getKeyword()
 	{
-		return Keyword;
+		return keyword;
 	}
 
 	/**
@@ -78,7 +69,7 @@
 	 */
 	public String getText()
 	{
-		return Text;
+		return text;
 	}
 
 }
\ No newline at end of file

Modified: 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=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java Sun Jul 27 12:42:40 2008
@@ -28,20 +28,14 @@
 
 public abstract class ByteSourceTest extends SanselanTest
 {
-	//	public ByteSourceTest(String name)
-	//	{
-	//		super(name);
-	//	}
+	// 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();
+		File file = createTempFile("raw_", ".bin");
 
 		// write test bytes to file.
 		OutputStream os = new FileOutputStream(file);
@@ -79,8 +73,6 @@
 		}
 		byte longArray[] = (baos.toByteArray());
 
-		return new byte[][]{
-				emptyArray, single, simple, zeroes, longArray,
-		};
+		return new byte[][] { emptyArray, single, simple, zeroes, longArray, };
 	}
 }

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java Sun Jul 27 12:42:40 2008
@@ -81,9 +81,8 @@
 				ByteArrayOutputStream baos = new ByteArrayOutputStream();
 				new ExifRewriter().removeExifMetadata(byteSource, baos);
 				byte bytes[] = baos.toByteArray();
-				File tempFile = File.createTempFile("test", ".jpg");
+				File tempFile = createTempFile("test", ".jpg");
 				Debug.debug("tempFile", tempFile);
-				tempFile.deleteOnExit();
 				IOUtils.writeToFile(bytes, tempFile);
 
 				Debug.debug("Output Segments:");
@@ -126,9 +125,8 @@
 				ByteArrayOutputStream baos = new ByteArrayOutputStream();
 				new ExifRewriter().removeExifMetadata(byteSource, baos);
 				byte bytes[] = baos.toByteArray();
-				File tempFile = File.createTempFile("removed", ".jpg");
+				File tempFile = createTempFile("removed", ".jpg");
 				Debug.debug("tempFile", tempFile);
-				tempFile.deleteOnExit();
 				IOUtils.writeToFile(bytes, tempFile);
 
 				Debug.debug("Output Segments:");
@@ -148,9 +146,8 @@
 						outputSet);
 
 				byte bytes[] = baos.toByteArray();
-				File tempFile = File.createTempFile("inserted" + "_", ".jpg");
+				File tempFile = createTempFile("inserted" + "_", ".jpg");
 				Debug.debug("tempFile", tempFile);
-				//			tempFile.deleteOnExit();
 				IOUtils.writeToFile(bytes, tempFile);
 
 				Debug.debug("Output Segments:");
@@ -223,9 +220,8 @@
 				ByteArrayOutputStream baos = new ByteArrayOutputStream();
 				rewriter.rewrite(byteSource, baos, outputSet);
 				byte bytes[] = baos.toByteArray();
-				File tempFile = File.createTempFile(name + "_", ".jpg");
+				File tempFile = createTempFile(name + "_", ".jpg");
 				Debug.debug("tempFile", tempFile);
-				//			tempFile.deleteOnExit();
 				IOUtils.writeToFile(bytes, tempFile);
 
 				Debug.debug("Output Segments:");

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java?rev=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java Sun Jul 27 12:42:40 2008
@@ -49,9 +49,8 @@
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile.getAbsoluteFile());
 
-			File tempFile = File.createTempFile("test", ".jpg");
+			File tempFile = createTempFile("test", ".jpg");
 			Debug.debug("tempFile", tempFile.getAbsoluteFile());
-			tempFile.deleteOnExit();
 
 			try
 			{
@@ -81,9 +80,8 @@
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile.getAbsoluteFile());
 
-			File tempFile = File.createTempFile("test", ".jpg");
+			File tempFile = createTempFile("test", ".jpg");
 			Debug.debug("tempFile", tempFile.getAbsoluteFile());
-			tempFile.deleteOnExit();
 
 			try
 			{

Modified: 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=680169&r1=680168&r2=680169&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java Sun Jul 27 12:42:40 2008
@@ -141,9 +141,7 @@
 
 		//		Debug.debug("bytes", bytes);
 
-		File tmpDirectory = new File("tmp");
-		File tempFile = File.createTempFile("temp", ".png", tmpDirectory);
-		tempFile.deleteOnExit();
+		File tempFile = createTempFile("temp", ".png");
 		IOUtils.writeToFile(bytes, tempFile);
 
 		BufferedImage dstImage = Sanselan.getBufferedImage(bytes);