Skip to content

Commit

Permalink
Lazy init of Tika
Browse files Browse the repository at this point in the history
Change-Id: I06872806f8a4c334614e1e15a12b5c533f5d8c11
Signed-off-by: Florent BENOIT <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Sep 11, 2017
1 parent 5231059 commit e493f57
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
@Singleton
public class ProjectService extends Service {
private static final Logger LOG = LoggerFactory.getLogger(ProjectService.class);
private static final Tika TIKA = new Tika();
private static Tika TIKA;

private final ProjectManager projectManager;
private final EventService eventService;
Expand Down Expand Up @@ -564,7 +564,10 @@ public Response getFile(
if (file == null) {
throw new NotFoundException("File not found for " + path);
}
return Response.ok().entity(file.getInputStream()).type(TIKA.detect(file.getName())).build();
return Response.ok()
.entity(file.getInputStream())
.type(getTIKA().detect(file.getName()))
.build();
}

@PUT
Expand Down Expand Up @@ -849,7 +852,7 @@ public Response exportFile(

final VirtualFile virtualFile = file.getVirtualFile();

return Response.ok(virtualFile.getContent(), TIKA.detect(virtualFile.getName()))
return Response.ok(virtualFile.getContent(), getTIKA().detect(virtualFile.getName()))
.lastModified(new Date(virtualFile.getLastModificationDate()))
.header(HttpHeaders.CONTENT_LENGTH, Long.toString(virtualFile.getLength()))
.header(
Expand Down Expand Up @@ -1264,4 +1267,12 @@ private ItemReference injectFolderLinks(ItemReference itemReference) {
private ProjectConfigDto injectProjectLinks(ProjectConfigDto projectConfig) {
return projectServiceLinksInjector.injectProjectLinks(projectConfig, getServiceContext());
}

/** Lazy init of Tika. */
private synchronized Tika getTIKA() {
if (TIKA == null) {
TIKA = new Tika();
}
return TIKA;
}
}

0 comments on commit e493f57

Please sign in to comment.