Skip to content

Commit e8d38f7

Browse files
committed
Updated readme
1 parent 3adad43 commit e8d38f7

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

README.md

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ Input data can come from a variety of sources. Sometimes it comes from standard
1212

1313
// Reading from standard input
1414
InputReader stdinReader = new InputReader(); // Defaults to reading from System.in
15-
String line = stdinReader.readLine();
15+
String line = stdinReader.nextLine();
1616

1717
// Reading from a file
1818
FileInputStream fileStream = new FileInputStream("/path/to/the/file");
1919
InputReader fileReader = new InputReader(fileStream);
20-
String entireFileContents = fileReader.readAll();
20+
String line = fileReader.nextLine();
2121

2222
// Reading from Web Socket
2323
Socket socket = new Socket("Some Machine", port);
2424
InputReader socketReader = new InputReader(socket.getInputStream());
25-
String data = socketReader.readStr(); // Read first string
25+
String data = socketReader.nextStr(); // Read first string
2626

2727
```
2828

@@ -65,53 +65,53 @@ public class InputReaderUsageExample {
6565

6666
**ALL methods in the InputReader class must be caught or thrown** because they throw an java.io.IOException when something bad happens such as trying to read a byte value from an empty stream. See [here](https://github.com/williamfiset/FastJavaIO#examples) for detailed examples of how to use the methods outlined below.
6767

68-
### .byteInt()
68+
### .nextByte()
6969
Reads a signed 8 bit integer from the input stream.
7070
``` java
7171
InputReader in = new InputReader();
72-
byte bytevalue = in.readByte();
72+
byte bytevalue = in.nextByte();
7373
```
7474

75-
### .readInt()
75+
### .nextInt()
7676
Reads a signed 32 bit integer from the input stream.
7777
``` java
7878
InputReader in = new InputReader();
79-
int intvalue = in.readInt();
79+
int intValue = in.nextInt();
8080
```
8181

82-
### .readLong()
82+
### .nextLong()
8383
Reads a signed 64 bit integer from the input stream.
8484
``` java
8585
InputReader in = new InputReader();
86-
long longvalue = in.readLong();
86+
long longvalue = in.nextLong();
8787
```
8888

89-
### .readDouble()
89+
### .nextDouble()
9090
Reads a signed double from the input stream.
9191
``` java
9292
InputReader in = new InputReader();
93-
double doublevalue = in.readDouble();
93+
double doublevalue = in.nextDouble();
9494
```
9595

96-
### .readFastDouble()
97-
Reads a double value ~3x times faster from the input stream than the .readDouble() method, but at the cost of accuracy. This method can only read doubles with at most 21 digits after the decimal point. Furthermore, the value being read may have an error of at most ~5*10^-16 (obtained from empirical tests) from its true value due to finite floating point number arithmetic (adding, multiplication) used to perform the quick calculation.
96+
### .nextDoubleFast()
97+
Reads a double value ~3x times faster from the input stream than the .nextDouble() method, but at the cost of accuracy. This method can only read doubles with at most 21 digits after the decimal point. Furthermore, the value being read may have an error of at most ~5*10^-16 (obtained from empirical tests) from its true value due to finite floating point number arithmetic (adding, multiplication) used to perform the quick calculation.
9898
``` java
9999
InputReader in = new InputReader();
100-
double doublevalue = in.readDoubleFast();
100+
double doublevalue = in.nextDoubleFast();
101101
```
102-
### .readStr()
102+
### .nextStr()
103103
Reads a string of characters from the input stream. The delimiter separating a string of characters is set to be
104104
any ASCII value <= 32 meaning any spaces, new lines, EOF characters, tabs... all of which do not count as being part of the string. If the input stream is empty null is returned.
105105
``` java
106106
InputReader in = new InputReader();
107-
String str = in.readStr();
107+
String str = in.nextStr();
108108
```
109109

110-
### .readLine()
111-
Reads a line of characters from the input stream until a new line character is reached. The .readLine() method includes spaces found in the input stream. If the input stream is empty a null value is returned to indicate so.
110+
### .nextLine()
111+
Reads a line of characters from the input stream until a new line character is reached. The .nextLine() method includes spaces found in the input stream. If the input stream is empty a null value is returned to indicate so.
112112
``` java
113113
InputReader in = new InputReader();
114-
String line = in.readLine();
114+
String line = in.nextLine();
115115
```
116116

117117
## Examples
@@ -123,94 +123,94 @@ String line = in.readLine();
123123
" 123 3.141592 abcdef the quick brown fox\n jumps \nover\n\n the lazy dog"
124124

125125
InputReader in = new InputReader();
126-
int intvalue = in.readInt(); // '123'
127-
double dblvalue = in.readDouble(); // '3.141592'
128-
String str = in.readStr(); // 'abcdef'
129-
String str2 = in.readStr(); // 'the'
130-
String line = in.readLine(); // 'quick brown fox'
131-
String line1 = in.readLine(); // ' jumps '
132-
String line2 = in.readLine(); // 'over'
133-
String line3 = in.readLine(); // ''
134-
String line4 = in.readLine(); // ' the lazy dog'
135-
String line5 = in.readLine(); // null
136-
```
137-
138-
#### .readByte() examples
126+
int intvalue = in.nextInt(); // '123'
127+
double dblvalue = in.nextDouble(); // '3.141592'
128+
String str = in.nextStr(); // 'abcdef'
129+
String str2 = in.nextStr(); // 'the'
130+
String line = in.nextLine(); // 'quick brown fox'
131+
String line1 = in.nextLine(); // ' jumps '
132+
String line2 = in.nextLine(); // 'over'
133+
String line3 = in.nextLine(); // ''
134+
String line4 = in.nextLine(); // ' the lazy dog'
135+
String line5 = in.nextLine(); // null
136+
```
137+
138+
#### .nextByte() examples
139139
``` java
140140
// Suppose standard input stream contains the following byte values we want to read:
141141
"-128 127 -1 -0 0 1 3454"
142142
// ^ NOTE: This does NOT fit in a signed byte!
143143

