Hi,
I stumbled about the BinaryFileMarshaler while looking for a problem I had.
This one has 2 parameters to set:
- contentType
- attachment
Now the question. Why should somebody specify a content type? Isn't it
better to use the FileDataSource to put the file as attachment into the
message?
Second is why is there a configuration possibility for naming the
attachment? Is this really needed? I mean 99% would use the file name as
this or not?
maybe we could also change it to something like this as a middle solution:
/**
* A FileMarshaler that converts the given input stream into a binary
* attachment.
*
* @org.apache.xbean.XBean
*
* @author Guillaume Nodet
* @since 3.0
*/
public class BinaryFileMarshaler extends DefaultFileMarshaler {
private String attachment = FILE_CONTENT;
private String contentType;
public String getAttachment() {
return attachment;
}
public void setAttachment(String attachment) {
this.attachment = attachment;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public void readMessage(MessageExchange exchange, NormalizedMessage
message,
InputStream in, String path) throws IOException,
JBIException {
File file = new File(path);
FileDataSource fds = new FileDataSource(file);
DataSource ds = new StreamDataSource(in, contentType != null ?
contentType : fds.getContentType(), file.getName());
DataHandler handler = new DataHandler(ds);
message.addAttachment(attachment, handler);
message.setProperty(FILE_NAME_PROPERTY, file.getName());
message.setProperty(FILE_PATH_PROPERTY, path);
}
public void writeMessage(MessageExchange exchange, NormalizedMessage
message,
OutputStream out, String path) throws
IOException, JBIException {
DataHandler handler = message.getAttachment(attachment);
if (handler == null) {
throw new MessagingException("Could not find attachment: "
+ attachment);
}
InputStream is = handler.getInputStream();
FileUtil.copyInputStream(is, out);
}
}
Shouldn't it be possible to use only FileDataSource or where is the sense in
doing it with StreamDataSource?
Regards,
Lars
--
View this message in context:
http://www.nabble.com/Question-regarding-the-BinaryFileMarshaler-tp15854291s12049p15854291.html
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.