Search in sources :

Example 71 with ClassPathResource

use of org.datavec.api.util.ClassPathResource in project deeplearning4j by deeplearning4j.

the class Assets method apply.

@Override
public Result apply(String s) {
    String fullPath = assetsRootDirectory + s;
    InputStream inputStream;
    try {
        inputStream = new ClassPathResource(fullPath).getInputStream();
    } catch (Exception e) {
        log.debug("Could not find asset: {}", s);
        return ok();
    } catch (Throwable t) {
        return ok();
    }
    String fileName = FilenameUtils.getName(fullPath);
    response().setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"");
    scala.Option<String> contentType = MimeTypes.forFileName(fileName);
    String ct;
    if (contentType.isDefined()) {
        ct = contentType.get();
    } else {
        ct = "application/octet-stream";
    }
    return ok(inputStream).as(ct);
}
Also used : InputStream(java.io.InputStream) ClassPathResource(org.datavec.api.util.ClassPathResource)

Aggregations

ClassPathResource (org.datavec.api.util.ClassPathResource)71 Test (org.junit.Test)63 File (java.io.File)45 TokenizerFactory (org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory)28 BasicLineIterator (org.deeplearning4j.text.sentenceiterator.BasicLineIterator)27 DefaultTokenizerFactory (org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory)27 VocabWord (org.deeplearning4j.models.word2vec.VocabWord)23 SentenceIterator (org.deeplearning4j.text.sentenceiterator.SentenceIterator)23 INDArray (org.nd4j.linalg.api.ndarray.INDArray)23 CommonPreprocessor (org.deeplearning4j.text.tokenization.tokenizer.preprocessor.CommonPreprocessor)20 SentenceTransformer (org.deeplearning4j.models.sequencevectors.transformers.impl.SentenceTransformer)12 AbstractCache (org.deeplearning4j.models.word2vec.wordstore.inmemory.AbstractCache)11 WordVectors (org.deeplearning4j.models.embeddings.wordvectors.WordVectors)10 AbstractSequenceIterator (org.deeplearning4j.models.sequencevectors.iterators.AbstractSequenceIterator)10 ArrayList (java.util.ArrayList)9 Word2Vec (org.deeplearning4j.models.word2vec.Word2Vec)8 AggregatingSentenceIterator (org.deeplearning4j.text.sentenceiterator.AggregatingSentenceIterator)7 FileSentenceIterator (org.deeplearning4j.text.sentenceiterator.FileSentenceIterator)7 DataSet (org.nd4j.linalg.dataset.DataSet)7 InputStream (java.io.InputStream)6