All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openstack4j.model.common.payloads.URLPayload Maven / Gradle / Ivy

package org.openstack4j.model.common.payloads;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.openstack4j.model.common.Payload;

import com.google.common.base.Throwables;

/**
 * URL based Payload
 * 
 * @author Jeremy Unruh
 */
public class URLPayload implements Payload {

	URL url;
	InputStream is;
	
	public URLPayload(URL url) {
		this.url = url;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void close() throws IOException {
		if (is != null)
			is.close();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public InputStream open() {
		try {
			is = url.openStream();
			return is;
		}
		catch (IOException e) {
			throw Throwables.propagate(e);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void closeQuietly() {
		try
		{
			if (is != null)
				is.close();
		}
		catch (IOException e) { }
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public URL getRaw() {
		return url;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy