geopackage-sdk/src/main/java/mil/nga/geopackage/tiles/UrlTileGenerator.java
@Override
    protected byte[] createTile(int z, long x, long y) {

        byte[] bytes = null;

        String zoomUrl = tileUrl;

        // Replace x, y, and z
        if (urlHasXYZ) {
            long yRequest = y;

            // If TMS, flip the y value
            if (tms) {
                yRequest = TileBoundingBoxUtils.getYAsOppositeTileFormat(z,
                        (int) y);
            }

            zoomUrl = replaceXYZ(zoomUrl, z, x, yRequest);
        }

        // Replace bounding box
        if (urlHasBoundingBox) {
            zoomUrl = replaceBoundingBox(zoomUrl, z, x, y);
        }

        URL url;
        try {
            url = new URL(zoomUrl);
        } catch (MalformedURLException e) {
            throw new GeoPackageException("Failed to download tile. URL: "
                    + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y, e);
        }

        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();

            int responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_MOVED_PERM
                    || responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                    || responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
                String redirect = connection.getHeaderField("Location");
                connection.disconnect();
                url = new URL(redirect);
                connection = (HttpURLConnection) url.openConnection();
                connection.connect();
            }

            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new GeoPackageException("Failed to download tile. URL: "
                        + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y);
            }

            InputStream geoPackageStream = connection.getInputStream();
            bytes = GeoPackageIOUtils.streamBytes(geoPackageStream);

        } catch (IOException e) {
            throw new GeoPackageException("Failed to download tile. URL: "
                    + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y, e);
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }

        return bytes;
    }
@Override
    protected byte[] createTile(int z, long x, long y) {

        byte[] bytes = null;

        String zoomUrl = tileUrl;

        // Replace x, y, and z
        if (urlHasXYZ) {
            long yRequest = y;

            // If TMS, flip the y value
            if (tms) {
                yRequest = TileBoundingBoxUtils.getYAsOppositeTileFormat(z,
                        (int) y);
            }

            zoomUrl = replaceXYZ(zoomUrl, z, x, yRequest);
        }

        // Replace bounding box
        if (urlHasBoundingBox) {
            zoomUrl = replaceBoundingBox(zoomUrl, z, x, y);
        }

        URL url;
        try {
            url = new URL(zoomUrl);
        } catch (MalformedURLException e) {
            throw new GeoPackageException("Failed to download tile. URL: "
                    + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y, e);
        }

        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();

            int responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_MOVED_PERM
                    || responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                    || responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
                String redirect = connection.getHeaderField("Location");
                connection.disconnect();
                url = new URL(redirect);
                connection = (HttpURLConnection) url.openConnection();
                connection.connect();
            }

            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new GeoPackageException("Failed to download tile. URL: "
                        + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y);
            }

            InputStream geoPackageStream = connection.getInputStream();
            bytes = GeoPackageIOUtils.streamBytes(geoPackageStream);

        } catch (IOException e) {
            throw new GeoPackageException("Failed to download tile. URL: "
                    + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y, e);
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }

        return bytes;
    }
@ Override protected byte [ ] createTile ( int z , long x , long y ) { byte [ ] bytes = null ; String zoomUrl = tileUrl ; // Replace x, y, and z if ( urlHasXYZ ) { long yRequest = y ; // If TMS, flip the y value if ( tms ) { yRequest = TileBoundingBoxUtils . getYAsOppositeTileFormat ( z , ( int ) y ) ; } zoomUrl = replaceXYZ ( zoomUrl , z , x , yRequest ) ; } // Replace bounding box if ( urlHasBoundingBox ) { zoomUrl = replaceBoundingBox ( zoomUrl , z , x , y ) ; } URL url ; try { url = new URL ( zoomUrl ) ; } catch ( MalformedURLException e ) { throw new GeoPackageException ( "Failed to download tile. URL: " + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y , e ) ; } HttpURLConnection connection = null ; try { connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . connect ( ) ; int responseCode = connection . getResponseCode ( ) ; if ( responseCode == HttpURLConnection . HTTP_MOVED_PERM || responseCode == HttpURLConnection . HTTP_MOVED_TEMP || responseCode == HttpURLConnection . HTTP_SEE_OTHER ) { String redirect = connection . getHeaderField ( "Location" ) ; connection . disconnect ( ) ; url = new URL ( redirect ) ; connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . connect ( ) ; } if ( connection . getResponseCode ( ) != HttpURLConnection . HTTP_OK ) { throw new GeoPackageException ( "Failed to download tile. URL: " + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y ) ; } InputStream geoPackageStream = connection . getInputStream ( ) ; bytes = GeoPackageIOUtils . streamBytes ( geoPackageStream ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to download tile. URL: " + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y , e ) ; } finally { if ( connection != null ) { connection . disconnect ( ) ; } } return bytes ; }
{@inheritDoc}
{