<commit_before>/*
 *  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);
        }
    }
}<commit_msg>Replace array with holder in RxWrapper<commit_after>/*
 *  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 rx.Observable;
import rx.functions.Action1;

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

        observable.toBlocking().subscribe(new Action1<T>() {
            @Override
            public void call(T t) {
                holder.obj = 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 holder.obj;
        }
    }

    static class Holder<T> {
        T obj;
    }
}
{'fraction_non_alphanumeric': 0.09859566998244587, 'fraction_numerical': 0.012580456407255705, 'mean_word_length': 2.2407582938388626, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2644247', 'n_tokens_mistral': 960, 'n_tokens_neox': 921, 'n_words': 309}