|
113 | 113 | @Singleton |
114 | 114 | public class ProjectService extends Service { |
115 | 115 | private static final Logger LOG = LoggerFactory.getLogger(ProjectService.class); |
116 | | - private static final Tika TIKA = new Tika(); |
| 116 | + private static Tika TIKA; |
117 | 117 |
|
118 | 118 | private final ProjectManager projectManager; |
119 | 119 | private final EventService eventService; |
@@ -564,7 +564,10 @@ public Response getFile( |
564 | 564 | if (file == null) { |
565 | 565 | throw new NotFoundException("File not found for " + path); |
566 | 566 | } |
567 | | - return Response.ok().entity(file.getInputStream()).type(TIKA.detect(file.getName())).build(); |
| 567 | + return Response.ok() |
| 568 | + .entity(file.getInputStream()) |
| 569 | + .type(getTIKA().detect(file.getName())) |
| 570 | + .build(); |
568 | 571 | } |
569 | 572 |
|
570 | 573 | @PUT |
@@ -849,7 +852,7 @@ public Response exportFile( |
849 | 852 |
|
850 | 853 | final VirtualFile virtualFile = file.getVirtualFile(); |
851 | 854 |
|
852 | | - return Response.ok(virtualFile.getContent(), TIKA.detect(virtualFile.getName())) |
| 855 | + return Response.ok(virtualFile.getContent(), getTIKA().detect(virtualFile.getName())) |
853 | 856 | .lastModified(new Date(virtualFile.getLastModificationDate())) |
854 | 857 | .header(HttpHeaders.CONTENT_LENGTH, Long.toString(virtualFile.getLength())) |
855 | 858 | .header( |
@@ -1264,4 +1267,12 @@ private ItemReference injectFolderLinks(ItemReference itemReference) { |
1264 | 1267 | private ProjectConfigDto injectProjectLinks(ProjectConfigDto projectConfig) { |
1265 | 1268 | return projectServiceLinksInjector.injectProjectLinks(projectConfig, getServiceContext()); |
1266 | 1269 | } |
| 1270 | + |
| 1271 | + /** Lazy init of Tika. */ |
| 1272 | + private synchronized Tika getTIKA() { |
| 1273 | + if (TIKA == null) { |
| 1274 | + TIKA = new Tika(); |
| 1275 | + } |
| 1276 | + return TIKA; |
| 1277 | + } |
1267 | 1278 | } |
0 commit comments