package net.gotev.uploadservice;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import net.gotev.uploadservice.schemehandlers.SchemeHandler;
import net.gotev.uploadservice.schemehandlers.SchemeHandlerFactory;
/* loaded from: classes.dex */
public class UploadFile implements Parcelable {
    public static final Parcelable.Creator<UploadFile> CREATOR = new Parcelable.Creator<UploadFile>() { // from class: net.gotev.uploadservice.UploadFile.1
        @Override // android.os.Parcelable.Creator
        public UploadFile createFromParcel(Parcel parcel) {
            return new UploadFile(parcel);
        }

        @Override // android.os.Parcelable.Creator
        public UploadFile[] newArray(int i) {
            return new UploadFile[i];
        }
    };
    protected final SchemeHandler handler;
    protected final String path;
    private LinkedHashMap<String, String> properties;

    @Override // android.os.Parcelable
    public int describeContents() {
        return 0;
    }

    public UploadFile(String str) throws FileNotFoundException {
        this.properties = new LinkedHashMap<>();
        if (str == null || BuildConfig.FLAVOR.equals(str)) {
            throw new IllegalArgumentException("Please specify a file path!");
        }
        if (!SchemeHandlerFactory.getInstance().isSupported(str)) {
            throw new UnsupportedOperationException("Unsupported scheme: " + str);
        }
        this.path = str;
        try {
            this.handler = SchemeHandlerFactory.getInstance().get(str);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public long length(Context context) {
        return this.handler.getLength(context);
    }

    public final InputStream getStream(Context context) throws FileNotFoundException {
        return this.handler.getInputStream(context);
    }

    public final String getContentType(Context context) {
        return this.handler.getContentType(context);
    }

    public final String getName(Context context) {
        return this.handler.getName(context);
    }

    public final String getPath() {
        return this.path;
    }

    @Override // android.os.Parcelable
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.path);
        parcel.writeSerializable(this.properties);
    }

    private UploadFile(Parcel parcel) {
        this.properties = new LinkedHashMap<>();
        String readString = parcel.readString();
        this.path = readString;
        this.properties = (LinkedHashMap) parcel.readSerializable();
        try {
            this.handler = SchemeHandlerFactory.getInstance().get(readString);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void setProperty(String str, String str2) {
        this.properties.put(str, str2);
    }

    public String getProperty(String str) {
        return this.properties.get(str);
    }

    public String getProperty(String str, String str2) {
        String str3 = this.properties.get(str);
        return str3 == null ? str2 : str3;
    }
}
