Search in sources :

Example 6 with CaptionConverter

use of org.opencastproject.caption.api.CaptionConverter in project opencast by opencast.

the class CaptionServiceImpl method importCaptions.

/**
 * Imports captions using registered converter engine and specified language.
 *
 * @param input
 *          file containing captions
 * @param inputFormat
 *          format of imported captions
 * @param language
 *          (optional) captions' language
 * @return {@link List} of parsed captions
 * @throws UnsupportedCaptionFormatException
 *           if there is no registered engine for given format
 * @throws IllegalCaptionFormatException
 *           if parser encounters exception
 */
private List<Caption> importCaptions(File input, String inputFormat, String language) throws UnsupportedCaptionFormatException, CaptionConverterException {
    // get input format
    CaptionConverter converter = getCaptionConverter(inputFormat);
    if (converter == null) {
        logger.error("No available caption format found for {}.", inputFormat);
        throw new UnsupportedCaptionFormatException(inputFormat);
    }
    FileInputStream fileStream = null;
    try {
        fileStream = new FileInputStream(input);
        List<Caption> collection = converter.importCaption(fileStream, language);
        return collection;
    } catch (FileNotFoundException e) {
        throw new CaptionConverterException("Could not locate file " + input);
    } finally {
        IOUtils.closeQuietly(fileStream);
    }
}
Also used : CaptionConverterException(org.opencastproject.caption.api.CaptionConverterException) UnsupportedCaptionFormatException(org.opencastproject.caption.api.UnsupportedCaptionFormatException) FileNotFoundException(java.io.FileNotFoundException) CaptionConverter(org.opencastproject.caption.api.CaptionConverter) FileInputStream(java.io.FileInputStream) Caption(org.opencastproject.caption.api.Caption)

Aggregations

CaptionConverter (org.opencastproject.caption.api.CaptionConverter)6 UnsupportedCaptionFormatException (org.opencastproject.caption.api.UnsupportedCaptionFormatException)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 CaptionConverterException (org.opencastproject.caption.api.CaptionConverterException)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Caption (org.opencastproject.caption.api.Caption)2 NotFoundException (org.opencastproject.util.NotFoundException)2 ServiceReference (org.osgi.framework.ServiceReference)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)1 MediaPackageElementBuilder (org.opencastproject.mediapackage.MediaPackageElementBuilder)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)1