144144
InputReader in = new InputReader();
145-
byte b1 = in.readByte(); // -128
146-
byte b2 = in.readByte(); // 127
147-
byte b3 = in.readByte(); // -1
148-
byte b4 = in.readByte(); // 0
149-
byte b5 = in.readByte(); // 0
150-
byte b6 = in.readByte(); // 1
151-
byte b7 = in.readByte(); // 126, this byte value overflowed! No safety check
145+
byte b1 = in.nextByte(); // -128
146+
byte b2 = in.nextByte(); // 127
147+
byte b3 = in.nextByte(); // -1
148+
byte b4 = in.nextByte(); // 0
149+
byte b5 = in.nextByte(); // 0
150+
byte b6 = in.nextByte(); // 1
151+
byte b7 = in.nextByte(); // 126, this byte value overflowed! No safety check
152152
// gets done for this. It is assumed the user knows
153153
// the range of the values they're reading from the stream.
154-
byte b8 = in.readByte(); // Nothing left in stream so an error is thrown
154+
byte b8 = in.nextByte(); // Nothing left in stream so an error is thrown
155155
```
156156

157-
#### .readInt() examples
157+
#### .nextInt() examples
158158
``` java
159159
// Suppose standard input stream contains the following byte values we want to read:
160160
"2147483647 -2147483648 34545 -1 -0 0 1 999999999999"
161161
// ^ NOTE: This does NOT fit in a signed int!
162162

