Supporting byte-ranges inside a Seam component
bgoll Mar 5, 2010 3:58 PMHello,
I currently try to implement a simple streaming-server for ogg vorbis-files. This server will be included into a bigger project. The ogg-files will be played back via the HTML5 audio-tag in Firefox. Serving the files to the browser works fine but not seeking inside of the file. For this to work properly, I would have to support byte-ranges inside my Seam component (according to http://pearce.org.nz/blog/?p=9). Since Tomcat supports byte-ranges by default, I would like to pass my outputstream directly to Tomcat. Is there any possibility for this?
Maybe a bit of code can make more clear what I mean:
@Name("streamingServer")
@AutoCreate
@Scope(ScopeType.APPLICATION)
@Startup
public class StreamingServer
{
@Logger
private Log log;
@In
EntityManager entityManager;
@In
String libraryPath;
@In(value="#{facesContext.externalContext}")
private ExternalContext extCtx;
@In(value="#{facesContext}")
FacesContext facesContext;
@RequestParameter
private Long trackId;
private static final int DEFAULT_BUFFER_SIZE = 1024;
public void download()
{
Track track = entityManager.find(Track.class, trackId);
File fileHandle = new File(libraryPath + track.getFilePath());
HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
response.reset();
response.setBufferSize(1024);
response.setContentType(track.getMimeType());
response.setContentLength((int) fileHandle.length());
response.setHeader("X-Content-Duration", Float.toString(track.getLength()));
BufferedInputStream in = null;
BufferedOutputStream out = null;
try
{
in = new BufferedInputStream(new FileInputStream(fileHandle), DEFAULT_BUFFER_SIZE);
out = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int length;
while ((length = in.read(buffer)) > 0)
{
out.write(buffer, 0, length);
}
in.close();
out.close();
facesContext.responseComplete();
}
catch(Exception e)
{
log.error("Failure : " + e.toString());
}
}
}What I would like to do is read in the ogg-file from the disk and pass it to Tomcat's default servlet which could then serve it supporting byte-ranges.
If this is not possible, do you see any other possibility to achieve my goal?
environment:
JBoss 4.2.3GA
Seam 2.2.0GA
ICEFaces 1.8.2
Thanks in advance!
Regards
Benjamin