From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch14.io;
02
03 importimport means to make the classes and/or packages available in this program java.io.FilterReader;
04 importimport means to make the classes and/or packages available in this program java.io.IOException;
05 importimport means to make the classes and/or packages available in this program java.io.Reader;
06
07 /**
08 * This classclass is a group of fields and methods used for making objects wraps a {open braces start code blocks and must be matched with a close brace@link Reader}close braces end code blocks and must match an earlier open brace and reads it whilewhile is a looping structure for executing code repeatedly eliminating
09 * curly braces.Modeled after the SourceReader classclass is a group of fields and methods used for making objects presented in
10 * Harold, _Java I/O, 2E_
11 */
12 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects NoCurlyFilterReader
13 extendsextends means to customize or extend the functionality of a class FilterReader {open braces start code blocks and must be matched with a close brace
14 /** state flag; have we already seen the end of the stream? */
15 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false endOfStream =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
16
17 /**
18 * New {open braces start code blocks and must be matched with a close brace@link NoCurlyFilterReader}close braces end code blocks and must match an earlier open brace wrapped around the {open braces start code blocks and must be matched with a close brace@link Reader}close braces end code blocks and must match an earlier open brace.
19 *
20 * @paramthis is the Javadoc tag for documenting the purpose of parameters in the {open braces start code blocks and must be matched with a close brace@link Reader}close braces end code blocks and must match an earlier open brace where thisthis means the current object (the implicit parameter) reader gets characters.
21 */
22 publicpublic is used to indicate unrestricted access (any other class can have access) NoCurlyFilterReader(Reader in) {open braces start code blocks and must be matched with a close brace
23 super(in);
24 thisthis means the current object (the implicit parameter).endOfStream =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
25 }close braces end code blocks and must match an earlier open brace
26
27 /**
28 * Read one character whilewhile is a looping structure for executing code repeatedly replacing '{open braces start code blocks and must be matched with a close brace' and ' }close braces end code blocks and must match an earlier open brace' with '|this performs a bit-wise or (not the same as boolean or which is ||)'
29 *
30 * @returnnull the character read
31 */
32 @Override
33 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer read() throwsthrows means that the method does not handle the given types of exceptions that may occur IOException {open braces start code blocks and must be matched with a close brace
34 intint is the type for whole numbers and it is short for integer ch;// the character to return
35
36 ch =this assignment operator makes the left side equal to the right side in.read();
37 ifif executes the next statement only if the condition in parenthesis evaluates to true ((ch ==this is the comparison operator which evaluates to true if both sides are the same '{open braces start code blocks and must be matched with a close brace') ||this is boolean or, meaning if either or both are true then the result is true (ch ==this is the comparison operator which evaluates to true if both sides are the same '}close braces end code blocks and must match an earlier open brace')) {open braces start code blocks and must be matched with a close brace
38 ch =this assignment operator makes the left side equal to the right side '|this performs a bit-wise or (not the same as boolean or which is ||)';
39 }close braces end code blocks and must match an earlier open brace
40 returnreturn means to provide the result of the method and/or cease execution of the method immediately ch;
41 }close braces end code blocks and must match an earlier open brace
42
43 /**
44 * Fill charchar is the type for a single letter or symbol and it is short for character array buffer with {open braces start code blocks and must be matched with a close brace@link #read()}close braces end code blocks and must match an earlier open brace (DRY!this is the not operator, which changes true to false and false to true) forfor is a looping structure for repeatedly executing a block of code charchar is the type for a single letter or symbol and it is short for character map
45 *
46 * @paramthis is the Javadoc tag for documenting the purpose of parameters text character buffer where characters are to be placed
47 * @paramthis is the Javadoc tag for documenting the purpose of parameters offset offset into text to begin writing
48 * @paramthis is the Javadoc tag for documenting the purpose of parameters length number of characters desired
49 *
50 * @returnnull number of charchar is the type for a single letter or symbol and it is short for character read or -1 ifif executes the next statement only if the condition in parenthesis evaluates to true past end of stream
51 */
52 @Override
53 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer read(charchar is the type for a single letter or symbol and it is short for character[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays text, intint is the type for whole numbers and it is short for integer offset, intint is the type for whole numbers and it is short for integer length)
54 throwsthrows means that the method does not handle the given types of exceptions that may occur IOException {open braces start code blocks and must be matched with a close brace
55 ifif executes the next statement only if the condition in parenthesis evaluates to true (endOfStream) {open braces start code blocks and must be matched with a close brace
56 returnreturn means to provide the result of the method and/or cease execution of the method immediately -1;// end already reached
57 }close braces end code blocks and must match an earlier open brace
58
59 intint is the type for whole numbers and it is short for integer charCount =this assignment operator makes the left side equal to the right side 0;
60 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side offset; i < (offset +adds two numbers together or concatenates Strings together length); i++this is the increment operator, which increases the variable by 1) {open braces start code blocks and must be matched with a close brace
61 intint is the type for whole numbers and it is short for integer temp =this assignment operator makes the left side equal to the right side thisthis means the current object (the implicit parameter).read();
62 ifif executes the next statement only if the condition in parenthesis evaluates to true (temp ==this is the comparison operator which evaluates to true if both sides are the same -1) {open braces start code blocks and must be matched with a close brace
63 endOfStream =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
64 breakbreak terminates the loop immediately;
65 }close braces end code blocks and must match an earlier open brace
66 text[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays =this assignment operator makes the left side equal to the right side (charchar is the type for a single letter or symbol and it is short for character) temp;
67 charCount++this is the increment operator, which increases the variable by 1;
68 }close braces end code blocks and must match an earlier open brace
69 returnreturn means to provide the result of the method and/or cease execution of the method immediately charCount;
70 }close braces end code blocks and must match an earlier open brace
71
72 /**
73 * Skip over the given number of characters.
74 *
75 * @paramthis is the Javadoc tag for documenting the purpose of parameters n number of characters to skip over
76 *
77 * @returnnull number of charchar is the type for a single letter or symbol and it is short for character skipped or -1 ifif executes the next statement only if the condition in parenthesis evaluates to true past end of stream
78 */
79 @Override
80 publicpublic is used to indicate unrestricted access (any other class can have access) longlong is the type for whole numbers (they have a larger range than int) skip(longlong is the type for whole numbers (they have a larger range than int) n) throwsthrows means that the method does not handle the given types of exceptions that may occur IOException {open braces start code blocks and must be matched with a close brace
81 charchar is the type for a single letter or symbol and it is short for character[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays chArray =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor charchar is the type for a single letter or symbol and it is short for character[brackets are typically used to declare, initialize and index (indicate which element of) arrays(intint is the type for whole numbers and it is short for integer) n]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
82 intint is the type for whole numbers and it is short for integer charCountSkipped =this assignment operator makes the left side equal to the right side thisthis means the current object (the implicit parameter).read(chArray);
83 returnreturn means to provide the result of the method and/or cease execution of the method immediately charCountSkipped;
84 }close braces end code blocks and must match an earlier open brace
85 }close braces end code blocks and must match an earlier open brace
86
87 //Uploaded on Mon Mar 29 21:40:34 EDT 2010
|
Download/View scg/ch14/io/NoCurlyFilterReader.java