package com.chiorichan.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * Class containing file utilities
 */
public class FileUtil
{
	/**
	 * This method copies one file to another location
	 * 
	 * @param inFile
	 *             the source filename
	 * @param outFile
	 *             the target filename
	 * @return true on success
	 */
	
	@SuppressWarnings( "resource" )
	public static boolean copy( File inFile, File outFile )
	{
		if ( !inFile.exists() )
		{
			return false;
		}
		
		FileChannel in = null;
		FileChannel out = null;
		
		try
		{
			in = new FileInputStream( inFile ).getChannel();
			out = new FileOutputStream( outFile ).getChannel();
			
			long pos = 0;
			long size = in.size();
			
			while ( pos < size )
			{
				pos += in.transferTo( pos, 10 * 1024 * 1024, out );
			}
		}
		catch ( IOException ioe )
		{
			return false;
		}
		finally
		{
			try
			{
				if ( in != null )
				{
					in.close();
				}
				if ( out != null )
				{
					out.close();
				}
			}
			catch ( IOException ioe )
			{
				return false;
			}
		}
		
		return true;
	}
}

@@ -23,16 +23,54 @@
 .util;%0A%0A
+import java.io.ByteArrayOutputStream;%0A
 import j
@@ -175,16 +175,44 @@
 eption;%0A
+import java.io.InputStream;%0A
 import j
@@ -309,16 +309,488 @@
 eUtil%0A%7B%0A
+%09public static byte%5B%5D inputStream2Bytes( InputStream is ) throws IOException%0A%09%7B%0A%09%09return inputStream2ByteArray( is ).toByteArray();%0A%09%7D%0A%0A%09public static ByteArrayOutputStream inputStream2ByteArray( InputStream is ) throws IOException%0A%09%7B%0A%09%09int nRead;%0A%09%09byte%5B%5D data = new byte%5B16384%5D;%0A%09%09ByteArrayOutputStream bs = new ByteArrayOutputStream();%0A%0A%09%09while ( (nRead = is.read( data, 0, data.length )) != -1 )%0A%09%09%7B%0A%09%09%09bs.write( data, 0, nRead );%0A%09%09%7D%0A%0A%09%09bs.flush();%0A%0A%09%09return bs;%0A%09%7D%0A%0A
 %09/**%0A%09 *
@@ -841,17 +841,16 @@
 tion%0A%09 *
- 
 %0A%09 * @pa
@@ -859,36 +859,24 @@
 m inFile%0A%09 *
-            
  the source 
@@ -906,28 +906,16 @@
 File%0A%09 *
-            
  the tar
@@ -960,18 +960,16 @@
 ss%0A%09 */%0A
-%09%0A
 %09@Suppre
@@ -1079,20 +1079,16 @@
 sts() )%0A
-%09%09%7B%0A
 %09%09%09retur
@@ -1096,22 +1096,16 @@
  false;%0A
-%09%09%7D%0A%09%09
 %0A%09%09FileC
@@ -1148,18 +1148,16 @@
 = null;%0A
-%09%09
 %0A%09%09try%0A%09
@@ -1262,27 +1262,24 @@
 tChannel();%0A
-%09%09%09
 %0A%09%09%09long pos
@@ -1310,19 +1310,16 @@
 size();%0A
-%09%09%09
 %0A%09%09%09whil
@@ -1502,30 +1502,24 @@
 n != null )%0A
-%09%09%09%09%7B%0A
 %09%09%09%09%09in.clos
@@ -1523,22 +1523,16 @@
 lose();%0A
-%09%09%09%09%7D%0A
 %09%09%09%09if (
@@ -1550,14 +1550,8 @@
 l )%0A
-%09%09%09%09%7B%0A
 %09%09%09%09
@@ -1568,14 +1568,8 @@
 ();%0A
-%09%09%09%09%7D%0A
 %09%09%09%7D
@@ -1630,18 +1630,16 @@
 %09%09%7D%0A%09%09%7D%0A
-%09%09
 %0A%09%09retur

Add an InputStream consumer to the FileUtils class