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;
}
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;
}
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();
}
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;
}
}
Aggregations