1

00:00:01,110  -->  00:00:07,530
Let's not look at how we can read and write text efficiently and the sort sort of thing here can be

2

00:00:07,530  -->  00:00:14,090
a file or a socket or even a console that is a command prompt in the follow up lessons.

3

00:00:14,120  -->  00:00:21,970
People do the most of most of the stuff we learn in this lesson let's begin with file reader unfiled

4

00:00:21,980  -->  00:00:23,430
either process.

5

00:00:23,490  -->  00:00:29,830
And as the name suggests they are used to handle files that contain text obviously files that is for

6

00:00:29,830  -->  00:00:34,780
reading characters while Filemaker is for writing got actors.

7

00:00:34,860  -->  00:00:37,060
And here is how they are instantiated.

8

00:00:37,110  -->  00:00:41,960
You simply pass a filename to their constructors.

9

00:00:41,970  -->  00:00:48,180
Earlier you said that character streams are built on top of byte streams and these classes are built

10

00:00:48,180  -->  00:00:52,110
on top of file input stream unfiled stream process.

11

00:00:52,140  -->  00:00:58,050
So internally they use these classes to do the actual reading and writing off bytes and they perform

12

00:00:58,050  -->  00:01:02,930
the necessary to and fro cancellations between bytes and characters.

13

00:01:03,990  -->  00:01:10,510
Now JVM has a default Goudeket encoding for reading and writing bytes on these classes use that encoding

14

00:01:11,540  -->  00:01:19,110
and by default JVM actually uses the default character encoding of the underlying operating system.

15

00:01:19,110  -->  00:01:23,570
I believe it is C.P 12:52 on Windows annually of 8 on Linux.

16

00:01:24,120  -->  00:01:31,170
So it is a JVM configuration and if you want to change the JVM to different encoding you can set it

17

00:01:31,170  -->  00:01:32,870
on the command line in this way.

18

00:01:33,420  -->  00:01:39,150
Here find out and coding is referred to as a system property of JVM and the option high Fundy is used

19

00:01:39,150  -->  00:01:40,840
to indicate that.

20

00:01:42,210  -->  00:01:47,910
But if you want to know what encoding your JVM uses you can use either of these two approaches.

21

00:01:47,910  -->  00:01:53,760
One is by invoking the get property method in the system class and you would have to pass a system property

22

00:01:53,760  -->  00:01:57,810
name find and encoding as a method argument.

23

00:01:57,810  -->  00:02:03,630
Second is the default Gobseck matter from the outset class which is from the Djala Dot and I package

24

00:02:03,630  -->  00:02:04,680
.

25

00:02:04,770  -->  00:02:06,540
You can check out the resources section.

26

00:02:06,570  -->  00:02:13,770
Better link is included that has more information on JVM system properties.

27

00:02:13,770  -->  00:02:19,620
Generally it is recommended not to use these classes as you have no control on the carpet and coding

28

00:02:20,540  -->  00:02:25,560
that is you're forced to use the default setting unless you use the command line option to change the

29

00:02:25,560  -->  00:02:28,590
setting so you will be platform dependent.

30

00:02:28,590  -->  00:02:35,090
If you are relying on this process so the preferred approach is to use these two classes.

31

00:02:35,210  -->  00:02:41,750
Input stream reader an output stream writer and they enable you to set the character encoding.

32

00:02:41,880  -->  00:02:47,910
Well if I later unfiled order were specific to files these are general purpose classes for doing the

33

00:02:47,910  -->  00:02:50,970
translations between byte and Carkner streams.

34

00:02:51,430  -->  00:02:56,940
And hence you can see that the input parameters of the constructors of the abstract input stream an

35

00:02:57,000  -->  00:03:04,020
output stream process that is not specific to file streams and hence can be passed any by stream objects

36

00:03:05,340  -->  00:03:08,110
so input stream reader will translate from bytes.

37

00:03:08,100  -->  00:03:13,590
Look at occurs while output stream writer would translate from characters to bytes.

38

00:03:14,190  -->  00:03:19,310
So the benefit of using these two classes is that they are general purpose on modeler.

39

