Java Reference
In-Depth Information
} else
{
if (hadLF)
os.write(lineSep);
else
hadLF = true;
}
} else
{
If the character was a carriage return, then we check to see if there already was a carriage
return, then we write a line separator. If the character was not a carriage return, then we do
not write a line separator. Line feed is handled the same way. This causes each combination of
line ending characters to be written to the operating system's standard for line breaks.
If the character was not a line break, then it is handled with the following lines of code.
if (inLineBreak)
{
os.write(lineSep);
hadCR = hadLF = inLineBreak = false;
}
os.write(ch);
}
If we were in a line break, then an operating system line break is written; otherwise, we
write the character to the output stream.
Finally, we check to see if the character read was -1. If the character read was -1, this
indicates there are no more characters to read.
} while (ch != -1);
The algorithm is useful because it allows you to adjust incoming text to exactly how the
operating system would like it to be represented.
Summary
In this chapter you learned how to perform basic HTTP operations with Java. You saw
how you can access a URL and download the contents of that URL.
Java contains a URL class. This class allows you to open connections to a URL. By calling
the openStream function on a URL object, you are given an InputStream object
that you can use to access the contents of the URL. Once you have an InputStream,
you can read from the URL essentially the same as if you were reading from a file.
Search WWH ::




Custom Search