Search in sources :

Example 31 with FileNameMap

use of java.net.FileNameMap in project QuickAndroid by ImKarl.

the class FilePart method guessMimeType.

private static String guessMimeType(String filename) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(filename);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
Also used : FileNameMap(java.net.FileNameMap)

Example 32 with FileNameMap

use of java.net.FileNameMap in project j2objc by google.

the class FileURLConnection method getInputStream.

public synchronized InputStream getInputStream() throws IOException {
    int iconHeight;
    int iconWidth;
    connect();
    if (is == null) {
        if (isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();
            StringBuffer buf = new StringBuffer();
            if (files == null) {
                throw new FileNotFoundException(filename);
            }
            Collections.sort(files, Collator.getInstance());
            for (int i = 0; i < files.size(); i++) {
                String fileName = files.get(i);
                buf.append(fileName);
                buf.append("\n");
            }
            // Put it into a (default) locale-specific byte-stream.
            is = new ByteArrayInputStream(buf.toString().getBytes());
        } else {
            throw new FileNotFoundException(filename);
        }
    }
    return is;
}
Also used : FileNameMap(java.net.FileNameMap)

Example 33 with FileNameMap

use of java.net.FileNameMap in project OpenClinica by OpenClinica.

the class OpenRosaServices method getMediaFile.

/**
 * @api {get} /rest2/openrosa/:studyOID/downloadMedia Download media
 * @apiName getMediaFile
 * @apiPermission admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOID Study Oid.
 * @apiGroup Form
 * @apiDescription Downloads media associated with a form, including images and video.
 */
@GET
@Path("/{studyOID}/downloadMedia")
public Response getMediaFile(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("crfVersionMediaId") String crfVersionMediaId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
    if (!mayProceedPreview(studyOID))
        return null;
    CrfVersionMediaDao mediaDao = (CrfVersionMediaDao) SpringServletAccess.getApplicationContext(context).getBean("crfVersionMediaDao");
    CrfVersionMedia media = mediaDao.findById(Integer.valueOf(crfVersionMediaId));
    File image = new File(media.getPath() + media.getName());
    FileInputStream fis = new FileInputStream(image);
    StreamingOutput stream = new MediaStreamingOutput(fis);
    ResponseBuilder builder = Response.ok(stream);
    // Set content type, if known
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String type = fileNameMap.getContentTypeFor(media.getPath() + media.getName());
    if (type != null && !type.isEmpty())
        builder = builder.header("Content-Type", type);
    return builder.build();
}
Also used : CrfVersionMedia(org.akaza.openclinica.domain.datamap.CrfVersionMedia) StreamingOutput(javax.ws.rs.core.StreamingOutput) CrfVersionMediaDao(org.akaza.openclinica.dao.hibernate.CrfVersionMediaDao) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) FileNameMap(java.net.FileNameMap) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Path(javax.ws.rs.Path) XPath(javax.xml.xpath.XPath) GET(javax.ws.rs.GET)

Example 34 with FileNameMap

use of java.net.FileNameMap in project engine by craftercms.

the class ContentStoreUrlConnection method initializeHeaders.

protected void initializeHeaders() {
    if (!initializedHeaders) {
        length = content.getLength();
        lastModified = content.getLastModified();
        FileNameMap map = getFileNameMap();
        contentType = map.getContentTypeFor(url.getFile());
        if (contentType != null) {
            headers.put(CONTENT_TYPE, contentType);
        }
        headers.put(CONTENT_LENGTH, String.valueOf(length));
        /*
             * Format the last-modified field into the preferred
             * Internet standard - ie: fixed-length subset of that
             * defined by RFC 1123
             * */
        Date date = new Date(lastModified);
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
        dateFormat.setTimeZone(TimeZone.getTimeZone(TIMEZONE));
        headers.put(LAST_MODIFIED, dateFormat.format(date));
        initializedHeaders = true;
    }
}
Also used : FileNameMap(java.net.FileNameMap) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

FileNameMap (java.net.FileNameMap)34 File (java.io.File)7 SimpleDateFormat (java.text.SimpleDateFormat)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 DigestException (com.openmeap.digest.DigestException)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)2 BufferedInputStream (java.io.BufferedInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Map (java.util.Map)2 Wrong (app.hongs.util.verify.Wrong)1 Category (com.agiletec.aps.system.services.category.Category)1 BaseResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean)1 ModelManager (com.openmeap.model.ModelManager)1 Application (com.openmeap.model.dto.Application)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1