// accept() timeout: restart loop to check
// availability flag.
continue;
} catch (SocketException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage5"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage5"), e));
// throw new RuntimeException(e.getMessage());
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage6"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage6"), e));
}
// Get the socket input and output streams and wrap object
// input and output streams around them, respectively.
InputStream in = null;
OutputStream out = null;
ObjectInputStream objectIn = null;
ObjectOutputStream objectOut = null;
try {
in = socket.getInputStream();
out = socket.getOutputStream();
objectIn = new ObjectInputStream(in);
objectOut = new ObjectOutputStream(out);
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage7"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage7"), e));
// throw new RuntimeException(e.getMessage());
}
// Read the Object from the object stream.
Object obj = null;
try {
obj = objectIn.readObject();
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage8"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage8"), e));
// throw new RuntimeException(e.getMessage());
} catch (ClassNotFoundException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage9"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage9"), e));
}
// Switch according to object class; ignore unsupported types.
if (obj instanceof String &&
((String)obj).equals(CLOSE_MESSAGE)) {
try {
objectOut.writeObject(CLOSE_ACK);
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString(
"SerializableRenderedImage17"),
new ImagingException(JaiI18N.getString(
"SerializableRenderedImage17"), e));
// throw new RuntimeException(e.getMessage());
}
// Decrement the remote reference count.
decrementRemoteReferenceCount(this);
} else if (obj instanceof Rectangle) {
// Retrieve the Raster of data from the source image.
Raster raster = source.getData((Rectangle)obj);
// Write the serializable Raster to the
// object output stream.
if (useTileCodec) {
byte[] buf = encodeRasterToByteArray(raster);
try {
objectOut.writeObject(buf);
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage10"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage10"), e));
// throw new RuntimeException(e.getMessage());
}
}
else {
try {
objectOut.writeObject(SerializerFactory.getState(raster, null));
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage10"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage10"), e));
// throw new RuntimeException(e.getMessage());
}
}
}
// XXX Concerning serialization of properties, perhaps the
// best approach would be to serialize all the properties up
// front if a deep copy were being made but otherwise to wait
// until the first property request was received before
// transmitting any property values. When the first request
// was made, all property values would be transmitted and then
// cached. Up front serialization might in both cases include
// transmitting all names. If property serialization were
// deferred, then a new message branch would be added here
// to retrieve the properties which could be obtained as
// a PropertySourceImpl. If properties are also served up
// then this inner class should be renamed "DataServer".
// Close the various streams and the socket itself.
try {
objectOut.flush();
socket.shutdownOutput();
socket.shutdownInput();
objectOut.close();
objectIn.close();
out.close();
in.close();
socket.close();
} catch (IOException e) {
sendExceptionToListener(JaiI18N.getString("SerializableRenderedImage10"),
new ImagingException(JaiI18N.getString("SerializableRenderedImage10"), e));
// throw new RuntimeException(e.getMessage());
}
}
}