Java Reference
In-Depth Information
/**
* Download a text file, which means convert the line
* ending characters to the correct type for the
* operating system that is being used.
*
* @param is The input stream, which is the URL.
* @param os The output stream, a local file.
* @throws IOException Exception while downloading.
*/
private void downloadText(InputStream is, OutputStream os)
throws IOException
{
byte lineSep[] =
System.getProperty("line.separator").getBytes();
int ch = 0;
boolean inLineBreak = false;
boolean hadLF = false;
boolean hadCR = false;
do
{
ch = is.read();
if (ch != -1)
{
if ((ch == '\r') || (ch == '\n'))
{
inLineBreak = true;
if (ch == '\r')
{
if (hadCR)
os.write(lineSep);
else
hadCR = true;
} else
{
if (hadLF)
os.write(lineSep);
else
hadLF = true;
}
} else
{
if (inLineBreak)
{
os.write(lineSep);
hadCR = hadLF = inLineBreak = false;
Search WWH ::




Custom Search