Win a copy of Terraform in Action this week in the Cloud forum!

nk kumar

Greenhorn
+ Follow
since Sep 23, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by nk kumar

Thanks Stephan and Kurt for your amazing code samples, now I am able to see clear difference between the two.

11 years ago
Make sure input.txt contains only text ABC




11 years ago
Guru' s please weigh in...
11 years ago
Stephan, looks like you are partially correct or may be I am missing something here. So to validate your point I placed a print statement in the while loop to figure out how many times the loop was executed, to my surprise found some interesting behavior below -

with ByteStream -

1. Placed only 3 characters (ABC) in the input file and saved the txt with encoding UTF-8, output to console was 239, 187, 191, 65, 66, 67 (was expecting your answer 0, 65, 0, 66, 0, 67)

2. Saved the same input txt file as above with encoding - unicode, output was 255, 254, 65, 0, 66, 0, 67, 0

3. with encoding Unicode Big Endian, output was 254, 255, 0, 65, 0, 66, 0, 67

4. with Ansi encoding, output was 65, 66, 67


with CharacterStream -

1. UTF-8, output was 239, 187, 191, 65, 66, 67

2. Unicode, output was 255, 254, 65, 0, 66, 0, 67, 0

3. Big Endian, output was 254, 255, 0, 65, 0, 66, 0, 67

4. Ansi, output was 65, 66, 67
11 years ago

Stephan van Hulst wrote:It will, the only difference is that the loop in CopyBytes will run twice as much, because instead of reading a character at a time, it reads two bytes.



Thanks Stephan, but I am unable to see why CopyBytes, while loop will run twice as much. For example if the input file contains 3 characters CopyBytes and CopyCharacters while loop would run 4 times (3 times for 3 characters and 1 for end of file).
11 years ago
I am trying to understand difference between byte and character streams, and was reading

CopyBytes @ http://download.oracle.com/javase/tutorial/essential/io/bytestreams.html
CopyCharacters @ http://download.oracle.com/javase/tutorial/essential/io/charstreams.html

the difference between two mentioned was "CopyCharacters, int variable holds a character value in its last 16 bits; in CopyBytes, the int variable holds a byte value in its last 8 bits"

will I be right in assuming if a character in input file (xanadu.txt) is represented with an integer value >255 (more than 8 bits) will not be written to the output file (outagain.txt) if FileInputStream class in CopyBytes class is used.
11 years ago