use of javax.activation.MimetypesFileTypeMap in project sigla-main by consiglionazionaledellericerche.
the class FatturaPassivaElettronicaService method notificaFatturaAttivaAvvenutaTrasmissioneNonRecapitata.
private void notificaFatturaAttivaAvvenutaTrasmissioneNonRecapitata(Message message) throws ComponentException {
logger.info("Fatture Elettroniche: Attive: Inizio Avvenuta Trasmissione con impossibilità di recapito.");
try {
BodyPart bodyPartZip = estraiBodyPartZipNotificaFatturaAttiva(message);
if (bodyPartZip != null) {
logger.info("Fatture Elettroniche: Attive: Estratto Body Part.");
ZipInputStream zis = new ZipInputStream(bodyPartZip.getInputStream());
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
System.out.println("entry: " + entry.getName() + ", " + entry.getSize());
if (entry.getName().toLowerCase().endsWith("xml")) {
String contentType = new MimetypesFileTypeMap().getContentType(entry.getName());
DataHandler dataHandler = createDataHandler(zis, contentType);
trasmissioneFattureService.notificaFatturaAttivaAvvenutaTrasmissioneNonRecapitata(userContext, entry.getName(), dataHandler);
break;
}
}
}
} catch (Exception e) {
throw new ComponentException(e);
}
}
use of javax.activation.MimetypesFileTypeMap in project idempiere by idempiere.
the class MultiFileDownloadDialog method show.
private void show() {
Vlayout layout = new Vlayout();
layout.setStyle("padding-top: 10px; padding-bottom: 10px;");
appendChild(layout);
MimetypesFileTypeMap mimeMap = new MimetypesFileTypeMap();
for (File file : files) {
try {
AMedia media = new AMedia(file, mimeMap.getContentType(file), null);
DynamicMediaLink link = new DynamicMediaLink();
layout.appendChild(link);
link.setMedia(media);
link.setLabel(media.getName());
link.setStyle("margin: 5px;");
} catch (FileNotFoundException e) {
}
}
this.setClosable(true);
this.setSizable(true);
this.setMaximizable(true);
this.setBorder("normal");
this.setContentStyle("min-height: 200px; min-width:300px");
this.setPosition("center");
if (this.getTitle() == null || this.getTitle().length() == 0) {
this.setTitle("Downloads");
}
this.doHighlighted();
}
use of javax.activation.MimetypesFileTypeMap in project gravitee-api-management by gravitee-io.
the class ThemeServiceImpl method getImage.
private String getImage(String filename) {
String filepath = themesPath + "/" + filename;
try {
byte[] image = Files.readAllBytes(new File(filepath).toPath());
MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
return "data:" + fileTypeMap.getContentType(filename) + ";base64," + Base64.getEncoder().encodeToString(image);
} catch (IOException ex) {
final String error = "Error while trying to load image from: " + filepath;
LOGGER.error(error, ex);
return null;
}
}
use of javax.activation.MimetypesFileTypeMap in project studio by craftercms.
the class BinaryView method renderMergedOutputModel.
@Override
@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
OutputStream out = response.getOutputStream();
Map<String, Object> responseModelMap = (Map<String, Object>) model.get(RestScriptsController.DEFAULT_RESPONSE_BODY_MODEL_ATTR_NAME);
if (responseModelMap != null) {
InputStream contentStream = (InputStream) responseModelMap.get(DEFAULT_CONTENT_STREAM_MODEL_ATTR_NAME);
String contentPath = (String) responseModelMap.get(DEFAULT_CONTENT_PATH_MODEL_ATTR_NAME);
MimetypesFileTypeMap mimetypesFileTypeMap = new MimetypesFileTypeMap();
String contentType = mimetypesFileTypeMap.getContentType(contentPath);
response.setContentType(contentType);
if (contentStream != null) {
IOUtils.write(IOUtils.toByteArray(contentStream), out);
}
out.flush();
IOUtils.closeQuietly(contentStream);
IOUtils.closeQuietly(out);
}
}
use of javax.activation.MimetypesFileTypeMap in project studio by craftercms.
the class AwsUtils method uploadStream.
public static void uploadStream(String inputBucket, String inputKey, AmazonS3 s3Client, int partSize, String filename, InputStream content) throws AwsException {
List<PartETag> etags = new LinkedList<>();
InitiateMultipartUploadResult initResult = null;
try {
int partNumber = 1;
long totalBytes = 0;
MimetypesFileTypeMap mimeMap = new MimetypesFileTypeMap();
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(mimeMap.getContentType(filename));
InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(inputBucket, inputKey, meta);
initResult = s3Client.initiateMultipartUpload(initRequest);
byte[] buffer = new byte[partSize];
int read;
logger.debug("Starting upload for file '{}'", filename);
while (0 < (read = IOUtils.read(content, buffer))) {
totalBytes += read;
if (logger.isTraceEnabled()) {
logger.trace("Uploading part {} with size {} - total: {}", partNumber, read, totalBytes);
}
ByteArrayInputStream bais = new ByteArrayInputStream(buffer, 0, read);
UploadPartRequest uploadRequest = new UploadPartRequest().withUploadId(initResult.getUploadId()).withBucketName(inputBucket).withKey(inputKey).withInputStream(bais).withPartNumber(partNumber).withPartSize(read).withLastPart(read < partSize);
etags.add(s3Client.uploadPart(uploadRequest).getPartETag());
partNumber++;
}
if (totalBytes == 0) {
// If the file is empty, use the simple upload instead of the multipart
s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(inputBucket, inputKey, initResult.getUploadId()));
s3Client.putObject(inputBucket, inputKey, new ByteArrayInputStream(new byte[0]), meta);
} else {
CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest(inputBucket, inputKey, initResult.getUploadId(), etags);
s3Client.completeMultipartUpload(completeRequest);
}
logger.debug("Upload completed for file '{}'", filename);
} catch (Exception e) {
if (initResult != null) {
s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(inputBucket, inputKey, initResult.getUploadId()));
}
throw new AwsException("Upload of file '" + filename + "' failed", e);
}
}
Aggregations