Search in sources :

Example 11 with AnnisBinaryMetaData

use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.

the class QueryDaoImpl method getBinary.

@Override
public InputStream getBinary(String toplevelCorpusName, String corpusName, String mimeType, String title, int offset, int length) {
    AnnisBinaryMetaData binary = (AnnisBinaryMetaData) getJdbcTemplate().query(ByteHelper.SQL, byteHelper.getArgs(toplevelCorpusName, corpusName, mimeType, title, offset, length), ByteHelper.getArgTypes(), byteHelper);
    try {
        // retrieve the requested part of the file from the data directory
        File dataFile = new File(getRealDataDir(), binary.getLocalFileName());
        long fileSize = dataFile.length();
        Preconditions.checkArgument(offset + length <= fileSize, "Range larger than the actual file size requested. Actual file size is %d bytes, %d bytes were requested.", fileSize, offset + length);
        FileInputStream fInput = new FileInputStream(dataFile);
        ByteStreams.skipFully(fInput, offset);
        return ByteStreams.limit(fInput, length);
    } catch (FileNotFoundException ex) {
        log.warn("Media file from database not found in data directory", ex);
    } catch (IOException ex) {
        log.warn("Error when reading media file from the data directory", ex);
    }
    return new ByteArrayInputStream(new byte[0]);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) AnnisBinaryMetaData(annis.service.objects.AnnisBinaryMetaData) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

AnnisBinaryMetaData (annis.service.objects.AnnisBinaryMetaData)11 WebResource (com.sun.jersey.api.client.WebResource)4 List (java.util.List)3 MediaElementPlayer (annis.gui.components.medialement.MediaElementPlayer)2 MediaController (annis.libgui.media.MediaController)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 SQLException (java.sql.SQLException)2 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 VaadinServletResponse (com.vaadin.server.VaadinServletResponse)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 MediaType (javax.ws.rs.core.MediaType)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1