Java Reference
In-Depth Information
L ISTING 6.3
Continued
6
try {
// Set this to false in order to ignore caching
connection.setUseCaches(false);
// Set the content-type of the request
// application/octet-stream is used when writing
// application specific byte size data
connection.setRequestProperty(“CONTENT_TYPE”,
“application/octet-stream”);
// Set these vales to true to use the same connection
// for both input and output
connection.setDoInput(true);
connection.setDoOutput(true);
// Create the ObjectOutputStream passing it the
// OutputStream object.
ObjectOutputStream os =
new ObjectOutputStream(connection.getOutputStream());
// Write the StudentList to the ObjectOutputStream
System.err.println(“Writing StudentList Object.”);
os.writeObject(value);
os.flush();
os.close();
}
catch (IOException e) {
System.err.println(e.getMessage());
}
}
public StudentList readStudentList(URLConnection connection)
{
StudentList list = null;
try {
// Create the ObjectInputStream passing it the
// InputStream object from the URLConnection
ObjectInputStream is = new ObjectInputStream(
connection.getInputStream());
 
Search WWH ::




Custom Search