Search in sources :

Example 1 with MimeType

use of org.openecard.control.binding.http.common.MimeType in project open-ecard by ecsec.

the class FileHandler method handleFile.

private void handleFile(Http11Response httpResponse, URL file) throws Exception {
    String fileName = file.toString();
    String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
    MimeType mimeType = MimeType.fromFilenameExtension(fileExtension);
    String typeName = (mimeType != null) ? mimeType.getMimeType() : MimeType.TEXT_PLAIN.getMimeType();
    httpResponse.setStatusCode(HttpStatus.SC_OK);
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(file.openStream());
    entity.setContentType(ContentType.create(typeName, "UTF-8").toString());
    httpResponse.setEntity(entity);
}
Also used : BasicHttpEntity(org.openecard.apache.http.entity.BasicHttpEntity) MimeType(org.openecard.control.binding.http.common.MimeType)

Aggregations

BasicHttpEntity (org.openecard.apache.http.entity.BasicHttpEntity)1 MimeType (org.openecard.control.binding.http.common.MimeType)1