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

aQute.bnd.osgi.AbstractResource Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
package aQute.bnd.osgi;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public abstract class AbstractResource implements Resource {
	String	extra;
	byte[]	calculated;
	long	lastModified;

	protected AbstractResource(long modified) {
		lastModified = modified;
	}

	public String getExtra() {
		return extra;
	}

	public long lastModified() {
		return lastModified;
	}

	public InputStream openInputStream() throws IOException {
		return new ByteArrayInputStream(getLocalBytes());
	}

	private byte[] getLocalBytes() throws IOException {
		try {
			if (calculated != null)
				return calculated;

			return calculated = getBytes();
		} catch (IOException e) {
			throw e;
		} catch (Exception e) {
			IOException ee = new IOException("Opening resource");
			ee.initCause(e);
			throw ee;
		}
	}

	public void setExtra(String extra) {
		this.extra = extra;
	}

	public void write(OutputStream out) throws IOException {
		out.write(getLocalBytes());
	}

	abstract protected byte[] getBytes() throws Exception;

	public long size() throws IOException {
		return getLocalBytes().length;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy