So and other threats click on this package here new job class and the name of this class is going to
be iTunes.
Hush city client.
So remember our application our mobile device is going to be the client and it's the iTunes the iTunes
Web service is going to be the server.
So we are the client and we want to get the data from the server.
So that's why I actually created this class this class is going to actually connect to the server and
download those data and then click on OK here.
So here now we are inside of these items how shitty like a typical day in class.
So now I'm going to actually pasting some lines of code here inside this iTunes has shitty client class
and then I'm going to explain to you what's going on here.
So the first line of code that I want to actually paste in here is this line of code here as you can
see.
So as you can see the access modifier of these variable is actually private.
This is actually a static variable data type of this variable is strange.
So we have a string value.
OK.
And the name of this variable is based u r l.
So this is going to be the U R L that you want to actually get the the items that are right so high
shitty POS colon slash slash iTunes that Apple dot com slash search question mark and the term is Michael.
Plus Jackson.
OK so now I'm going to actually pasting MF at here and then I'm going to explain to you what's going
on here.
So as you can see here these are the lines of code that are actually pasted here.
OK.
So now I'm going to explain to you step by step what's going on here.
So as you can see here first of all this is actually the MF it and the access modifier of this method
is public.
The return type of this method is string.
So this is going to return an object of types 3.
OK.
And the name of this method is get iTunes stuff data.
So this is the name of this method right.
And here you can see this if it actually accepts a no arguments.
OK.
And here now am I to the inside of this method.
So inside of this method I created an object of type husht RL connection.
Ok this is very important because we want to connect to the iTunes Web service we need to create an
object of type husht connection and I assign the value null to this object here and in line 23.
I created an object of type input stream as you can see here the data type of this object is input stream
and then I assign the value gnarl to this object.
OK because we want to actually get the data and get those eight and put into our application.
We need to create an object of type input stream.
So here I have this try block here as you can see this try catch exception here as you can see here.
So first of all I created this try block.
So try.
And now inside the curly braces of this a try here as you can see I have these lines of code.
Ok I have this try block here.
So insight is tripe block.
This is very important.
We have we are actually initialising we are actually adding somebody used to these husht that if you
have a connection I am assigning a value to this hash to be a connection here.
11:27.
So I referred to the name of this husht that you are a connection object assignment operator.
So as you can see here I am actually casting this value here to a husht to be your connection object.
So I put this value here.
It is the name of the class I should have your connection inside the practices in order to recast this
value here to a husht you are a connection object.
So here as you can see inside the Prentice's here I actually say the prentices I am actually creating
an object new.
You all as you can see here I am creating an object of type u r l.
OK this is out of class and I am creating an object of type.
You are a class and inside Apprentice's of this you are all here.
This is the constructor of this.
You are in a class right inside Apprentice's.
I referred to the name of the base you are here.
OK.
So the base you are in is the you are at that all you want to actually get the data of the Michael Jackson
right.
As you can see here.
So here I actually created an object of type u r l and I passed this u r l.
This is actually a string value OK to this constructor of this class.
So now I have a U R L object.
OK.
And now as you can see I use this data notation here on this object.
So here as you can see I'm just creating this object without assigning this object to evaluate it to
evaluate it.
OK this is possible in Java.
I'm just creating this object and here I use this notation so that connection.
So this is actually an instance it inside the outer class so here we are we have a you are an object
and this is the method.
This is actually an instance method inside the you are a class open connection.
So I am calling this open connection method and this you are in.
So this means that it's going to actually open the connection that that is related to this.
You are here.
OK.
And it's going to actually cast this value to a real connection object.
OK.
I actually assigned this value to this has to be your last connection and then again in line 28 I referred
to the name of this has to be your connection object that set request method gets.
So because we want to actually get the data from the Internet the said request if must be good with
capital be capitalized to get as you can see here G.T. get.
This is very important and disvalue must be inside double quotes because we want to get the data from
the Internet.
OK.
And in line 29 as you can see husht it'll be your connection that said to input through and husht it
to be your own connection that's set to output.
So let's actually go to the Android documentation in order to see the docs of this has to be a collection
class.
So let's open our Web browser.
So as you can see here this is actually the Android documentation so it is in the search bar here.
I can actually search for husht DTP you RL connection class that is inside of the dot dot dot net package.
So I just need to click on this here and rapee ice and then it's going to actually guide us to this
page husht you all connection.
And this class is actually an abstract class public.
And this class actually extends from this RL connection class as you can see here.
So if you have some descriptions here or you are a connection with support for husht TTP specific features.
OK.
Users of this class follow up pattern obtain a new husht TTP your collection by calling you Arel that
open collection and casting the result to husht to put you on a collection.
So that's that's that's exactly what we did here.
OK.
And then are prepared to request to primary the primary property of a request.
Is it you or I.
OK.
Request headers may also include meta data such as credentials preferred content types and such cookies.
OK.
And these are some other descriptions.
And as you can see here we have this response handling husht you are a connection.
We'll follow up to five husht TTP directs.
It will follow a directs from one origin search and other.
This implementation does not follow redirects from husht TTP as to how she T-P or vice versa.
If the husht response indicates that an error occurred.
Get input stream and are no exception.
Use get error is thrain to read the error response.
The headers can be read in the normal way using the Get header fields and have performance OK.
Handling network seinen as I can see here GTP of integration and some other descriptions.
But for now we want to actually look at them effets.
And now let's scroll down and here this is really important.
Public methods.
So as you can see here we have disconnect indicates that other requests to the server are unlikely in
the near future.
We have good Airstream returns the airstream if the connection failed but the server sent useful data
nonetheless.
As you can see here and as you can see we have some other methods.
Good header field get header field DATE get instance followed redirects So it's important to actually
look at these methods and read the descriptions of these.
If it's OK and make sure that you actually read these descriptions OK this is really important.
And as you can see here we have this search request Meffert set them at for the request one of good
post head options put delete trace.
So we use this get in order to get the data from the Internet.
So now let's actually go back to our Android studio.
So as you can see here we have this Misfit's set.
Request Meffert is good because we want to get the entire information from the server.
And here you are the connection that soote to input.
True so because we want to actually get the data from the Internet and put that data put those information
into our application we need to set this Meffert true set to input true.
This is very important and inline filthy look at this line of code here.
Hush GTP you Aurel connection that set to output true.
OK this if it is actually for outputting data.
As for actually posting data to the Internet.
For example an application may want to actually upload some information to the server or post or post
something to the Internet this Smurfette to output does that job for us.
We don't need the Smurfette here.
I'll just put that here in order to show you what this method does.
We just want to get information from the Internet and put that in into our application.
OK.
We just live this one actually uploading or posting some data into the Internet.
So we don't need this method here because we just want to get the data from the Internet and put that
data into an application and show to the user.
So we just we can't actually comment out this line of code here.
I just wanted to show you what this Mivart does.
And in line for Steven actually referred to the name of this object husht to be your whole connection
that connect.
So it's going to connect to the Internet.
OK.
This is very important.
So and by the way in the future we will be creating more complex applications that involve Jason Parsees
or posting data to the Internet.
For now this is actually just the basic application in order to show you what is done and how to get
decent data from the Internet.
OK.
So and here as you can see I created a comment.
Let's read the response.
So now that we actually connected to the Internet now we want to actually read the response so in line
44 I created an object of type string buffer in order to read the response.
OK.
So the name of this object is a string buffer.
Assignment operator new string buffer an inline 45 as you can see here.
I referred to the name of this input stream object that I actually created inline to any free input
stream assignment operator husht it.
You are a collection that gets input stream.
So now I want to actually get the input stream from.
How should it be you are a connection object.
This is very important because we want to actually read the data if we want to.
We need to actually to initialize this input stream object in this way.
OK.
And then here in line for 86 I actually created an object of type buffer where the reader is slime and
the name of this object is buffered.
OK.
Assignment operator and as you can see here I am initializing this object new Bufford reader at inside
the prentices of these are constructed as you can see here new input stream B that I actually created
an object of type in put simply there and then I passed this input strip object to this in with string
reader here.
OK this is very important because we want to actually read the data from the Internet.
We need to create an object of type buffer every day.
So let's actually open our Android documentation and here as you can see in the search search bar I
can search for Barford buffer and reader class offered reader as you can see here inside the jobs that
are your package and as you can see here it says read text from a character input stream baffling characters
so as to provide for the efficient reading of characters arrows and lines.
So let's go to our Andrex studio.
So here I created an object of type Bufford reader assignment operator new Bufford reader and as you
can see here I am actually creating an object of type input stream reader and I pass this input stream
object to this input stream.
Reader here.
OK.
And inline 47.
I created an object of type string and I assign the value null to this object and the name of this object
is a line.
OK so I want to read the data line by line.
So here I created this while actually while loop here while as you can see and again inside Apprentice's
as you can see line I refer to this line here is string valuable assignment operator.
So here you refer to the next to the name of this Spofford written object that read the line so it can
actually read the data line by line.
OK buffer every bit of that read line.
And if this piece of code here is not equal to null.
OK.
If those information is going to be assigned to this line it's valuable.
And if this piece of code here as you can see here is not equal to nonne and this means that we successfully
got the data from the internet and inside the curly braces here then it's going to execute this line
of what you're saying buffer.
So here I referred to the name of this object string buffer that append.
OK.
Line as you can see here.
So here we are actually assigning this value line by line to this line string value is invaluable.
So line plus this is actually a newline character so we can actually delete this backward slash are
here.
OK.
And back forth slash art is actually our carriage return which means that the cursor should move to
the left leftmost column.
OK.
But this are back for a slash and it's actually a newline character.
OK so we just need this character here.
It can actually move the cursor to the next line.
OK.
So we just put this slash and here and now we are actually appending this value to the string buffer
object.
OK.
And in line 43 we need to close this impled stream here.
So input stream that close and in inline 44 as you can see here again we need to disconnect is how shitty
your whole connection after getting the data.
OK we need to close them and disconnected but how should it be you are a connection that disconnect.
And we are returning this string buffer object so return String buffer that to a string.
So remember this MF at here get iTunes stuff.
Data is actually returning a value of type string.
The return type of this Meffert is strange.
So if you need to return the string value of the string above an object string buffer.
That is strange.
And we have a catch up block here.
So in case that we cannot actually connect to the Internet or we don't have any internet connection
it's going to catch the errors and then it's going to output the error to the console to the larg t
that prints that trace.
As you can see here and we have this finally block here.
So this is very important.
So if the application fails to execute these lines of code here or if the application fails to execute
the try block here or the catch statement is going to finally execute these lines of code by putting
this finally block here if are 100 percent sure that it can actually execute these lines of code inside
is finally Blache so try and put in that close.
So here inside this finally block we have this try catch block here.
And again we are actually closing this input stream.
So if the if the application fails to execute these lines of code here as you can see it's going to
finally execute these things of course.
And this means that we are we are now 100 percent sure that it's going to close the input stream.
And how should we be sure that disconnect.
OK so these lines of code are going to be executed anyway.
So this is really important that you actually close the input stream and disconnect the connection.
OK.
And we have this catch block again in order to catch the errors and put them in the log.
And yet at the end if the flow of the application returns to this line of code here as you can see it's
going to return not what if the application succeeds to actually get the information from the Internet
is going to actually return this string buffer the twisting value.
So now let's actually paste in another Meffert.
In order to download the image from the Internet.
OK so remember we are actually getting the art form you are here in our iTunes in adjacent iTunes person
as you can see if you are actually setting the artist view you are there.
So you're getting this artwork here are for Twaddell So if you need to actually create another download
the image from the Internet.
So now I'm going to paste in MF at here and then I'm going to explain to you what's going on here.