Skip to content

Commit ea762f2

Browse files
Out of memory error thrown when using Dropwizard sample
1 parent 2d2d516 commit ea762f2

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

Demos/Dropwizard/src/main/java/com/groupdocs/ui/viewer/dropwizard/impls/HtmlViewer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
public class HtmlViewer extends CustomViewer<HtmlViewOptions> {
1414
public static final String CACHE_PAGES_EXTENSION = ".html";
1515
private final CustomFileStreamFactory fileStreamFactory = new CustomFileStreamFactory(this.cache, ".pdf");
16+
private CustomPageStreamFactory customPageStreamFactory;
17+
private CustomResourceStreamFactory customResourceStreamFactory;
1618

1719
public HtmlViewer(String filePath, ViewerCache cache, LoadOptions loadOptions) {
1820
this(filePath, cache, loadOptions, -1, 0);
@@ -26,9 +28,10 @@ public HtmlViewer(String filePath, ViewerCache cache, LoadOptions loadOptions, i
2628
}
2729

2830
private com.groupdocs.viewer.options.HtmlViewOptions createHtmlViewOptions(int passedPageNumber/* = -1*/, int newAngle/* = 0*/) {
29-
HtmlViewOptions htmlViewOptions = HtmlViewOptions.forExternalResources(
30-
new CustomPageStreamFactory(this.cache, CACHE_PAGES_EXTENSION),
31-
new CustomResourceStreamFactory(cache, Paths.get(filePath).getFileName().toString()));
31+
this.customPageStreamFactory = new CustomPageStreamFactory(this.cache, CACHE_PAGES_EXTENSION);
32+
this.customResourceStreamFactory = new CustomResourceStreamFactory(cache, Paths.get(filePath).getFileName().toString());
33+
34+
HtmlViewOptions htmlViewOptions = HtmlViewOptions.forExternalResources(customPageStreamFactory, customResourceStreamFactory);
3235

3336
htmlViewOptions.getSpreadsheetOptions().setTextOverflowMode(TextOverflowMode.HIDE_TEXT);
3437
htmlViewOptions.getSpreadsheetOptions().setSkipEmptyColumns(true);
@@ -67,5 +70,12 @@ protected int[] getPagesMissingFromCache(List<Page> pages) {
6770
public void close() {
6871
super.close();
6972
fileStreamFactory.close();
73+
74+
if (this.customPageStreamFactory != null) {
75+
this.customPageStreamFactory.close();
76+
}
77+
if (this.customResourceStreamFactory != null) {
78+
this.customResourceStreamFactory.close();
79+
}
7080
}
7181
}

Demos/Dropwizard/src/main/java/com/groupdocs/ui/viewer/dropwizard/impls/PngViewer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
public class PngViewer extends CustomViewer<PngViewOptions> {
1212
public static final String CACHE_PAGES_EXTENSION = ".png";
13+
private CustomFileStreamFactory customFileStreamFactory;
1314

1415
public PngViewer(String filePath, ViewerCache cache, LoadOptions loadOptions) {
1516
this(filePath, cache, loadOptions, -1, 0);
@@ -36,8 +37,8 @@ private PngViewOptions createPngViewOptions(int passedPageNumber/* = -1*/, int n
3637
}
3738

3839
private com.groupdocs.viewer.options.PdfViewOptions createPdfViewOptions() {
39-
PdfViewOptions pdfViewOptions = new PdfViewOptions(
40-
new CustomFileStreamFactory(this.cache, ".pdf"));
40+
this.customFileStreamFactory = new CustomFileStreamFactory(this.cache, ".pdf");
41+
PdfViewOptions pdfViewOptions = new PdfViewOptions(customFileStreamFactory);
4142
setWatermarkOptions(pdfViewOptions);
4243
return pdfViewOptions;
4344
}
@@ -46,4 +47,12 @@ private com.groupdocs.viewer.options.PdfViewOptions createPdfViewOptions() {
4647
protected int[] getPagesMissingFromCache(List<Page> pages) {
4748
return super.getPagesMissingFromCache(pages, CACHE_PAGES_EXTENSION);
4849
}
50+
51+
@Override
52+
public void close() {
53+
super.close();
54+
if (this.customFileStreamFactory != null) {
55+
this.customFileStreamFactory.close();
56+
}
57+
}
4958
}

Demos/Spring/src/main/java/com/groupdocs/ui/viewer/spring/impls/HtmlViewer.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
public class HtmlViewer extends CustomViewer<HtmlViewOptions> {
1414
public static final String CACHE_PAGES_EXTENSION = ".html";
15+
private final CustomFileStreamFactory fileStreamFactory = new CustomFileStreamFactory(this.cache, ".pdf");
16+
private CustomPageStreamFactory customPageStreamFactory;
17+
private CustomResourceStreamFactory customResourceStreamFactory;
1518

1619
public HtmlViewer(String filePath, ViewerCache cache, LoadOptions loadOptions) {
1720
this(filePath, cache, loadOptions, -1, 0);
@@ -25,9 +28,10 @@ public HtmlViewer(String filePath, ViewerCache cache, LoadOptions loadOptions, i
2528
}
2629

2730
private com.groupdocs.viewer.options.HtmlViewOptions createHtmlViewOptions(int passedPageNumber/* = -1*/, int newAngle/* = 0*/) {
28-
HtmlViewOptions htmlViewOptions = HtmlViewOptions.forExternalResources(
29-
new CustomPageStreamFactory(this.cache, CACHE_PAGES_EXTENSION),
30-
new CustomResourceStreamFactory(cache, Paths.get(filePath).getFileName().toString()));
31+
this.customPageStreamFactory = new CustomPageStreamFactory(this.cache, CACHE_PAGES_EXTENSION);
32+
this.customResourceStreamFactory = new CustomResourceStreamFactory(cache, Paths.get(filePath).getFileName().toString());
33+
34+
HtmlViewOptions htmlViewOptions = HtmlViewOptions.forExternalResources(customPageStreamFactory, customResourceStreamFactory);
3135

3236
htmlViewOptions.getSpreadsheetOptions().setTextOverflowMode(TextOverflowMode.HIDE_TEXT);
3337
htmlViewOptions.getSpreadsheetOptions().setSkipEmptyColumns(true);
@@ -45,7 +49,7 @@ private com.groupdocs.viewer.options.HtmlViewOptions createHtmlViewOptions(int p
4549
}
4650

4751
private com.groupdocs.viewer.options.PdfViewOptions createPdfViewOptions() {
48-
PdfViewOptions pdfViewOptions = new PdfViewOptions(new CustomFileStreamFactory(this.cache, ".pdf"));
52+
PdfViewOptions pdfViewOptions = new PdfViewOptions(fileStreamFactory);
4953
setCommonViewOptions(pdfViewOptions);
5054
return pdfViewOptions;
5155
}
@@ -61,4 +65,17 @@ private void setCommonViewOptions(com.groupdocs.viewer.options.ViewOptions viewO
6165
protected int[] getPagesMissingFromCache(List<Page> pages) {
6266
return super.getPagesMissingFromCache(pages, CACHE_PAGES_EXTENSION);
6367
}
68+
69+
@Override
70+
public void close() {
71+
super.close();
72+
fileStreamFactory.close();
73+
74+
if (this.customPageStreamFactory != null) {
75+
this.customPageStreamFactory.close();
76+
}
77+
if (this.customResourceStreamFactory != null) {
78+
this.customResourceStreamFactory.close();
79+
}
80+
}
6481
}

Demos/Spring/src/main/java/com/groupdocs/ui/viewer/spring/impls/PngViewer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
public class PngViewer extends CustomViewer<PngViewOptions> {
1212
public static final String CACHE_PAGES_EXTENSION = ".png";
13+
private CustomFileStreamFactory customFileStreamFactory;
1314

1415
public PngViewer(String filePath, ViewerCache cache, LoadOptions loadOptions) {
1516
this(filePath, cache, loadOptions, -1, 0);
@@ -36,7 +37,8 @@ private PngViewOptions createPngViewOptions(int passedPageNumber/* = -1*/, int n
3637
}
3738

3839
private com.groupdocs.viewer.options.PdfViewOptions createPdfViewOptions() {
39-
PdfViewOptions pdfViewOptions = new PdfViewOptions(new CustomFileStreamFactory(this.cache, ".pdf"));
40+
this.customFileStreamFactory = new CustomFileStreamFactory(this.cache, ".pdf");
41+
PdfViewOptions pdfViewOptions = new PdfViewOptions(customFileStreamFactory);
4042
setWatermarkOptions(pdfViewOptions);
4143
return pdfViewOptions;
4244
}
@@ -45,4 +47,12 @@ private com.groupdocs.viewer.options.PdfViewOptions createPdfViewOptions() {
4547
protected int[] getPagesMissingFromCache(List<Page> pages) {
4648
return super.getPagesMissingFromCache(pages, CACHE_PAGES_EXTENSION);
4749
}
50+
51+
@Override
52+
public void close() {
53+
super.close();
54+
if (this.customFileStreamFactory != null) {
55+
this.customFileStreamFactory.close();
56+
}
57+
}
4858
}

0 commit comments

Comments
 (0)