[Schmitzm-commits] r1590 - branches/2.5/schmitzm-core/src/main/java/de/schmitzm/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat May 28 19:21:29 CEST 2011


Author: alfonx
Date: 2011-05-28 19:21:28 +0200 (Sat, 28 May 2011)
New Revision: 1590

Modified:
   branches/2.5/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
Log:
change windows \ to / when adding files zo zips

Modified: branches/2.5/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- branches/2.5/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2011-05-28 15:49:46 UTC (rev 1589)
+++ branches/2.5/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2011-05-28 17:21:28 UTC (rev 1590)
@@ -380,27 +380,27 @@
 		}
 	}
 
-    /**
-     * Versucht einen Eingabe-Stream zu schliessen.<br>
-     * Dabei werden bei Misserfolg keine Exceptions geworfen! SK: bei
-     * <code>null</code> wird true zurueckgegeben
-     * 
-     * @param in
-     *            zu schliessender Stream
-     * @return <code>false</code> falls das Schliessen nicht erfolgreich war
-     */
-    public static boolean closeReader(Reader in) {
-        if (in == null)
-            return true;
-        try {
-            in.close();
-        } catch (Exception err) {
-            return false;
-        }
-        return true;
-    }
+	/**
+	 * Versucht einen Eingabe-Stream zu schliessen.<br>
+	 * Dabei werden bei Misserfolg keine Exceptions geworfen! SK: bei
+	 * <code>null</code> wird true zurueckgegeben
+	 * 
+	 * @param in
+	 *            zu schliessender Stream
+	 * @return <code>false</code> falls das Schliessen nicht erfolgreich war
+	 */
+	public static boolean closeReader(Reader in) {
+		if (in == null)
+			return true;
+		try {
+			in.close();
+		} catch (Exception err) {
+			return false;
+		}
+		return true;
+	}
 
-    /**
+	/**
 	 * Versucht einen Eingabe-Stream zu schliessen.<br>
 	 * Dabei werden bei Misserfolg keine Exceptions geworfen! SK: bei
 	 * <code>null</code> wird true zurueckgegeben
@@ -612,31 +612,36 @@
 		return new File(path3);
 	}
 
-	  /**
-	   * Searches for files in a directory (and its sub folders).
-	   * @param dir directory to search in
-	   * @param fileFilter filter for the files to search for
-	   * @param recursive indicates whether sub directories are
-	   *                  scanned
-	   * @param foundFiles list to store the found files in (if {@code null}
-	   *                   a new list is created and returned)
-	   */
-	  public static Vector<File> findFiles(File dir, FileFilter fileFilter, boolean recursive, Vector<File> foundFiles) {
-	    if ( foundFiles == null )
-	      foundFiles = new Vector<File>();
-	    if ( dir == null || !dir.isDirectory() )
-	      return foundFiles;
-	    
-	    File[] files = dir.listFiles(fileFilter);
-	    LangUtil.addObjectsToVector(files, foundFiles);
-	    if ( recursive ) {
-	      File[] subDirs = dir.listFiles(FilterUtil.ALL_DIRS_FILTER);
-	      for ( File subDir : subDirs )
-	        findFiles(subDir,fileFilter,recursive,foundFiles);
-	    }
-	    return foundFiles;
-	  }
+	/**
+	 * Searches for files in a directory (and its sub folders).
+	 * 
+	 * @param dir
+	 *            directory to search in
+	 * @param fileFilter
+	 *            filter for the files to search for
+	 * @param recursive
+	 *            indicates whether sub directories are scanned
+	 * @param foundFiles
+	 *            list to store the found files in (if {@code null} a new list
+	 *            is created and returned)
+	 */
+	public static Vector<File> findFiles(File dir, FileFilter fileFilter,
+			boolean recursive, Vector<File> foundFiles) {
+		if (foundFiles == null)
+			foundFiles = new Vector<File>();
+		if (dir == null || !dir.isDirectory())
+			return foundFiles;
 
+		File[] files = dir.listFiles(fileFilter);
+		LangUtil.addObjectsToVector(files, foundFiles);
+		if (recursive) {
+			File[] subDirs = dir.listFiles(FilterUtil.ALL_DIRS_FILTER);
+			for (File subDir : subDirs)
+				findFiles(subDir, fileFilter, recursive, foundFiles);
+		}
+		return foundFiles;
+	}
+
 	/**
 	 * Loescht Dateien oder Verzeichnisse in einem Verzeichnis. Das Verzeichnis
 	 * selbst wird dabei NICHT geloescht, auch wenn es am Ende leer ist!
@@ -972,32 +977,33 @@
 			return false;
 		}
 	}
-	
+
 	/**
-	 * Decodes an encoded string several times, so that the string
-	 * is also decoded, if the source string was encoded multiple
-	 * times. The decoding procedure is looped until the there
-	 * are no changes.
-	 * @param encodedStr encoded string
+	 * Decodes an encoded string several times, so that the string is also
+	 * decoded, if the source string was encoded multiple times. The decoding
+	 * procedure is looped until the there are no changes.
+	 * 
+	 * @param encodedStr
+	 *            encoded string
 	 * @return empty string if source is {@code null}
 	 * @see URLDecoder#decode(String, String)
 	 */
 	public static String decodeURL(String encodedStr) {
-	  if ( encodedStr == null )
-	    return "";
-	  String decodedStr = null;
-	  try {
-	    do {
-	      // except the first loop use the decoded string
-	      // of the last loop as source
-	      if ( decodedStr != null )
-	        encodedStr = decodedStr; 
-	      decodedStr = URLDecoder.decode(encodedStr, "UTF-8");
-	    } while( !decodedStr.equals( encodedStr ) );
-	  } catch (UnsupportedEncodingException err) {
-	    // ignore
-	  }
-	  return decodedStr;
+		if (encodedStr == null)
+			return "";
+		String decodedStr = null;
+		try {
+			do {
+				// except the first loop use the decoded string
+				// of the last loop as source
+				if (decodedStr != null)
+					encodedStr = decodedStr;
+				decodedStr = URLDecoder.decode(encodedStr, "UTF-8");
+			} while (!decodedStr.equals(encodedStr));
+		} catch (UnsupportedEncodingException err) {
+			// ignore
+		}
+		return decodedStr;
 	}
 
 	/**
@@ -1328,6 +1334,8 @@
 	 * @param zos
 	 * @param cutOff
 	 *            use 0 for absolute paths.
+	 * @param linuxsep
+	 *            Use Linux instead of Windows separators in zipFile
 	 * @throws IOException
 	 */
 	public static void zipDir(String zipMePath, ZipOutputStream zos, int cutOff)
@@ -1374,6 +1382,9 @@
 		if (pathInZip.equals("")) {
 			System.out.println("new entry=" + pathInZip);
 		}
+
+		pathInZip = pathInZip.replace('\\', '/'); // Windows for Linux
+													// separators
 		ZipEntry anEntry = new ZipEntry(pathInZip);
 		// place the zip entry in the ZipOutputStream object
 		zos.putNextEntry(anEntry);
@@ -1526,9 +1537,9 @@
 		}
 	}
 
-	public static void zipFile(File delFile, ZipOutputStream zos, File cutOff)
+	public static void zipFile(File inputFile, ZipOutputStream zos, File cutOff)
 			throws IOException {
-		zipFile(delFile, zos, cutOff.getAbsolutePath().length());
+		zipFile(inputFile, zos, cutOff.getAbsolutePath().length());
 	}
 
 	/**



More information about the Schmitzm-commits mailing list