/*
 * Copyright (C) 2010 TranceCode Software
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */
package org.trancecode.io;

import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Utility methods related to {@link InputStream} and {@link OutputStream}.
 * 
 * @author Herve Quiroz
 */
public final class TcByteStreams
{
    public static long copy(final InputStream in, final OutputStream out, final boolean close)
    {
        try
        {
            final long bytes = ByteStreams.copy(in, out);
            Closeables.close(in, false);
            Closeables.close(out, false);
            return bytes;
        }
        catch (final IOException e)
        {
            throw new RuntimeIOException(e);
        }
        finally
        {
            if (close)
            {
                Closeables.closeQuietly(in);
                Closeables.closeQuietly(out);
            }
        }
    }

    private TcByteStreams()
    {
        // No instantiation
    }
}

@@ -809,16 +809,56 @@
 de.io;%0A%0A
+import com.google.common.base.Supplier;%0A
 import c
@@ -890,16 +890,16 @@
 treams;%0A
-
 import c
@@ -931,16 +931,37 @@
 ables;%0A%0A
+import java.io.File;%0A
 import j
@@ -1746,32 +1746,32 @@
 ;%0A            %7D%0A
-
         %7D%0A    %7D%0A
@@ -1771,16 +1771,831 @@
 %0A    %7D%0A%0A
+    public static Supplier%3CFile%3E copyToTempFile(final InputStream in)%0A    %7B%0A        final File file = Files.createTempFile(TcByteStreams.class);%0A        final Thread thread = new Thread(new Runnable()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A                TcByteStreams.copy(in, Files.newFileOutputStream(file), true);%0A            %7D%0A        %7D);%0A        thread.start();%0A        return new Supplier%3CFile%3E()%0A        %7B%0A            @Override%0A            public File get()%0A            %7B%0A                try%0A                %7B%0A                    thread.join();%0A                %7D%0A                catch (final InterruptedException e)%0A                %7B%0A                    throw new IllegalStateException(e);%0A                %7D%0A                return file;%0A            %7D%0A        %7D;%0A    %7D%0A%0A
     priv

Add TcByteStreams.copyToTempFile()