use of eu.medsea.mimeutil.MimeType in project gerrit by GerritCodeReview.
the class CommentContextLoader method getContentType.
private String getContentType(TreeWalk tw, String filePath, Text src) {
PatchScript.FileMode fileMode = PatchScript.FileMode.fromJgitFileMode(tw.getFileMode(0));
String mimeType = MimeUtil2.UNKNOWN_MIME_TYPE.toString();
if (src.size() > 0 && PatchScript.FileMode.SYMLINK != fileMode) {
MimeType registryMimeType = registry.getMimeType(filePath, src.getContent());
mimeType = registryMimeType.toString();
}
return FileContentUtil.resolveContentType(projectState, filePath, fileMode, mimeType);
}
use of eu.medsea.mimeutil.MimeType in project BroadleafCommerce by BroadleafCommerce.
the class StaticAssetServiceImpl method getMimeType.
protected void getMimeType(InputStream inputStream, String fileName, StaticAsset newAsset) {
Collection mimeTypes = MimeUtil.getMimeTypes(fileName);
if (!mimeTypes.isEmpty()) {
MimeType mimeType = (MimeType) mimeTypes.iterator().next();
newAsset.setMimeType(mimeType.toString());
} else {
mimeTypes = MimeUtil.getMimeTypes(inputStream);
if (!mimeTypes.isEmpty()) {
MimeType mimeType = (MimeType) mimeTypes.iterator().next();
newAsset.setMimeType(mimeType.toString());
}
}
}
use of eu.medsea.mimeutil.MimeType in project gerrit by GerritCodeReview.
the class FileContentUtil method downloadContent.
public BinaryResult downloadContent(ProjectState project, ObjectId revstr, String path, @Nullable Integer parent) throws ResourceNotFoundException, IOException {
try (Repository repo = openRepository(project);
RevWalk rw = new RevWalk(repo)) {
String suffix = "new";
RevCommit commit = rw.parseCommit(revstr);
if (parent != null && parent > 0) {
if (commit.getParentCount() == 1) {
suffix = "old";
} else {
suffix = "old" + parent;
}
commit = rw.parseCommit(commit.getParent(parent - 1));
}
try (TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(), path, commit.getTree())) {
if (tw == null) {
throw new ResourceNotFoundException();
}
int mode = tw.getFileMode(0).getObjectType();
if (mode != Constants.OBJ_BLOB) {
throw new ResourceNotFoundException();
}
ObjectId id = tw.getObjectId(0);
ObjectLoader obj = repo.open(id, OBJ_BLOB);
byte[] raw;
try {
raw = obj.getCachedBytes(MAX_SIZE);
} catch (LargeObjectException e) {
raw = null;
}
MimeType contentType = registry.getMimeType(path, raw);
return registry.isSafeInline(contentType) ? wrapBlob(path, obj, raw, contentType, suffix) : zipBlob(path, obj, commit, suffix);
}
}
}
use of eu.medsea.mimeutil.MimeType in project gerrit by GerritCodeReview.
the class DefaultFileExtensionRegistry method getMimeTypesFileName.
@Override
protected Collection<MimeType> getMimeTypesFileName(String name) {
int s = name.lastIndexOf('/');
if (s >= 0) {
name = name.substring(s + 1);
}
MimeType type = TYPES.get(name);
if (type != null) {
return Collections.singletonList(type);
}
int d = name.lastIndexOf('.');
if (0 < d) {
type = TYPES.get(name.substring(d + 1));
if (type != null) {
return Collections.singletonList(type);
}
}
return Collections.emptyList();
}
use of eu.medsea.mimeutil.MimeType in project lobcder by skoulouzis.
the class ContentTypeUtils method buildContentTypeText.
private static String buildContentTypeText(Collection mimeTypes) {
StringBuilder sb = null;
for (Object o : mimeTypes) {
MimeType mt = (MimeType) o;
if (sb == null) {
sb = new StringBuilder();
} else {
sb.append(",");
}
sb.append(mt.toString());
}
if (sb == null) {
return "";
} else {
return sb.toString();
}
}
Aggregations