163163
InputReader in = new InputReader();
164-
int integer1 = in.readInt(); // 2147483647
165-
int integer2 = in.readInt(); // -2147483648
166-
int integer3 = in.readInt(); // 34545
167-
int integer4 = in.readInt(); // -1
168-
int integer5 = in.readInt(); // 0
169-
int integer6 = in.readInt(); // 0
170-
int integer7 = in.readInt(); // 1
171-
int integer8 = in.readInt(); // -727379969, this int value overflowed! No safety check
164+
int integer1 = in.nextInt(); // 2147483647
165+
int integer2 = in.nextInt(); // -2147483648
166+
int integer3 = in.nextInt(); // 34545
167+
int integer4 = in.nextInt(); // -1
168+
int integer5 = in.nextInt(); // 0
169+
int integer6 = in.nextInt(); // 0
170+
int integer7 = in.nextInt(); // 1
171+
int integer8 = in.nextInt(); // -727379969, this int value overflowed! No safety check
172172
// gets done for this.It is assumed the user knows the
173173
// range of the values they're reading from the stream
174-
int integer9 = in.readInt(); // Nothing left in stream so an error is thrown
174+
int integer9 = in.nextInt(); // Nothing left in stream so an error is thrown
175175
```
176176

177-
#### .readStr() example
177+
#### .nextStr() example
178178

179179
``` java
180180
// Suppose standard input stream contains the following string and we want
181181
// to read the individual fruits names contained inside this sentence. We
182-
// Can easily do this by using the .readStr()
182+
// Can easily do this by using the .nextStr()
183183
"Apple banana orange\n\n KiWi dragonFRuIt \n \n WatERmeOn \n\n\nPEARS\n\n "
184184

185185
InputReader in = new InputReader();
186-
String s1 = in.readStr(); // "Apple"
187-
String s2 = in.readStr(); // "banana"
188-
String s3 = in.readStr(); // "orange"
189-
String s4 = in.readStr(); // "KiWi"
190-
String s5 = in.readStr(); // "dragonFRuIt"
191-
String s6 = in.readStr(); // "WatERmeOn"
192-
String s7 = in.readStr(); // "PEARS"
193-
String s8 = in.readStr(); // null - Returns null when no more strings are found in the input stream
186+
String s1 = in.nextStr(); // "Apple"
187+
String s2 = in.nextStr(); // "banana"
188+
String s3 = in.nextStr(); // "orange"
189+
String s4 = in.nextStr(); // "KiWi"
190+
String s5 = in.nextStr(); // "dragonFRuIt"
191+
String s6 = in.nextStr(); // "WatERmeOn"
192+
String s7 = in.nextStr(); // "PEARS"
193+
String s8 = in.nextStr(); // null - Returns null when no more strings are found in the input stream
194194
```
195195

196-
#### .readLine() example
196+
#### .nextLine() example
197197

198198
``` java
199199
// Suppose standard input stream contains the following string and we want
200-
// to read it line by line. We can do this using the .readLine() method
200+
// to read it line by line. We can do this using the .nextLine() method
201201
"Apple banana orange\n\n KiWi dragonFRuIt \n \n WatERmelOn \n\n\nPEARS\n\n "
202202

203203
InputReader in = new InputReader();
204-
String s1 = in.readLine(); // "Apple banana orange"
205-
String s2 = in.readLine(); // ""
206-
String s3 = in.readLine(); // " KiWi dragonFRuIt "
207-
String s4 = in.readLine(); // " "
208-
String s5 = in.readLine(); // " WatERmelOn "
209-
String s6 = in.readLine(); // ""
210-
String s7 = in.readLine(); // ""
211-
String s8 = in.readLine(); // "PEARS"
212-
String s9 = in.readLine(); // ""
213-
String s10 = in.readLine(); // " "
214-
String s11 = in.readLine(); // null - No more lines left so null is returned
204+
String s1 = in.nextLine(); // "Apple banana orange"
205+
String s2 = in.nextLine(); // ""
206+
String s3 = in.nextLine(); // " KiWi dragonFRuIt "
207+
String s4 = in.nextLine(); // " "
208+
String s5 = in.nextLine(); // " WatERmelOn "
209+
String s6 = in.nextLine(); // ""
210+
String s7 = in.nextLine(); // ""
211+
String s8 = in.nextLine(); // "PEARS"
212+
String s9 = in.nextLine(); // ""
213+
String s10 = in.nextLine(); // " "
214+
String s11 = in.nextLine(); // null - No more lines left so null is returned
215215
```
216216

0 commit comments

Comments
 (0)