I want to take the data from a BytesMessage and pass is to a class that will de-serialize it. I'm running some tests to see if using Hessan for serialization is any better than Java Serialization.
The Hessan classes take an InputStream to read from. The BytesMessage has no getInputStream() method so I thought I'd write a wrapper around it.
Here is an idea:
public class BytesMessageReader extends InputStream {
private BytesMessage message;
public BytesMessageReader(BytesMessage message) {
this.message = message;
}
public int read() throws IOException {
try {
return (int)message.readByte();
} catch (JMSException e) {
throw new IOException("Error reading bytes message: " + e.getMessage());
}
}
public int read(byte b[]) throws IOException {
try {
return message.readBytes(b);
} catch (JMSException e) {
throw new IOException("Error reading bytes message: " + e.getMessage());
}
}
}
Does this seem like a good idea? Is there some other way I am missing of getting at the bytes without making a complete copy?