[Schmitzm-commits] r1184 - in trunk: src/schmitzm/io src/schmitzm/swing src_junit/schmitzm/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 27 10:14:38 CEST 2010


Author: alfonx
Date: 2010-10-27 10:14:37 +0200 (Wed, 27 Oct 2010)
New Revision: 1184

Modified:
   trunk/src/schmitzm/io/IOUtil.java
   trunk/src/schmitzm/swing/SwingUtil.java
   trunk/src_junit/schmitzm/io/IOUtilTest.java
Log:


Modified: trunk/src/schmitzm/io/IOUtil.java
===================================================================
--- trunk/src/schmitzm/io/IOUtil.java	2010-10-27 07:31:47 UTC (rev 1183)
+++ trunk/src/schmitzm/io/IOUtil.java	2010-10-27 08:14:37 UTC (rev 1184)
@@ -598,19 +598,21 @@
 	 * @param url
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
+	 * 
+	 * @deprecated Use DataUtilties.url2file
 	 */
 	public static File urlToFile(URL url) {
-//		// LOGGER.debug("\nconverting " + url.toString() + " to ");
-//		File f;
-//		try {
-//			f = new File(url.toURI());
-//		} catch (Exception e) {
-//			// TODO Here we probably need more cases...
-//			f = new File(url.getPath().replace("%20", " "));
-//		}
-//		// LOGGER.debug("        to " + f.toString());
-//		return f;
-		
+		// // LOGGER.debug("\nconverting " + url.toString() + " to ");
+		// File f;
+		// try {
+		// f = new File(url.toURI());
+		// } catch (Exception e) {
+		// // TODO Here we probably need more cases...
+		// f = new File(url.getPath().replace("%20", " "));
+		// }
+		// // LOGGER.debug("        to " + f.toString());
+		// return f;
+
 		return DataUtilities.urlToFile(url);
 	}
 
@@ -955,27 +957,29 @@
 
 	/**
 	 * Copy file or folder recursively to file or folder. All filenames are
-	 * turned to lower case!
+	 * turned to lower case!<br/>
+	 * <br/>
+	 * Attention: This method has the function to clean filenames. Using it to
+	 * copy <code>/a/a.txt</code> to <code>/b/b.txt</code> does not work, even
+	 * when param cleanfile is false! It will copy a.txt to
+	 * <code>/b/a.txt</copy>. Use Fileutil.copyURLToFile directly if you rneed the mentioned routine.
 	 * 
 	 * @param source
 	 *            File or directory or wildcard to copy
 	 * @param destination
 	 *            Directory or filename...
 	 * @param cleanFilenames
-	 *            Convert target filenames to clean, lowercase filenames
+	 *            Convert target filenames to clean, lowercase filenames. Even
+	 *            if <code>false</code>, the old filnem will be used when
+	 *            copying a file to file.
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
-	 * 
-	 * @throws URISyntaxException
-	 * @throws IOException
-	 * 
-	 * @throws IOException
 	 */
 	public final static void copyUrl(final URL source, File destination,
 			final Boolean cleanFilenames) throws IOException,
 			URISyntaxException {
 
-		final String sourceName = IOUtil.urlToFile(source).getName();
+		final String sourceName = new File(source.getPath()).getName();
 		final String cleanName = cleanFilenames ? IOUtil
 				.cleanFilename(sourceName) : sourceName;
 

Modified: trunk/src/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/src/schmitzm/swing/SwingUtil.java	2010-10-27 07:31:47 UTC (rev 1183)
+++ trunk/src/schmitzm/swing/SwingUtil.java	2010-10-27 08:14:37 UTC (rev 1184)
@@ -50,11 +50,9 @@
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
-import java.net.URISyntaxException;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Random;

Modified: trunk/src_junit/schmitzm/io/IOUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/io/IOUtilTest.java	2010-10-27 07:31:47 UTC (rev 1183)
+++ trunk/src_junit/schmitzm/io/IOUtilTest.java	2010-10-27 08:14:37 UTC (rev 1184)
@@ -1,11 +1,15 @@
 package schmitzm.io;
 
+import static org.junit.Assert.*;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.net.URL;
 
+import org.geotools.data.DataUtilities;
 import org.junit.Test;
 
 public class IOUtilTest {
@@ -16,7 +20,7 @@
 				+ System.currentTimeMillis());
 		File d1 = new File(d0, "d1");
 		d1.mkdirs();
-		
+
 		File f1 = new File(d1, "f1");
 		f1.createNewFile();
 		PrintWriter printWriter = new PrintWriter(f1);
@@ -30,9 +34,26 @@
 		System.out.println(d0);
 		System.out.println(f1);
 		System.out.println(zipFile);
-		
+
 		assertTrue(zipFile.length() > 0l);
 
 	}
 
+	@Test
+	public void testCopyUrl() throws IOException, URISyntaxException {
+
+		File srcFile = File.createTempFile("junit", "");
+		URL source = DataUtilities.fileToURL(srcFile);
+		assertNotNull(source);
+		File dest = File.createTempFile("junit", "");
+
+		dest.delete();
+		assertFalse("File must not exists before", dest.exists());
+
+		IOUtil.copyUrl(source, dest, false);
+
+		assertFalse(
+				"The destination file must not exist, because the original name was applied during copying",
+				dest.exists());
+	}
 }



More information about the Schmitzm-commits mailing list