OK. 2
Finally let's get back to our project and let's make some extensions. 3
I think it's been a while. 4
So it's time for us to extend our project. 5
So we're going to get to some of the stuff we have learned in the previous lesson. 6
And the main thing that we are going to test is how to read data from that text in an efficient way 7
. 8
So that's what we learned in the previous lesson. 9
Now we are going to test that. 10
Now if you recall we had this class data stores which was acting as a database and all the data was 11
hardcoded here in this class. 12
Ok here you are. 13
Here we are. 14
For example here we have the user data and we hardcoded it. 15
And similarly if you go down we had babblings. 16
And further down we had movies and books. 17
So all of that it was hardcoded. 18
So we were not using a database. 19
So we had to rely on this class to provide that data. 20
Now what we're going to do is we're going to move all of this data into files okaying or text files 21
and we are going to read from that. 22
So that's going to be a nice extension. 23
So you're going to do that. 24
And if you'll recall when we created this class we also created these four classes that text files that 25
you'll see here book more we use it on babbling. 26
They actually had that data with them. 27
Of course we did not use any of those files but we just use the data from that. 28
So but now we're going to use the files. 29
OK. 30
And the data that you'll see here is the data that we have here we simply copied the data and do these 31
files and we just hardcoded them. 32
So now we are going to remove all of this we are going to delete all of this and we are going to simply 33
read from the file. 34
So I wanted to read in the code. 35
So you're not going to write any new code here. 36
And in fact we have already seen the code and then the last lesson. 37
So we are just going to review the code that has already been written. 38
So it's it's the exact same code. 39
So we don't have to write it again. 40
So let's just go ahead and let's just look at the code. 41
So if you recall this is the project really all I want is another project which is for our demo classes 42
the classes that we use for demoing our concepts. 43
So it really is a project that we created. 44
And we had all these packages here and I have created a new package called as you can see this com semantic 45
script through Leo and UKL and biton the utile class. 46
I created this class called Sauti within the package I created this class called. 47
I will you can. 48
So you would how all utility classes. 49
OK. 50
Any utility classes that we are going to create will go into this package. 51
So the first one that we have created is all your data. 52
Ok I can hear how to read motard so that we can read data from these files undertreatment there has 53
two parameters. 54
One is data string array. 55
Another is filename. 56
OK so in a given invocation we would pass the final one off the filenames and we will read the data 57
into this string at it. 58
So it's kind of similar to the read method that we have seen in the reader class where we were passing 59
a character characters. 60
OK. 61
So it's exactly identical to that. 62
So in this case we would read for example for instance if we passed the user filename then we would 63
use this data on each element in the idea would be filled up. 64
One of the lines on these lines here that it is operated by DAPs. 65
So in this case the array size would be fine by the time we read all of this the size of the string 66
array would be fine. 67
So each element in that it would store a single line. 68
So here. 69
So as we have as you can see here is a file name we are creating a file input stream object and we are 70
chaining it to input stream reader or an input stream reader also has another parameter which is a character 71
sort of it's just the encoding scheme and it is of 8 here and it is in Don't chained to a buffer treater 72
for performance. 73
OK. 74
And this is the third try with the resources Sendak's that we are using here and here is a line and 75
here we are reading invoking the read line method. 76
We order did ask it and we are invoking it on the radar object on that line and we are storing that 77
line in this Are called data and we are incrementing on the index variable as being incremented here 78
. 79
So it's initialized to zero and after adding in line it's once again being incremented on whenever we 80
reach whenever read Landru dense and then we terminate dunno. 81
It means that we have read everything that we need. 82
Now here I just have to try I need to add some catch blocks here. 83
So here is the first one. 84
It says I need to add some exceptions here. 85
The catch blocks here. 86
So let's just go ahead and say I'd catch Glaus to try. 87
So it's going to add to the cache but also on his unsupported and coding exception the other one is 88
file not found exception. 89
Another one is the last one is Iowa exception. 90
Now we don't have those errors anymore here. 91
But first let me run this existing file. 92
So that's the old version. 93
So far everything is running fine. 94
So now it's time to commandeers out 95
and here it is. 96
So this is a new chord. 97
So this is a little user's method and that they just are class so it's going to load user data. 98
So here we are creating a string instance and we have a total of five users. 99
So the size of the string arrays 5 and we are invoking the I will you tell Metford the read method and 100
we are passing this data the string array and we are passing the name of the file which is user. 101
OK so user has all of this data here. 102
So this is the ID field. 103
This is the. 104
And third one I need to see what that is but this is the first name last name. 105
This is the gender under the user type I guess. 106
Yeah. 107
And this is the password. 108
So that's the thing. 109
And here we are reading the reader once the data is read. 110
We are the next step is to just do whatever we are doing here which is to create user instances and 111
store them. 112
And this they called us users. 113
OK. 114
So that's what we are doing here. 115
In each iteration we are creating a single user instance on storing it in the users. 116
Ari. 117
OK. 118
So here we are iterating the string array. 119
And in each iteration we are going to read a single line that has been read and since it is tabular 120
McGirt we are splitting that line. 121
We are we are calling it as a roll. 122
Each line this is being called as a row and we are splitting it by TAB delimiter but tab delimiter because 123
the data is delimited by tabs and so the values get stored here. 124
And then the sixth element is actually the gender. 125
So we are getting that gender information here. 126
So by default we are saying it is male but then if it happens to be F in which case we are reassigning 127
it to wit and gendered or female. 128
Otherwise we are re-assigning a good transgender and everything is fine here. 129
It's a long way. 130
The first one the idea is long. 131
So we are doing a long Darbar so long to get along well you and everything else is fine. 132
So let's just go ahead and run with this first change and everything is fine. 133
So let's go ahead and make the second change also. 134
And this is for ramblings. 135
So here is the blank file. 136
And you have this information here and you can ignore the last fill here for all of the bookmarks wabbling 137
movie and book. 138
There is this thing called the unknown which is which indicates the kid friendly starters but you don't 139
have to worry about it for now. 140
So 141
OK so similarly we are declaring the string here creating the string array and this value is five count 142
per type. 143
So we are going to have five bookmarks for each type. 144
So let's start variable and we are passing this name weblink. 145
And the same thing. 146
We are simply spreading the values and we are invoking it here. 147
Our only thing is the unknown value which you read which I said that we can ignore as being ignored 148
here. 149
And the same bet movies do. 150
So let me comment this out. 151
OK. 152
So we are passing the movie as a filename here and we are spreading the values. 153
Only thing is cast here and diverters. 154
So if you go here cast and directors can have multiple values which are supported by commas. 155
So this piece of code is taking care of that. 156
So we are splitting that into String Array here. 157
And we are simply passing those values here. 158
Gaston directors are being passed us a string Arrius. 159
So that's what movies and the final bonus books. 160
So I'm going to upload these three methods three or four methods into a file so you can look at data 161
in the resources section. 162
So here you are passing book and bookmark count. 163
Once again file eins here only the authors can have multiple values. 164
So because a book can be written by multiple authors. 165
So that's why we are using another split on the fifth the value that is supposed to represent the authors 166
. 167
So that's about it. 168
So we have all of this sort of mirrored around it one more time and everything is running fine. 169
It's well-tested so it's running fine. 170
So I'm going to just upload those methods. 171
This matter I don't have to upload I think you can write it yourself but I might also upload this. 172
So that's about it that's how we are going to read data here by chaining multiple training so that's 173
the recreative Madden Huynh buffer reader helps in reading it in a very efficient way. 174
And we are using UTF 8 here. 175
That's about it. 176
And thank you