/*
 *  Copyright (c) 2015-2016 Tapglue (https://www.tapglue.com/). All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.tapglue.sdk;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.functions.Action1;

public class RxWrapper<T> {
    public T unwrap(Observable<T> observable) throws IOException {
        final List<T> returnValue = new ArrayList<>();
        final Throwable[] throwable = new Throwable[1];

        observable.toBlocking().subscribe(new Action1<T>() {
            @Override
            public void call(T t) {
                returnValue.add(t);
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable t) {
                throwable[0] = t;
            }
        });

        if(throwable[0] != null) {
            if(throwable[0] instanceof IOException) {
                throw (IOException) throwable[0];
            } else {
                throw new RuntimeException(throwable[0]);
            }
        } else {
            return returnValue.isEmpty() ? null : returnValue.get(0);
        }
    }
}

@@ -709,59 +709,8 @@
 ion;
-%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0A%0Aim
@@ -872,43 +872,37 @@
 nal 
-List%3CT%3E returnValue = new ArrayList
+Holder%3CT%3E holder = new Holder
 %3C%3E()
@@ -1099,26 +1099,22 @@
     
-returnValue.add(t)
+holder.obj = t
 ;%0A  
@@ -1562,58 +1562,65 @@
 urn 
-returnValue.isEmpty() ? null : returnValue.get(0);
+holder.obj;%0A        %7D%0A    %7D%0A%0A    static class Holder%3CT%3E %7B
 %0A   
@@ -1620,22 +1620,27 @@
 %3E %7B%0A        
-%7D
+T obj;
 %0A    %7D%0A%7D%0A

Replace array with holder in RxWrapper