001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.blob; 018 019 import java.io.File; 020 import java.io.IOException; 021 import java.io.InputStream; 022 import java.net.URL; 023 024 import javax.jms.JMSException; 025 026 import org.apache.activemq.command.ActiveMQBlobMessage; 027 028 /** 029 * A helper class to represent a required upload of a BLOB to some remote URL 030 * 031 * 032 */ 033 public class BlobUploader { 034 035 private BlobTransferPolicy blobTransferPolicy; 036 private File file; 037 private InputStream in; 038 039 public BlobUploader(BlobTransferPolicy blobTransferPolicy, InputStream in) { 040 this.blobTransferPolicy = blobTransferPolicy; 041 this.in = in; 042 } 043 044 public BlobUploader(BlobTransferPolicy blobTransferPolicy, File file) { 045 this.blobTransferPolicy = blobTransferPolicy; 046 this.file = file; 047 } 048 049 public URL upload(ActiveMQBlobMessage message) throws JMSException, IOException { 050 if (file != null) { 051 return getStrategy().uploadFile(message, file); 052 } else { 053 return getStrategy().uploadStream(message, in); 054 } 055 } 056 057 public BlobTransferPolicy getBlobTransferPolicy() { 058 return blobTransferPolicy; 059 } 060 061 public BlobUploadStrategy getStrategy() { 062 return getBlobTransferPolicy().getUploadStrategy(); 063 } 064 }