/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.util;

import java.io.Closeable;
import java.io.IOException;

// from m-c.
public class IOUtil {

    private IOUtil() {}

    public static void safeStreamClose(Closeable stream) {
        try {
            if (stream != null)
                stream.close();
        } catch (IOException e) { }
    }
}

@@ -284,21 +284,90 @@
 on;%0A
-%0A// from m-c.
+import java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A
 %0Apub
@@ -411,16 +411,33 @@
 l() %7B%7D%0A%0A
+    // from m-c.%0A
     publ
@@ -606,11 +606,1846 @@
  %7D%0A    %7D
+%0A%0A    // TODO: explain how this should be used.%0A    /**%0A     * Blocks until the given asynchronous call completes.%0A     *%0A     * @param timeoutMillis The number of milliseconds until this call times out.%0A     * @param asyncCall An object whose method will begin the async call.%0A     * @param %3CT%3E Return type of the async call.%0A     * @return The result of the asynchronous call.%0A     * @throws Exception An exception thrown during the async task.%0A     */%0A    public static %3CT%3E T makeSync(final long timeoutMillis, final AsyncCall%3CT%3E asyncCall) throws Exception %7B // TODO: ExecutionException.%0A        final CountDownLatch makeSyncLatch = new CountDownLatch(1);%0A        final AsyncReturnValueContainer%3CT%3E returnValueContainer = new AsyncReturnValueContainer%3CT%3E();%0A%0A        asyncCall.initAsyncCall(new OnAsyncCallComplete%3CT%3E() %7B%0A            @Override%0A            public void onSuccess(T returnValue) %7B%0A                returnValueContainer.returnValue = returnValue;%0A                makeSyncLatch.countDown();%0A            %7D%0A%0A            @Override%0A            public void onError(final Exception e) %7B%0A                returnValueContainer.exception = e;%0A                makeSyncLatch.countDown();%0A            %7D%0A        %7D);%0A%0A        makeSyncLatch.await(timeoutMillis, TimeUnit.MILLISECONDS);%0A        if (returnValueContainer.exception != null) %7B throw returnValueContainer.exception; %7D%0A        return returnValueContainer.returnValue;%0A    %7D%0A%0A    private static class AsyncReturnValueContainer%3CT%3E %7B%0A        private Exception exception;%0A        private T returnValue;%0A    %7D%0A%0A    // TODO: docs.%0A    public interface AsyncCall%3CT%3E %7B%0A        void initAsyncCall(OnAsyncCallComplete%3CT%3E onComplete);%0A    %7D%0A%0A    // todo: DOCS.%0A    public interface OnAsyncCallComplete%3CT%3E %7B%0A        void onError(Exception e);%0A        void onSuccess(T returnValue);%0A    %7D
 %0A%7D%0A

Add IOUtil.makeSync.