VIRTUAL_HERO v2.1.0版本的 MD5 值为:3b332b47960b14f8b2d05ddc2f617624

以下内容为反编译后的 BingMapTileSource.java 源代码,内容仅作参考


package org.osmdroid.tileprovider.tilesource.bing;

import android.content.Context;
import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Locale;
import java.util.Map;
import org.osmdroid.api.IMapView;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.IStyledTileSource;
import org.osmdroid.tileprovider.tilesource.QuadTreeTileSource;
import org.osmdroid.tileprovider.util.ManifestUtil;
import org.osmdroid.tileprovider.util.StreamUtils;
public class BingMapTileSource extends QuadTreeTileSource implements IStyledTileSource<String> {
    private static final String BASE_URL_PATTERN = "https://dev.virtualearth.net/REST/V1/Imagery/Metadata/%s?mapVersion=v1&output=json&uriScheme=https&key=%s";
    private static final String BING_KEY = "BING_KEY";
    private static final String FILENAME_ENDING = ".jpeg";
    public static final String IMAGERYSET_AERIAL = "Aerial";
    public static final String IMAGERYSET_AERIALWITHLABELS = "AerialWithLabels";
    public static final String IMAGERYSET_ROAD = "Road";
    private static String mBingMapKey = "";
    private String mBaseUrl;
    private ImageryMetaDataResource mImageryData;
    private String mLocale;
    private String mStyle;
    private String mUrl;

    public BingMapTileSource(String str) {
        super("BingMaps", 0, 19, 256, FILENAME_ENDING, null);
        this.mStyle = IMAGERYSET_ROAD;
        this.mImageryData = ImageryMetaDataResource.getDefaultInstance();
        this.mLocale = str;
        if (str == null) {
            this.mLocale = Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry();
        }
    }

    public static void retrieveBingKey(Context context) {
        mBingMapKey = ManifestUtil.retrieveKey(context, BING_KEY);
    }

    public static String getBingKey() {
        return mBingMapKey;
    }

    public static void setBingKey(String str) {
        mBingMapKey = str;
    }

    @Override
    public String getBaseUrl() {
        if (!this.mImageryData.m_isInitialised) {
            initMetaData();
        }
        return this.mBaseUrl;
    }

    @Override
    public String getTileURLString(long j) {
        if (!this.mImageryData.m_isInitialised) {
            initMetaData();
        }
        return String.format(this.mUrl, quadTree(j));
    }

    @Override
    public int getMinimumZoomLevel() {
        return this.mImageryData.m_zoomMin;
    }

    @Override
    public int getMaximumZoomLevel() {
        return this.mImageryData.m_zoomMax;
    }

    @Override
    public int getTileSizePixels() {
        return this.mImageryData.m_imageHeight;
    }

    @Override
    public String pathBase() {
        return this.mName + this.mStyle;
    }

    @Override
    public String getCopyrightNotice() {
        return this.mImageryData.copyright;
    }

    @Override
    public void setStyle(String str) {
        if (!str.equals(this.mStyle)) {
            synchronized (this.mStyle) {
                this.mUrl = null;
                this.mBaseUrl = null;
                this.mImageryData.m_isInitialised = false;
            }
        }
        this.mStyle = str;
        this.mName = pathBase();
    }

    @Override
    public String getStyle() {
        return this.mStyle;
    }

    public ImageryMetaDataResource initMetaData() {
        ImageryMetaDataResource metaData;
        if (!this.mImageryData.m_isInitialised) {
            synchronized (this) {
                if (!this.mImageryData.m_isInitialised && (metaData = getMetaData()) != null) {
                    this.mImageryData = metaData;
                    updateBaseUrl();
                }
            }
        }
        return this.mImageryData;
    }

