nl.vpro.api.rs.subtitles.AbstractIteratorWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of subtitles-domain Show documentation
Show all versions of subtitles-domain Show documentation
Subtitles are related to media, but are implemented completely parallel. Classes to contain, parse, and assemble subtitle objects are here.
The newest version!
package nl.vpro.api.rs.subtitles;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Iterator;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;
import nl.vpro.domain.subtitles.Cue;
import nl.vpro.domain.subtitles.SubtitlesFormat;
/**
* @author Michiel Meeuwissen
* @since 5.1
*/
abstract class AbstractIteratorWriter implements MessageBodyWriter> {
private final MediaType mediaType;
private final String extension;
public AbstractIteratorWriter(SubtitlesFormat format) {
this.mediaType = MediaType.valueOf(format.getMediaType());
this.extension = format.getExtension();
}
@Override
public boolean isWriteable(Class> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return mediaType.isCompatible(this.mediaType) && Iterator.class.isAssignableFrom(type);
}
@Override
public long getSize(Iterator cueIterator, Class> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}
@Override
public void writeTo(Iterator cueIterator, Class> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
cueIterator = Util.headers(cueIterator, httpHeaders, extension);
stream(cueIterator, entityStream);
}
protected abstract void stream(Iterator cueIterator, OutputStream entityStream) throws IOException;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy