1 17 package org.apache.activemq.blob; 18 19 import org.apache.activemq.command.ActiveMQBlobMessage; 20 21 import javax.jms.JMSException ; 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.net.URL ; 26 27 32 public class BlobUploader { 33 34 private BlobTransferPolicy blobTransferPolicy; 35 private File file; 36 private InputStream in; 37 38 39 public BlobUploader(BlobTransferPolicy blobTransferPolicy, InputStream in) { 40 this.blobTransferPolicy = blobTransferPolicy; 41 this.in = in; 42 } 43 44 public BlobUploader(BlobTransferPolicy blobTransferPolicy, File file) { 45 this.blobTransferPolicy = blobTransferPolicy; 46 this.file = file; 47 } 48 49 public URL upload(ActiveMQBlobMessage message) throws JMSException , IOException { 50 if (file != null) { 51 return getStrategy().uploadFile(message, file); 52 } 53 else { 54 return getStrategy().uploadStream(message, in); 55 } 56 } 57 58 59 public BlobTransferPolicy getBlobTransferPolicy() { 60 return blobTransferPolicy; 61 } 62 63 public BlobUploadStrategy getStrategy() { 64 return getBlobTransferPolicy().getUploadStrategy(); 65 } 66 } 67 | Popular Tags |