    private ImageryMetaDataResource getMetaData() {
        ByteArrayOutputStream byteArrayOutputStream;
        InputStream inputStream;
        HttpURLConnection httpURLConnection;
        InputStream inputStream2;
        Throwable th;
        InputStream inputStream3;
        BufferedOutputStream bufferedOutputStream;
        BufferedOutputStream bufferedOutputStream2;
        ByteArrayOutputStream byteArrayOutputStream2;
        ByteArrayOutputStream byteArrayOutputStream3;
        BufferedOutputStream bufferedOutputStream3;
        ImageryMetaDataResource instanceFromJSON;
        Log.d(IMapView.LOGTAG, "getMetaData");
        HttpURLConnection httpURLConnection2 = null;
        InputStream inputStream4 = null;
        try {
            httpURLConnection = (HttpURLConnection) new URL(String.format(BASE_URL_PATTERN, this.mStyle, mBingMapKey)).openConnection();
            try {
                Log.d(IMapView.LOGTAG, "make request " + httpURLConnection.getURL().toString().toString());
                httpURLConnection.setRequestProperty(Configuration.getInstance().getUserAgentHttpHeader(), Configuration.getInstance().getUserAgentValue());
                for (Map.Entry<String, String> entry : Configuration.getInstance().getAdditionalHttpRequestProperties().entrySet()) {
                    httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
                }
                httpURLConnection.connect();
                if (httpURLConnection.getResponseCode() != 200) {
                    Log.e(IMapView.LOGTAG, "Cannot get response for url " + httpURLConnection.getURL().toString() + " " + httpURLConnection.getResponseMessage());
                    instanceFromJSON = null;
                    byteArrayOutputStream = null;
                    bufferedOutputStream3 = null;
                } else {
                    inputStream3 = httpURLConnection.getInputStream();
                    try {
                        byteArrayOutputStream = new ByteArrayOutputStream();
                        try {
                            bufferedOutputStream3 = new BufferedOutputStream(byteArrayOutputStream, 8192);
                            try {
                                StreamUtils.copy(inputStream3, bufferedOutputStream3);
                                bufferedOutputStream3.flush();
                                instanceFromJSON = ImageryMetaData.getInstanceFromJSON(byteArrayOutputStream.toString());
                                inputStream4 = inputStream3;
                            } catch (Exception e) {
                                byteArrayOutputStream3 = byteArrayOutputStream;
                                inputStream2 = inputStream3;
                                e = e;
                                bufferedOutputStream = bufferedOutputStream3;
                                byteArrayOutputStream2 = byteArrayOutputStream3;
                                try {
                                    Log.e(IMapView.LOGTAG, "Error getting imagery meta data", e);
                                    if (httpURLConnection != null) {
                                        try {
                                            httpURLConnection.disconnect();
                                        } catch (Exception e2) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e2);
                                        }
                                    }
                                    if (inputStream2 != null) {
                                        try {
                                            inputStream2.close();
                                        } catch (Exception e3) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e3);
                                        }
                                    }
                                    if (byteArrayOutputStream2 != 0) {
                                        try {
                                            byteArrayOutputStream2.close();
                                        } catch (Exception e4) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e4);
                                        }
                                    }
                                    if (bufferedOutputStream != null) {
                                        try {
                                            bufferedOutputStream.close();
                                        } catch (Exception e5) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e5);
                                        }
                                    }
                                    Log.d(IMapView.LOGTAG, "end getMetaData");
                                    return null;
                                } catch (Throwable th2) {
                                    httpURLConnection2 = httpURLConnection;
                                    th = th2;
                                    inputStream3 = inputStream2;
                                    byteArrayOutputStream = byteArrayOutputStream2;
                                    bufferedOutputStream2 = bufferedOutputStream;
                                    if (httpURLConnection2 != null) {
                                        try {
                                            httpURLConnection2.disconnect();
                                        } catch (Exception e6) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e6);
                                        }
                                    }
                                    if (inputStream3 != null) {
                                        try {
                                            inputStream3.close();
                                        } catch (Exception e7) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e7);
                                        }
                                    }
                                    if (byteArrayOutputStream != null) {
                                        try {
                                            byteArrayOutputStream.close();
                                        } catch (Exception e8) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e8);
                                        }
                                    }
                                    if (bufferedOutputStream2 != 0) {
                                        try {
                                            bufferedOutputStream2.close();
                                        } catch (Exception e9) {
                                            Log.d(IMapView.LOGTAG, "end getMetaData", e9);
                                        }
                                    }
                                    Log.d(IMapView.LOGTAG, "end getMetaData");
                                    throw th;
                                }
                            } catch (Throwable th3) {
                                th = th3;
                                httpURLConnection2 = httpURLConnection;
                                bufferedOutputStream2 = bufferedOutputStream3;
                                if (httpURLConnection2 != null) {
                                }
                                if (inputStream3 != null) {
                                }
                                if (byteArrayOutputStream != null) {
                                }
                                if (bufferedOutputStream2 != 0) {
                                }
                                Log.d(IMapView.LOGTAG, "end getMetaData");
                                throw th;
                            }
                        } catch (Exception e10) {
                            bufferedOutputStream = null;
                            byteArrayOutputStream3 = byteArrayOutputStream;
                            inputStream2 = inputStream3;
                            e = e10;
                        } catch (Throwable th4) {
                            bufferedOutputStream2 = 0;
                            httpURLConnection2 = httpURLConnection;
                            th = th4;
                        }
                    } catch (Exception e11) {
                        byteArrayOutputStream2 = 0;
                        bufferedOutputStream = null;
                        inputStream2 = inputStream3;
                        e = e11;
                    } catch (Throwable th5) {
                        bufferedOutputStream2 = 0;
                        httpURLConnection2 = httpURLConnection;
                        th = th5;
                        byteArrayOutputStream = null;
                    }
                }
                if (httpURLConnection != null) {
                    try {
                        httpURLConnection.disconnect();
                    } catch (Exception e12) {
                        Log.d(IMapView.LOGTAG, "end getMetaData", e12);
                    }
                }
                if (inputStream4 != null) {
                    try {
                        inputStream4.close();
                    } catch (Exception e13) {
                        Log.d(IMapView.LOGTAG, "end getMetaData", e13);
                    }
                }
                if (byteArrayOutputStream != null) {
                    try {
                        byteArrayOutputStream.close();
                    } catch (Exception e14) {
                        Log.d(IMapView.LOGTAG, "end getMetaData", e14);
                    }
                }
                if (bufferedOutputStream3 != null) {
                    try {
                        bufferedOutputStream3.close();
                    } catch (Exception e15) {
                        Log.d(IMapView.LOGTAG, "end getMetaData", e15);
                    }
                }
                Log.d(IMapView.LOGTAG, "end getMetaData");
                return instanceFromJSON;
            } catch (Exception e16) {
                e = e16;
                inputStream2 = null;
                InputStream inputStream5 = inputStream2;
                bufferedOutputStream = inputStream5;
                byteArrayOutputStream2 = inputStream5;
                Log.e(IMapView.LOGTAG, "Error getting imagery meta data", e);
                if (httpURLConnection != null) {
                }
                if (inputStream2 != null) {
                }
                if (byteArrayOutputStream2 != 0) {
                }
                if (bufferedOutputStream != null) {
                }
                Log.d(IMapView.LOGTAG, "end getMetaData");
                return null;
            } catch (Throwable th6) {
                th = th6;
                byteArrayOutputStream = null;
                inputStream = null;
                httpURLConnection2 = httpURLConnection;
                th = th;
                inputStream3 = inputStream;
                bufferedOutputStream2 = inputStream;
                if (httpURLConnection2 != null) {
                }
                if (inputStream3 != null) {
                }
                if (byteArrayOutputStream != null) {
                }
                if (bufferedOutputStream2 != 0) {
                }
                Log.d(IMapView.LOGTAG, "end getMetaData");
                throw th;
            }
        } catch (Exception e17) {
            e = e17;
            httpURLConnection = null;
            inputStream2 = null;
        } catch (Throwable th7) {
            th = th7;
            byteArrayOutputStream = null;
            inputStream = null;
        }
    }

    protected void updateBaseUrl() {
        Log.d(IMapView.LOGTAG, "updateBaseUrl");
        String subDomain = this.mImageryData.getSubDomain();
        int lastIndexOf = this.mImageryData.m_imageUrl.lastIndexOf("/");
        if (lastIndexOf > 0) {
            this.mBaseUrl = this.mImageryData.m_imageUrl.substring(0, lastIndexOf);
        } else {
            this.mBaseUrl = this.mImageryData.m_imageUrl;
        }
        this.mUrl = this.mImageryData.m_imageUrl;
        if (subDomain != null) {
            this.mBaseUrl = String.format(this.mBaseUrl, subDomain);
            this.mUrl = String.format(this.mUrl, subDomain, "%s", this.mLocale);
        }
        Log.d(IMapView.LOGTAG, "updated url = " + this.mUrl);
        Log.d(IMapView.LOGTAG, "end updateBaseUrl");
    }
}