Networking Basics

You are going to have one class handle the networking in PhotoGallery. Create a new Java class and, since you will be connecting to Flickr, name this class FlickrFetchr.

FlickrFetchr will start off small with only two methods: getUrlBytes(String) and getUrlString(String). The getUrlBytes(String) method fetches raw data from a URL and returns it as an array of bytes. The getUrlString(String) method converts the result from getUrlBytes(String) to a String.

In FlickrFetchr.java, add implementations for getUrlBytes(String) and getUrlString(String) (Listing 23.3).

Listing 23.3  Basic networking code (FlickrFetchr.java)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​F​l​i​c​k​r​F​e​t​c​h​r​ ​{​
 ​ ​ ​ ​p​u​b​l​i​c​ ​b​y​t​e​[​]​ ​g​e​t​U​r​l​B​y​t​e​s​(​S​t​r​i​n​g​ ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.