You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2011/03/26 15:57:01 UTC

svn commit: r1085730 - in /servicemix/utils/trunk/src: main/java/org/apache/servicemix/components/util/ main/java/org/apache/servicemix/executors/impl/ main/java/org/apache/servicemix/jbi/transformer/ main/java/org/apache/servicemix/jdbc/ main/java/org...

Author: gertv
Date: Sat Mar 26 14:57:00 2011
New Revision: 1085730

URL: http://svn.apache.org/viewvc?rev=1085730&view=rev
Log:
Removing some TABs from the servicemix-utils codebase

Modified:
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/FactoryFinder.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/Statements.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/jaf/ByteArrayDataSource.java
    servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/DefaultFileMarshalerTest.java
    servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java
    servicemix/utils/trunk/src/test/java/org/apache/servicemix/tck/mock/MockExchangeFactoryTest.java
    servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/encoding.xml
    servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/expression-editor.xml

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java Sat Mar 26 14:57:00 2011
@@ -75,11 +75,11 @@ public class DefaultFileMarshaler extend
         return asString(fileName.evaluate(exchange, message));
     }
 
-	public String getTempOutputName(MessageExchange exchange,
-			NormalizedMessage message) throws MessagingException {
-		Object retVal = tempFileName.evaluate(exchange, message);
-		return retVal == null ? null : asString(retVal);
-	}
+    public String getTempOutputName(MessageExchange exchange,
+            NormalizedMessage message) throws MessagingException {
+        Object retVal = tempFileName.evaluate(exchange, message);
+        return retVal == null ? null : asString(retVal);
+    }
     
     public void writeMessage(MessageExchange exchange, NormalizedMessage message, 
                              OutputStream out, String path) throws IOException, JBIException {

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java Sat Mar 26 14:57:00 2011
@@ -27,7 +27,7 @@ import java.io.InputStream;
  */
 public class StreamDataSource extends org.apache.servicemix.util.jaf.StreamDataSource {
 
-	public StreamDataSource(InputStream in) {
+    public StreamDataSource(InputStream in) {
         super(in);
     }
 

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/FactoryFinder.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/FactoryFinder.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/FactoryFinder.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/FactoryFinder.java Sat Mar 26 14:57:00 2011
@@ -165,14 +165,14 @@ class FactoryFinder {
 
                     ClassLoader classLoader = findClassLoader();
 
-			        try {
-			            // If we are deployed into an OSGi environment, leverage it
-			            Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(iFactoryId);
-			            if (spiClass != null) {
-			                return spiClass.newInstance();
-			            }
-			        } catch (Throwable e) {
-			        }
+                    try {
+                        // If we are deployed into an OSGi environment, leverage it
+                        Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(iFactoryId);
+                        if (spiClass != null) {
+                            return spiClass.newInstance();
+                        }
+                    } catch (Throwable e) {
+                    }
 
                     // Use the system property first
                     try {

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java Sat Mar 26 14:57:00 2011
@@ -46,4 +46,4 @@ public class PropertyAddTransformer exte
     public void setValue(String value) {
         this.value = value;
     }
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/Statements.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/Statements.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/Statements.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/Statements.java Sat Mar 26 14:57:00 2011
@@ -210,4 +210,4 @@ public class Statements {
         this.countStatement = getCountStatement;
     }
 
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java Sat Mar 26 14:57:00 2011
@@ -38,4 +38,4 @@ package org.apache.servicemix.jdbc.adapt
  */
 public class BlobJDBCAdapter extends DefaultJDBCAdapter {
     
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java Sat Mar 26 14:57:00 2011
@@ -46,4 +46,4 @@ public class BytesJDBCAdapter extends De
         s.setBytes(index, data);
     }
 
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java Sat Mar 26 14:57:00 2011
@@ -29,4 +29,4 @@ public class HsqldbJDBCAdapter extends B
         super.setStatements(statements);
     }
 
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java Sat Mar 26 14:57:00 2011
@@ -37,4 +37,4 @@ public class ImageBasedJDBCAdaptor exten
         super.setStatements(statements);
     }
     
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java Sat Mar 26 14:57:00 2011
@@ -67,4 +67,4 @@ public class StreamJDBCAdapter extends D
         s.setBinaryStream(index, new ByteArrayInputStream(data), data.length);
     }
 
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java Sat Mar 26 14:57:00 2011
@@ -167,4 +167,4 @@ public class HazelcastStore implements S
             }
         }
     }
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java Sat Mar 26 14:57:00 2011
@@ -41,59 +41,59 @@ import java.util.zip.ZipOutputStream;
  */
 public final class FileUtil {
 
-	private FileUtil() {
-	}
+    private FileUtil() {
+    }
+
+    /**
+     * Move a File
+     * 
+     * @param src
+     * @param targetDirectory
+     * @throws IOException
+     */
+    public static void moveFile(File src, File targetDirectory)
+            throws IOException {
+        if (src == null || !src.exists() || !src.isFile() ||
+            targetDirectory == null || !targetDirectory.exists() || !targetDirectory.isDirectory() ||
+            !src.renameTo(new File(targetDirectory, src.getName()))) {
+            // unable to move the file
+            throw new IOException("Failed to move " + src + " to " + targetDirectory);
+        }
+    }
+
+    /**
+     * Build a path- but do not create it
+     * 
+     * @param parent
+     * @param subDirectory
+     * @return a File representing the path
+     */
+    public static File getDirectoryPath(File parent, String subDirectory) {
+        File result = null;
+        if (parent != null) {
+            result = new File(parent, subDirectory);
+        }
+        return result;
+    }
 
-	/**
-	 * Move a File
-	 * 
-	 * @param src
-	 * @param targetDirectory
-	 * @throws IOException
-	 */
-	public static void moveFile(File src, File targetDirectory)
-			throws IOException {
-		if (src == null || !src.exists() || !src.isFile() ||
-		    targetDirectory == null || !targetDirectory.exists() || !targetDirectory.isDirectory() ||
-		    !src.renameTo(new File(targetDirectory, src.getName()))) {
-			// unable to move the file
-			throw new IOException("Failed to move " + src + " to " + targetDirectory);
-		}
-	}
-
-	/**
-	 * Build a path- but do not create it
-	 * 
-	 * @param parent
-	 * @param subDirectory
-	 * @return a File representing the path
-	 */
-	public static File getDirectoryPath(File parent, String subDirectory) {
-		File result = null;
-		if (parent != null) {
-			result = new File(parent, subDirectory);
-		}
-		return result;
-	}
-
-	/**
-	 * Build a directory path - creating directories if neccesary
-	 * 
-	 * @param file
-	 * @return true if the directory exists, or making it was successful
-	 */
-	public static boolean buildDirectory(File file) {
-		return file.exists() || file.mkdirs();
-	}
-
-	/**
-	 * Count files in a directory (including files in all subdirectories)
-	 * 
-	 * @param directory
-	 *            the directory to start in
-	 * @return the total number of files
-	 */
-	public static int countFilesInDirectory(File directory) {
+    /**
+     * Build a directory path - creating directories if neccesary
+     * 
+     * @param file
+     * @return true if the directory exists, or making it was successful
+     */
+    public static boolean buildDirectory(File file) {
+        return file.exists() || file.mkdirs();
+    }
+
+    /**
+     * Count files in a directory (including files in all subdirectories)
+     * 
+     * @param directory
+     *            the directory to start in
+     * @return the total number of files
+     */
+    public static int countFilesInDirectory(File directory) {
         int count = 0;
         for (File file : directory.listFiles()) {
             if (file.isFile()) {
@@ -106,280 +106,280 @@ public final class FileUtil {
         return count;
     }
 
-	/**
-	 * Copy in stream to an out stream
-	 * 
-	 * @param in
-	 * @param out
-	 * @throws IOException
-	 */
-	public static void copyInputStream(InputStream in, OutputStream out)
-			throws IOException {
-		// simply use the fastCopy method
-		fastCopy(in, out);
-	}
-
-	/**
-	 * Unpack a zip file
-	 * 
-	 * @param theFile
-	 * @param targetDir
-	 * @return the file
-	 * @throws IOException
-	 */
-	public static File unpackArchive(File theFile, File targetDir)
-			throws IOException {
-		if (!theFile.exists()) {
-			throw new IOException(theFile.getAbsolutePath() + " does not exist");
-		}
-		if (!buildDirectory(targetDir)) {
-			throw new IOException("Could not create directory: " + targetDir);
-		}
-		ZipFile zipFile;
-		zipFile = new ZipFile(theFile);
-		for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
-			ZipEntry entry = (ZipEntry) entries.nextElement();
-			File file = new File(targetDir, File.separator + entry.getName());
-			// Take the sledgehammer approach to creating directories
-			// to work around ZIP's that incorrectly miss directories
-			if (!buildDirectory(file.getParentFile())) {
-				throw new IOException("Could not create directory: "
-						+ file.getParentFile());
-			}
-			if (!entry.isDirectory()) {
-				copyInputStream(zipFile.getInputStream(entry),
-						new BufferedOutputStream(new FileOutputStream(file)));
-			} else {
-				if (!buildDirectory(file)) {
-					throw new IOException("Could not create directory: " + file);
-				}
-			}
-		}
-		zipFile.close();
-		return theFile;
-	}
-
-	/**
-	 * Unpack an archive from a URL
-	 * 
-	 * @param url
-	 * @param targetDir
-	 * @return the file to the url
-	 * @throws IOException
-	 */
-	public static File unpackArchive(URL url, File targetDir)
-			throws IOException {
-		if (!targetDir.exists()) {
-			targetDir.mkdirs();
-		}
-		InputStream in = new BufferedInputStream(url.openStream());
-		// make sure we get the actual file
-		File zip = File.createTempFile("arc", ".zip", targetDir);
-		OutputStream out = new BufferedOutputStream(new FileOutputStream(zip));
-		copyInputStream(in, out);
-		out.close();
-		return unpackArchive(zip, targetDir);
-	}
-
-	/**
-	 * Validate that an archive contains a named entry
-	 * 
-	 * @param theFile
-	 * @param name
-	 * @return true if the entry exists
-	 * @throws IOException
-	 */
-	public static boolean archiveContainsEntry(File theFile, String name)
-			throws IOException {
-		boolean result = false;
-		ZipFile zipFile;
-		zipFile = new ZipFile(theFile);
-		for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
-			ZipEntry entry = (ZipEntry) entries.nextElement();
-			if (entry.getName().equals(name)) {
-				result = true;
-				break;
-			}
-		}
-		zipFile.close();
-		return result;
-	}
-
-	/**
-	 * Create a unique directory within a directory 'root'
-	 * 
-	 * @param rootDir
-	 * @param seed
-	 * @return unique directory
-	 * @throws IOException
-	 */
-	public static synchronized File createUniqueDirectory(File rootDir,
-			String seed) throws IOException {
-		int index = seed.lastIndexOf('.');
-		if (index > 0) {
-			seed = seed.substring(0, index);
-		}
-		File result = null;
-		int count = 0;
-		while (result == null) {
-			String name = seed + "." + count + ".tmp";
-			File file = new File(rootDir, name);
-			if (!file.exists()) {
-				file.mkdirs();
-				result = file;
-			}
-			count++;
-		}
-		return result;
-	}
-
-	/**
-	 * Delete a file
-	 * 
-	 * @param fileToDelete
-	 * @return true if the File is deleted
-	 */
-	public static boolean deleteFile(File fileToDelete) {
-		if (fileToDelete == null || !fileToDelete.exists()) {
-			return true;
-		}
-		boolean result = true;
-		if (fileToDelete.isDirectory()) {
-			File[] files = fileToDelete.listFiles();
-			if (files == null) {
-				result = false;
-			} else {
-				for (int i = 0; i < files.length; i++) {
-					File file = files[i];
-					if (file.getName().equals(".")
-							|| file.getName().equals("..")) {
-						continue;
-					}
-					if (file.isDirectory()) {
-						result &= deleteFile(file);
-					} else {
-						result &= file.delete();
-					}
-				}
-			}
-		}
-		result &= fileToDelete.delete();
-		return result;
-	}
-
-	/**
-	 * Zip up a directory
-	 * 
-	 * @param directory
-	 * @param zipName
-	 * @throws IOException
-	 */
-	public static void zipDir(String directory, String zipName)
-			throws IOException {
-		// create a ZipOutputStream to zip the data to
-		ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipName));
-		String path = "";
-		zipDir(directory, zos, path);
-		// close the stream
-		zos.close();
-	}
-
-	/**
-	 * Zip up a directory path
-	 * 
-	 * @param directory
-	 * @param zos
-	 * @param path
-	 * @throws IOException
-	 */
-	public static void zipDir(String directory, ZipOutputStream zos, String path)
-			throws IOException {
-		File zipDir = new File(directory);
-		// get a listing of the directory content
-		String[] dirList = zipDir.list();
-		byte[] readBuffer = new byte[2156];
-		int bytesIn = 0;
-		// loop through dirList, and zip the files
-		for (int i = 0; i < dirList.length; i++) {
-			File f = new File(zipDir, dirList[i]);
-			if (f.isDirectory()) {
-				String filePath = f.getPath();
-				zipDir(filePath, zos, path + f.getName() + "/");
-				continue;
-			}
-			FileInputStream fis = new FileInputStream(f);
-			try {
-				ZipEntry anEntry = new ZipEntry(path + f.getName());
-				zos.putNextEntry(anEntry);
-				bytesIn = fis.read(readBuffer);
-				while (bytesIn != -1) {
-					zos.write(readBuffer, 0, bytesIn);
-					bytesIn = fis.read(readBuffer);
-				}
-			} finally {
-				fis.close();
-			}
-		}
-	}
-
-	/**
-	 * checks whether a file is fully transmitted or still being copied
-	 * 
-	 * @param path
-	 *            the full file path
-	 * @returns true if the file size didn't change for 100 millis
-	 */
-	public static boolean isFileFullyAvailable(String path) {
-		return isFileFullyAvailable(new File(path));
-	}
-
-	/**
-	 * checks whether a file is fully transmitted or still being copied
-	 * 
-	 * @param file
-	 *            the file to check
-	 * @returns true if the file size didn't change for 100 millis
-	 */
-	public static boolean isFileFullyAvailable(File file) {
-		// First check to see if the file is still growing
-		long targetLength = file.length();
-		try {
-			Thread.sleep(100);
-		} catch (InterruptedException e) {
-			// Do nothing
-		}
-		long target2Length = file.length();
-
-		if (targetLength != target2Length) {
-			return false;
-		}
-
-		return true;
-	}
-
-	/**
-	 * Copies the whole content from the input stream to the output stream using
-	 * nio channels to speed it up.
-	 * 
-	 * @param input  the input stream
-	 * @param output the output stream
-	 * @throws IOException if any IO error occurs during read/write
-	 */
-	public static void fastCopy(final InputStream input, final OutputStream output) throws IOException {
-		final ReadableByteChannel src = Channels.newChannel(input);
-		final WritableByteChannel dest = Channels.newChannel(output);
-		final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
-
-		while (src.read(buffer) != -1) {
-			buffer.flip();
-			dest.write(buffer);
-			buffer.compact();
-		}
-		buffer.flip();
-		while (buffer.hasRemaining()) {
-			dest.write(buffer);
-		}
-		src.close();
-		dest.close();
-	}
-}
\ No newline at end of file
+    /**
+     * Copy in stream to an out stream
+     * 
+     * @param in
+     * @param out
+     * @throws IOException
+     */
+    public static void copyInputStream(InputStream in, OutputStream out)
+            throws IOException {
+        // simply use the fastCopy method
+        fastCopy(in, out);
+    }
+
+    /**
+     * Unpack a zip file
+     * 
+     * @param theFile
+     * @param targetDir
+     * @return the file
+     * @throws IOException
+     */
+    public static File unpackArchive(File theFile, File targetDir)
+            throws IOException {
+        if (!theFile.exists()) {
+            throw new IOException(theFile.getAbsolutePath() + " does not exist");
+        }
+        if (!buildDirectory(targetDir)) {
+            throw new IOException("Could not create directory: " + targetDir);
+        }
+        ZipFile zipFile;
+        zipFile = new ZipFile(theFile);
+        for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
+            ZipEntry entry = (ZipEntry) entries.nextElement();
+            File file = new File(targetDir, File.separator + entry.getName());
+            // Take the sledgehammer approach to creating directories
+            // to work around ZIP's that incorrectly miss directories
+            if (!buildDirectory(file.getParentFile())) {
+                throw new IOException("Could not create directory: "
+                        + file.getParentFile());
+            }
+            if (!entry.isDirectory()) {
+                copyInputStream(zipFile.getInputStream(entry),
+                        new BufferedOutputStream(new FileOutputStream(file)));
+            } else {
+                if (!buildDirectory(file)) {
+                    throw new IOException("Could not create directory: " + file);
+                }
+            }
+        }
+        zipFile.close();
+        return theFile;
+    }
+
+    /**
+     * Unpack an archive from a URL
+     * 
+     * @param url
+     * @param targetDir
+     * @return the file to the url
+     * @throws IOException
+     */
+    public static File unpackArchive(URL url, File targetDir)
+            throws IOException {
+        if (!targetDir.exists()) {
+            targetDir.mkdirs();
+        }
+        InputStream in = new BufferedInputStream(url.openStream());
+        // make sure we get the actual file
+        File zip = File.createTempFile("arc", ".zip", targetDir);
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(zip));
+        copyInputStream(in, out);
+        out.close();
+        return unpackArchive(zip, targetDir);
+    }
+
+    /**
+     * Validate that an archive contains a named entry
+     * 
+     * @param theFile
+     * @param name
+     * @return true if the entry exists
+     * @throws IOException
+     */
+    public static boolean archiveContainsEntry(File theFile, String name)
+            throws IOException {
+        boolean result = false;
+        ZipFile zipFile;
+        zipFile = new ZipFile(theFile);
+        for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
+            ZipEntry entry = (ZipEntry) entries.nextElement();
+            if (entry.getName().equals(name)) {
+                result = true;
+                break;
+            }
+        }
+        zipFile.close();
+        return result;
+    }
+
+    /**
+     * Create a unique directory within a directory 'root'
+     * 
+     * @param rootDir
+     * @param seed
+     * @return unique directory
+     * @throws IOException
+     */
+    public static synchronized File createUniqueDirectory(File rootDir,
+            String seed) throws IOException {
+        int index = seed.lastIndexOf('.');
+        if (index > 0) {
+            seed = seed.substring(0, index);
+        }
+        File result = null;
+        int count = 0;
+        while (result == null) {
+            String name = seed + "." + count + ".tmp";
+            File file = new File(rootDir, name);
+            if (!file.exists()) {
+                file.mkdirs();
+                result = file;
+            }
+            count++;
+        }
+        return result;
+    }
+
+    /**
+     * Delete a file
+     * 
+     * @param fileToDelete
+     * @return true if the File is deleted
+     */
+    public static boolean deleteFile(File fileToDelete) {
+        if (fileToDelete == null || !fileToDelete.exists()) {
+            return true;
+        }
+        boolean result = true;
+        if (fileToDelete.isDirectory()) {
+            File[] files = fileToDelete.listFiles();
+            if (files == null) {
+                result = false;
+            } else {
+                for (int i = 0; i < files.length; i++) {
+                    File file = files[i];
+                    if (file.getName().equals(".")
+                            || file.getName().equals("..")) {
+                        continue;
+                    }
+                    if (file.isDirectory()) {
+                        result &= deleteFile(file);
+                    } else {
+                        result &= file.delete();
+                    }
+                }
+            }
+        }
+        result &= fileToDelete.delete();
+        return result;
+    }
+
+    /**
+     * Zip up a directory
+     * 
+     * @param directory
+     * @param zipName
+     * @throws IOException
+     */
+    public static void zipDir(String directory, String zipName)
+            throws IOException {
+        // create a ZipOutputStream to zip the data to
+        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipName));
+        String path = "";
+        zipDir(directory, zos, path);
+        // close the stream
+        zos.close();
+    }
+
+    /**
+     * Zip up a directory path
+     * 
+     * @param directory
+     * @param zos
+     * @param path
+     * @throws IOException
+     */
+    public static void zipDir(String directory, ZipOutputStream zos, String path)
+            throws IOException {
+        File zipDir = new File(directory);
+        // get a listing of the directory content
+        String[] dirList = zipDir.list();
+        byte[] readBuffer = new byte[2156];
+        int bytesIn = 0;
+        // loop through dirList, and zip the files
+        for (int i = 0; i < dirList.length; i++) {
+            File f = new File(zipDir, dirList[i]);
+            if (f.isDirectory()) {
+                String filePath = f.getPath();
+                zipDir(filePath, zos, path + f.getName() + "/");
+                continue;
+            }
+            FileInputStream fis = new FileInputStream(f);
+            try {
+                ZipEntry anEntry = new ZipEntry(path + f.getName());
+                zos.putNextEntry(anEntry);
+                bytesIn = fis.read(readBuffer);
+                while (bytesIn != -1) {
+                    zos.write(readBuffer, 0, bytesIn);
+                    bytesIn = fis.read(readBuffer);
+                }
+            } finally {
+                fis.close();
+            }
+        }
+    }
+
+    /**
+     * checks whether a file is fully transmitted or still being copied
+     * 
+     * @param path
+     *            the full file path
+     * @returns true if the file size didn't change for 100 millis
+     */
+    public static boolean isFileFullyAvailable(String path) {
+        return isFileFullyAvailable(new File(path));
+    }
+
+    /**
+     * checks whether a file is fully transmitted or still being copied
+     * 
+     * @param file
+     *            the file to check
+     * @returns true if the file size didn't change for 100 millis
+     */
+    public static boolean isFileFullyAvailable(File file) {
+        // First check to see if the file is still growing
+        long targetLength = file.length();
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            // Do nothing
+        }
+        long target2Length = file.length();
+
+        if (targetLength != target2Length) {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * Copies the whole content from the input stream to the output stream using
+     * nio channels to speed it up.
+     * 
+     * @param input  the input stream
+     * @param output the output stream
+     * @throws IOException if any IO error occurs during read/write
+     */
+    public static void fastCopy(final InputStream input, final OutputStream output) throws IOException {
+        final ReadableByteChannel src = Channels.newChannel(input);
+        final WritableByteChannel dest = Channels.newChannel(output);
+        final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
+
+        while (src.read(buffer) != -1) {
+            buffer.flip();
+            dest.write(buffer);
+            buffer.compact();
+        }
+        buffer.flip();
+        while (buffer.hasRemaining()) {
+            dest.write(buffer);
+        }
+        src.close();
+        dest.close();
+    }
+}

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/jaf/ByteArrayDataSource.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/jaf/ByteArrayDataSource.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/jaf/ByteArrayDataSource.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/jaf/ByteArrayDataSource.java Sat Mar 26 14:57:00 2011
@@ -65,4 +65,4 @@ public class ByteArrayDataSource impleme
     public void setName(String name) {
         this.name = name;
     }
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/DefaultFileMarshalerTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/DefaultFileMarshalerTest.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/DefaultFileMarshalerTest.java (original)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/DefaultFileMarshalerTest.java Sat Mar 26 14:57:00 2011
@@ -89,27 +89,27 @@ public class DefaultFileMarshalerTest ex
     }
 
     public void testTempFileNameFromNmsg() throws Exception {
-    	String tmp = "tmp_filename.ext_123";
-    	MessageExchange exchange = createMockExchange();
-    	exchange.getMessage("in").setContent(new StringSource(MESSAGE));
-    	exchange.getMessage("in").setProperty(DefaultFileMarshaler.TEMP_FILE_NAME_PROPERTY, tmp);
-    	String tempName = marshaler.getTempOutputName(exchange, exchange.getMessage("in"));
-    	assertEquals("The temp file name was not extracted correctly", tmp, tempName);
+        String tmp = "tmp_filename.ext_123";
+        MessageExchange exchange = createMockExchange();
+        exchange.getMessage("in").setContent(new StringSource(MESSAGE));
+        exchange.getMessage("in").setProperty(DefaultFileMarshaler.TEMP_FILE_NAME_PROPERTY, tmp);
+        String tempName = marshaler.getTempOutputName(exchange, exchange.getMessage("in"));
+        assertEquals("The temp file name was not extracted correctly", tmp, tempName);
     }
     
     public void testTempFileNameFromExchange() throws Exception {
-    	String tmp = "tmp_filename.ext_123";
-    	MessageExchange exchange = createMockExchange();
-    	exchange.getMessage("in").setContent(new StringSource(MESSAGE));
-    	exchange.setProperty(DefaultFileMarshaler.TEMP_FILE_NAME_PROPERTY, tmp);
-    	String tempName = marshaler.getTempOutputName(exchange, exchange.getMessage("in"));
-    	assertEquals("The temp file name was not extracted correctly", tmp, tempName);
+        String tmp = "tmp_filename.ext_123";
+        MessageExchange exchange = createMockExchange();
+        exchange.getMessage("in").setContent(new StringSource(MESSAGE));
+        exchange.setProperty(DefaultFileMarshaler.TEMP_FILE_NAME_PROPERTY, tmp);
+        String tempName = marshaler.getTempOutputName(exchange, exchange.getMessage("in"));
+        assertEquals("The temp file name was not extracted correctly", tmp, tempName);
     }
     
     public void testTempFileNameNull() throws Exception {
-    	MessageExchange exchange = createMockExchange();
-    	exchange.getMessage("in").setContent(new StringSource(MESSAGE));
-    	String tempName = marshaler.getTempOutputName(exchange, exchange.getMessage("in"));
-    	assertNull("The temp file name was not null", tempName);
+        MessageExchange exchange = createMockExchange();
+        exchange.getMessage("in").setContent(new StringSource(MESSAGE));
+        String tempName = marshaler.getTempOutputName(exchange, exchange.getMessage("in"));
+        assertNull("The temp file name was not null", tempName);
     }
 }

