forked from j62/ctbrec
41 lines
767 B
Java
41 lines
767 B
Java
package org.taktik.mpegts.sources;
|
|
|
|
import org.taktik.mpegts.MTSPacket;
|
|
|
|
public abstract class AbstractMTSSource implements MTSSource {
|
|
private boolean closed;
|
|
|
|
@Override
|
|
public final MTSPacket nextPacket() throws Exception {
|
|
if (isClosed()) {
|
|
throw new IllegalStateException("Source is closed");
|
|
}
|
|
return nextPacketInternal();
|
|
}
|
|
|
|
@Override
|
|
public final void close() throws Exception {
|
|
try {
|
|
closeInternal();
|
|
} finally {
|
|
closed = true;
|
|
}
|
|
}
|
|
|
|
protected boolean isClosed() {
|
|
return closed;
|
|
}
|
|
|
|
protected abstract MTSPacket nextPacketInternal() throws Exception;
|
|
protected abstract void closeInternal() throws Exception;
|
|
|
|
|
|
@Override
|
|
protected void finalize() throws Throwable {
|
|
if (!closed) {
|
|
close();
|
|
}
|
|
super.finalize();
|
|
}
|
|
}
|