Java Reference
In-Depth Information
conditions = “sunny”;
break;
case 1:
conditions = “rainy”;
break;
case 2:
conditions = “windy”;
break;
default:
conditions = “snowy”;
}
out.writeUTF(conditions);
}catch(IOException e)
{
e.printStackTrace();
}
}
}
You are probably wondering why the RandomWeather class does not use
the PipedOutputStream class, especially because this section is on pipes.
Well, pipes are going to be used, but I made a design decision when
writing the RandomWeather class. Because the RandomWeather class
chains the output stream with a DataOutputStream, it does not really care
if the low-level stream is a pipe, file, or other stream; therefore, I have
designed the RandomWeather class to work with any OutputStream. In
the following PipeDemo program, the actual OutputStream is going to be
a PipedOutputStream.
Similarly, the WeatherViewer class uses a DataInputStream to read the
data, and it is designed to read data from any InputStream. Since
PipedInputStream is a child of InputStream, the WeatherViewer can read
from pipes, which is the case in the PipeDemo program.
The RandomWeather thread is going to send the output to the following
WeatherViewer thread:
import java.io.*;
public class WeatherViewer extends Thread
{
private DataInputStream in;
public WeatherViewer(InputStream src)
{
in = new DataInputStream(src);
}
Search WWH ::




Custom Search