00:03:19,350  -->  00:03:23,220
You can set the carpet encoding off your choice.

40

00:03:23,250  -->  00:03:28,060
There are also overloaded constrictors and you can check them out from the API.

41

00:03:28,920  -->  00:03:30,570
And here is an example.

42

00:03:30,570  -->  00:03:33,290
Here we want to read on benzyl for text file.

43

00:03:33,750  -->  00:03:38,910
So you must create a file input stream object and then we pass it as an argument to the input stream

44

00:03:38,910  -->  00:03:39,820
reader.

45

00:03:40,050  -->  00:03:44,500
Here the character encoding is specified as Eudy of eight.

46

00:03:45,510  -->  00:03:51,930
Since files are on Filemaker are specific to files they actually extend these classes as these classes

47

00:03:51,930  -->  00:03:53,930
are more generic.

48

00:03:54,000  -->  00:04:01,890
Also note is that I do here says Michie's and that's because these classes act as a bridge in the translation

49

00:04:01,890  -->  00:04:09,690
between bytes and characters and to achieve Dopp efficiency you would grab them with that buffered reader

50

00:04:09,780  -->  00:04:15,600
or buffer the writer class which provide additional buffering capability.

51

00:04:15,630  -->  00:04:19,100
And here are the constructors for buffered reader and buffer writer.

52

00:04:19,170  -->  00:04:22,730
They simply take out after streams reader and writers input.

53

00:04:23,040  -->  00:04:30,050
There are also overloaded versions which additionally take the buffer size of them but note that the

54

00:04:30,050  -->  00:04:33,820
default buffer size is around 8000 characters.

55

00:04:33,900  -->  00:04:41,370
That is it is a Carrere with the size of add on 8000 So these are similar to buffer input stream unbuffered

56

00:04:41,430  -->  00:04:49,190
output stream process which are chained to input stream an output stream instances So let's look at

57

00:04:49,190  -->  00:04:53,320
the Bufford reader on here and read methods written before Twitter.

58

00:04:53,550  -->  00:04:56,900
We all get it is because of too while discussing Rueter.

59

00:04:57,170  -->  00:05:02,320
However we now get the additional benefit of buffering just method here.

60

00:05:02,320  -->  00:05:03,930
Returns a single character.

61

00:05:04,190  -->  00:05:10,580
Well the second one reads a group of characters in the input katak it underlines that amount of character

62

00:05:10,580  -->  00:05:18,410
Selecta Turbin is something new and it is probably the most commonly used when reading Cocker's as a

63

00:05:18,410  -->  00:05:19,600
matter of or.

64

00:05:19,700  -->  00:05:24,530
It simply needs a single line of text unrepented as a string.

65

00:05:24,530  -->  00:05:30,230
So if the input character stream has spects with several lines then this method can read on each line

66

00:05:30,230  -->  00:05:31,180
separately.

67

00:05:31,580  -->  00:05:37,970
That is each invocation rodent's one single line and to identify lines.

68

00:05:38,270  -->  00:05:44,270
The matter looks what these lines up added or as a line feed a carriage return or a carriage return

69

00:05:44,270  -->  00:05:47,780
followed immediately by a line feed.

70

00:05:47,780  -->  00:05:53,960
Also just in case if you are not aware of this line separate or guns they happen to come from the typewriter

71

00:05:53,960  -->  00:06:00,800
times where carriage return would signal moving horizontally to the beginning of the same line one line

72

00:06:00,800  -->  00:06:04,140
feet would signal moving to the next line.

73

00:06:04,380  -->  00:06:10,040
So together they give you the effect of moving to the beginning of the next line.

74

00:06:10,300  -->  00:06:16,170
And here is an example of using a buffered reader for reading a text file which is named as go doc.

75

00:06:16,190  -->  00:06:17,530
The XTi.

76

00:06:17,570  -->  00:06:18,930
So the Cripe answers.

77

00:06:18,950  -->  00:06:20,490
We help buffer the reader.

78

00:06:20,600  -->  00:06:26,630
Just change to an input stream reader that is intention to file input stream which actually reached

79

00:06:26,630  -->  00:06:28,010
bytes from the file.

80

