Java Reference
In-Depth Information
// Otherwise, start building a stringbuffer
StringBuffer sb
=
new
new
StringBuffer
(
s
);
// Read as many continued lines as there are, if any.
while
while
(
true
true
) {
String nextPart
=
readPhysicalLine
();
iif
(
nextPart
==
null
null
) {
// Egad! EOF within continued line.
// Return what we have so far.
return
return
sb
.
toString
();
}
// If the next line begins with space, it's continuation
iif
(
nextPart
.
length
() >
0
&&
Character
.
isWhitespace
(
nextPart
.
charAt
(
0
))) {
sb
.
append
(
nextPart
);
// and add line.
}
else
else
{
// else we just read too far, so put in "pushback" holder
prevLine
=
nextPart
;
break
break
;
}
}
return
return
sb
.
toString
();
// return what's left
}
Reading/Writing Binary Data
Problem
You need to read or write binary data, as opposed to text.
Solution
Use a
DataInputStream
or
DataOutputStream
.
Discussion
The
Stream
classes have been in Java since the beginning of time and are optimal for read-
ing and writing bytes rather than characters. The “data” layer over them, comprising
DataInputStream
and
DataOutputStream
, is configured for reading and writing binary val-