Skip to content

Commit e493f57

Browse files
committed
Lazy init of Tika
Change-Id: I06872806f8a4c334614e1e15a12b5c533f5d8c11 Signed-off-by: Florent BENOIT <fbenoit@redhat.com>
1 parent 5231059 commit e493f57

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
@Singleton
114114
public class ProjectService extends Service {
115115
private static final Logger LOG = LoggerFactory.getLogger(ProjectService.class);
116-
private static final Tika TIKA = new Tika();
116+
private static Tika TIKA;
117117

118118
private final ProjectManager projectManager;
119119
private final EventService eventService;
@@ -564,7 +564,10 @@ public Response getFile(
564564
if (file == null) {
565565
throw new NotFoundException("File not found for " + path);
566566
}
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();
568571
}
569572

570573
@PUT
@@ -849,7 +852,7 @@ public Response exportFile(
849852

850853
final VirtualFile virtualFile = file.getVirtualFile();
851854

852-
return Response.ok(virtualFile.getContent(), TIKA.detect(virtualFile.getName()))
855+
return Response.ok(virtualFile.getContent(), getTIKA().detect(virtualFile.getName()))
853856
.lastModified(new Date(virtualFile.getLastModificationDate()))
854857
.header(HttpHeaders.CONTENT_LENGTH, Long.toString(virtualFile.getLength()))
855858
.header(
@@ -1264,4 +1267,12 @@ private ItemReference injectFolderLinks(ItemReference itemReference) {
12641267
private ProjectConfigDto injectProjectLinks(ProjectConfigDto projectConfig) {
12651268
return projectServiceLinksInjector.injectProjectLinks(projectConfig, getServiceContext());
12661269
}
1270+
1271+
/** Lazy init of Tika. */
1272+
private synchronized Tika getTIKA() {
1273+
if (TIKA == null) {
1274+
TIKA = new Tika();
1275+
}
1276+
return TIKA;
1277+
}
12671278
}

0 commit comments

Comments
 (0)