00:06:28,520  -->  00:06:31,370
So that's three objects chained together.

81

00:06:31,370  -->  00:06:37,790
So file input stream reef's bytes from the file while input stream leader translates those bytes into

82

00:06:37,790  -->  00:06:44,990
characters using UAP of 8 encoding and finally buffer reader would buffer those characters so that we

83

00:06:44,990  -->  00:06:47,380
get the performance benefit.

84

00:06:47,690  -->  00:06:53,810
Outside that block we are creating a string builder that is used for accumulating that text read from

85

00:06:53,810  -->  00:06:54,750
the file.

86

00:06:55,430  -->  00:07:01,610
So the while loop with each iteration reads a single line of text and we can see that it is using the

87

00:07:01,610  -->  00:07:09,170
read line method of the buffer reader object and with each iteration the line that is read is appended

88

00:07:09,170  -->  00:07:11,710
to the string builder object.

89

00:07:11,720  -->  00:07:18,290
Also notice that we are opening a new line explicitly and that's because Red Line method strips new

90

00:07:18,290  -->  00:07:19,620
lines.

91

00:07:19,670  -->  00:07:26,690
Finally once the entire text is read the relend method were written in and the loop terminated.

92

00:07:26,980  -->  00:07:31,550
And finally we can do it on the string containing the string builder.

93

00:07:31,560  -->  00:07:38,000
Also please make sure we use cringle for such cases as using Pless for concatenation would be very expensive

94

00:07:38,010  -->  00:07:38,620
.

95

00:07:38,940  -->  00:07:46,580
And if the file is very large then it may involve several concatenation operations on here as an example

96

00:07:46,630  -->  00:07:50,130
rendered rendering text from a console that has a command prompt.

97

00:07:50,370  -->  00:07:56,310
Only change here is in the Cripe parenthesis file input stream has been replaced with System Duggin

98

00:07:57,250  -->  00:08:04,430
in is basically a static variable within the system class and it represents an input stream object and

99

00:08:04,430  -->  00:08:09,830
we know that input stream reader is a general purpose bridge class and so it can work with any input

100

00:08:09,830  -->  00:08:15,920
stream object and the text that the user enters in the console will be captured by the read line method

101

00:08:15,920  -->  00:08:16,820
.

102

00:08:16,850  -->  00:08:23,000
So in this case the user will be repeatedly prompted for input on the news user and does the text start

103

00:08:23,630  -->  00:08:27,970
at which point the while loop will terminate.

104

00:08:28,130  -->  00:08:30,860
So we look at how we can read dextro efficiently.

105

00:08:30,860  -->  00:08:33,960
Now let's see how we can write extra efficiently.

106

00:08:34,280  -->  00:08:40,340
Here's an example of using a buffered writer for writing a text file unchaining is very similar to the

107

00:08:40,340  -->  00:08:43,470
read operation in the type parenthesis.

108

00:08:43,580  -->  00:08:49,550
We have a buffered writer that just change to an output stream loader that is in turn change the final

109

00:08:49,550  -->  00:08:56,770
output stream which writes bytes to the destination fine character encoding used for writing bytes is

110

00:08:56,790  -->  00:09:03,520
UTF aid here write methods and work on the buffer to write an object with some text pass doesn't boot

111

00:09:03,530  -->  00:09:04,060
.

112

00:09:04,730  -->  00:09:08,840
You can assume it has a string but it can also be a character in it.

113

00:09:08,930  -->  00:09:13,030
And it means that right is an overloaded method.

114

00:09:13,040  -->  00:09:17,930
In fact this notion of the right method is actually inherited from the writer class.

115

00:09:18,230  -->  00:09:22,510
You can take a look at the API of this class to get more understanding of it.

116

00:09:23,060  -->  00:09:28,280
So that's about it will get Halvard can't read dextro efficiently from an input stream.

117

00:09:28,370  -->  00:09:32,790
And also how we can write text efficiently to some output stream.

118

00:09:32,840  -->  00:09:37,850
Next we are willing to do one AACo the most good test all the stuff we learned in this lesson.

119

00:09:38,060  -->  00:09:38,470
Thank you
