private ImageryMetaDataResource getMetaData ( ) { Log . d ( IMapView . LOGTAG , "getMetaData" ) ; ImageryMetaDataResource returnValue = null ; InputStream in = null ; HttpURLConnection client = null ; ByteArrayOutputStream dataStream = null ; BufferedOutputStream out = null ; try { client = ( HttpURLConnection ) ( new URL ( String . format ( BASE_URL_PATTERN , mStyle , mBingMapKey ) ) . openConnection ( ) ) ; Log . d ( IMapView . LOGTAG , "make request " + client . getURL ( ) . toString ( ) . toString ( ) ) ; client . setRequestProperty ( Configuration . getInstance ( ) . getUserAgentHttpHeader ( ) , Configuration . getInstance ( ) . getUserAgentValue ( ) ) ; for ( final Map . Entry < String , String > entry : Configuration . getInstance ( ) . getAdditionalHttpRequestProperties ( ) . entrySet ( ) ) { client . setRequestProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } client . connect ( ) ; if ( client . getResponseCode ( ) != 200 ) { Log . e ( IMapView . LOGTAG , "Cannot get response for url " + client . getURL ( ) . toString ( ) + " " + client . getResponseMessage ( ) ) ; } else { in = client . getInputStream ( ) ; dataStream = new ByteArrayOutputStream ( ) ; out = new BufferedOutputStream ( dataStream , StreamUtils . IO_BUFFER_SIZE ) ; StreamUtils . copy ( in , out ) ; out . flush ( ) ; returnValue = ImageryMetaData . getInstanceFromJSON ( dataStream . toString ( ) ) ; } } catch ( final Exception e ) { Log . e ( IMapView . LOGTAG , "Error getting imagery meta data" , e ) ; } finally { if ( client != null ) try { client . disconnect ( ) ; } catch ( Exception e ) { Log . d ( IMapView . LOGTAG , "end getMetaData" , e ) ; } if ( in != null ) try { in . close ( ) ; } catch ( Exception e ) { Log . d ( IMapView . LOGTAG , "end getMetaData" , e ) ; } if ( dataStream != null ) try { dataStream . close ( ) ; } catch ( Exception e ) { Log . d ( IMapView . LOGTAG , "end getMetaData" , e ) ; } if ( out != null ) try { out . close ( ) ; } catch ( Exception e ) { Log . d ( IMapView . LOGTAG , "end getMetaData" , e ) ; } Log . d ( IMapView . LOGTAG , "end getMetaData" ) ; } return returnValue ; }
Gets the imagery meta from the REST service or null if it fails