Modified: servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java (original)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java Sat Mar 26 14:57:00 2011
@@ -81,4 +81,4 @@ public class HazelcastStoreTest extends 
         assertNotNull(data);
         assertEquals(data, result);        
     }
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/test/java/org/apache/servicemix/tck/mock/MockExchangeFactoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/tck/mock/MockExchangeFactoryTest.java?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/tck/mock/MockExchangeFactoryTest.java (original)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/tck/mock/MockExchangeFactoryTest.java Sat Mar 26 14:57:00 2011
@@ -70,4 +70,4 @@ public class MockExchangeFactoryTest ext
         assertNotNull(exchange.getExchangeId());
         assertEquals(MockExchangeFactory.ROBUST_IN_ONLY,exchange.getPattern());
     }
-}
\ No newline at end of file
+}

Modified: servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/encoding.xml
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/encoding.xml?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/encoding.xml (original)
+++ servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/encoding.xml Sat Mar 26 14:57:00 2011
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<test>l'élève est à l'école</test>        
\ No newline at end of file
+<test>l'élève est à l'école</test>        

Modified: servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/expression-editor.xml
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/expression-editor.xml?rev=1085730&r1=1085729&r2=1085730&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/expression-editor.xml (original)
+++ servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/expression-editor.xml Sat Mar 26 14:57:00 2011
@@ -20,7 +20,7 @@
 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 <beans>
 
-	<bean id="ExpressionTestSupport" class="org.apache.servicemix.expression.ExpressionTestSupport">
-		<property name="expression"><value>test</value></property>
-	</bean>
+    <bean id="ExpressionTestSupport" class="org.apache.servicemix.expression.ExpressionTestSupport">
+        <property name="expression"><value>test</value></property>
+    </bean>
 </beans>