// Path: library/src/main/java/com/danikula/videocache/headers/EmptyHeadersInjector.java
// public class EmptyHeadersInjector implements HeaderInjector {
// 
//     @Override
//     public Map<String, String> addHeaders(String url) {
//         return new HashMap<>();
//     }
// 
// }
// 
// Path: library/src/main/java/com/danikula/videocache/headers/HeaderInjector.java
// public interface HeaderInjector {
// 
//     /**
//      * Adds headers to server's requests for corresponding url.
//      *
//      * @param url an url headers will be added for
//      * @return a map with headers, where keys are header's names, and values are header's values. {@code null} is not acceptable!
//      */
//     Map<String, String> addHeaders(String url);
// 
// }
// 
// Path: library/src/main/java/com/danikula/videocache/sourcestorage/SourceInfoStorage.java
// public interface SourceInfoStorage {
// 
//     SourceInfo get(String url);
// 
//     void put(String url, SourceInfo sourceInfo);
// 
//     void release();
// }
// 
// Path: library/src/main/java/com/danikula/videocache/sourcestorage/SourceInfoStorageFactory.java
// public class SourceInfoStorageFactory {
// 
//     public static SourceInfoStorage newSourceInfoStorage(Context context) {
//         return new DatabaseSourceInfoStorage(context);
//     }
// 
//     public static SourceInfoStorage newEmptySourceInfoStorage() {
//         return new NoSourceInfoStorage();
//     }
// }
// 
// Path: library/src/main/java/com/danikula/videocache/Preconditions.java
// public static <T> T checkNotNull(T reference) {
//     if (reference == null) {
//         throw new NullPointerException();
//     }
//     return reference;
// }
// 
// Path: library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java
// static final int DEFAULT_BUFFER_SIZE = 8 * 1024;


import android.text.TextUtils;
import com.danikula.videocache.headers.EmptyHeadersInjector;
import com.danikula.videocache.headers.HeaderInjector;
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import static com.danikula.videocache.Preconditions.checkNotNull;
import static com.danikula.videocache.ProxyCacheUtils.DEFAULT_BUFFER_SIZE;
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.HttpURLConnection.HTTP_PARTIAL;
import static java.net.HttpURLConnection.HTTP_SEE_OTHER;
package com.danikula.videocache;






/**
 * {@link Source} that uses http resource as source for {@link ProxyCache}.
 *
 * @author Alexey Danilov (danikula@gmail.com).
 */
public class HttpUrlSource implements Source {

    private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource");

    private static final int MAX_REDIRECTS = 5;
    private final SourceInfoStorage sourceInfoStorage;
    private final HeaderInjector headerInjector;
    private SourceInfo sourceInfo;
    private HttpURLConnection connection;
    private InputStream inputStream;

    public HttpUrlSource(String url) {
        this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
    }

    public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
        this(url, sourceInfoStorage, new EmptyHeadersInjector());
    }

    public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
// Path: library/src/main/java/com/danikula/videocache/headers/EmptyHeadersInjector.java
// public class EmptyHeadersInjector implements HeaderInjector {
// 
//     @Override
//     public Map<String, String> addHeaders(String url) {
//         return new HashMap<>();
//     }
// 
// }
// 
// Path: library/src/main/java/com/danikula/videocache/headers/HeaderInjector.java
// public interface HeaderInjector {
// 
//     /**
//      * Adds headers to server's requests for corresponding url.
//      *
//      * @param url an url headers will be added for
//      * @return a map with headers, where keys are header's names, and values are header's values. {@code null} is not acceptable!
//      */
//     Map<String, String> addHeaders(String url);
// 
// }
// 
// Path: library/src/main/java/com/danikula/videocache/sourcestorage/SourceInfoStorage.java
// public interface SourceInfoStorage {
// 
//     SourceInfo get(String url);
// 
//     void put(String url, SourceInfo sourceInfo);
// 
//     void release();
// }
// 
// Path: library/src/main/java/com/danikula/videocache/sourcestorage/SourceInfoStorageFactory.java
// public class SourceInfoStorageFactory {
// 
//     public static SourceInfoStorage newSourceInfoStorage(Context context) {
//         return new DatabaseSourceInfoStorage(context);
//     }
// 
//     public static SourceInfoStorage newEmptySourceInfoStorage() {
//         return new NoSourceInfoStorage();
//     }
// }
// 
// Path: library/src/main/java/com/danikula/videocache/Preconditions.java
// public static <T> T checkNotNull(T reference) {
//     if (reference == null) {
//         throw new NullPointerException();
//     }
//     return reference;
// }
// 
// Path: library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java
// static final int DEFAULT_BUFFER_SIZE = 8 * 1024;


// Path: library/src/main/java/com/danikula/videocache/HttpUrlSource.java
import android.text.TextUtils;
import com.danikula.videocache.headers.EmptyHeadersInjector;
import com.danikula.videocache.headers.HeaderInjector;
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import static com.danikula.videocache.Preconditions.checkNotNull;
import static com.danikula.videocache.ProxyCacheUtils.DEFAULT_BUFFER_SIZE;
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.HttpURLConnection.HTTP_PARTIAL;
import static java.net.HttpURLConnection.HTTP_SEE_OTHER;

package com.danikula.videocache;






/**
 * {@link Source} that uses http resource as source for {@link ProxyCache}.
 *
 * @author Alexey Danilov (danikula@gmail.com).
 */
public class HttpUrlSource implements Source {

    private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource");

    private static final int MAX_REDIRECTS = 5;
    private final SourceInfoStorage sourceInfoStorage;
    private final HeaderInjector headerInjector;
    private SourceInfo sourceInfo;
    private HttpURLConnection connection;
    private InputStream inputStream;

    public HttpUrlSource(String url) {
        this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
    }

    public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
        this(url, sourceInfoStorage, new EmptyHeadersInjector());
    }

    public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
        this.sourceInfoStorage = checkNotNull(sourceInfoStorage);