73
73
import org .exist .util .crypto .digest .DigestType ;
74
74
import org .exist .util .crypto .digest .MessageDigest ;
75
75
import org .exist .util .io .ContentFile ;
76
+ import org .exist .util .io .ContentFilePool ;
76
77
import org .exist .util .io .TemporaryFileManager ;
77
- import org .exist .util .io .VirtualTempPath ;
78
78
import org .exist .util .serializer .SAXSerializer ;
79
79
import org .exist .util .serializer .SerializerPool ;
80
80
import org .exist .validation .ValidationReport ;
@@ -137,12 +137,14 @@ public class RpcConnection implements RpcAPI {
137
137
private final static Charset DEFAULT_ENCODING = StandardCharsets .UTF_8 ;
138
138
139
139
private final XmldbRequestProcessorFactory factory ;
140
+ private final ContentFilePool filePool ;
140
141
private final Subject user ;
141
142
private final Random random = new Random ();
142
143
143
- public RpcConnection (final XmldbRequestProcessorFactory factory , final Subject user ) {
144
+ public RpcConnection (final XmldbRequestProcessorFactory factory , final ContentFilePool filePool , final Subject user ) {
144
145
super ();
145
146
this .factory = factory ;
147
+ this .filePool = filePool ;
146
148
this .user = user ;
147
149
}
148
150
@@ -169,10 +171,6 @@ private TemporaryFileManager temporaryFileManager() {
169
171
return TemporaryFileManager .getInstance ();
170
172
}
171
173
172
- private VirtualTempPath createVirtualTempPath () {
173
- return new VirtualTempPath (temporaryFileManager ());
174
- }
175
-
176
174
private boolean createCollection (final XmldbURI collUri , final Date created ) throws PermissionDeniedException , EXistException {
177
175
withDb ((broker , transaction ) -> {
178
176
Collection current = broker .getCollection (collUri );
@@ -704,7 +702,7 @@ public Map<String, Object> getDocumentData(final String docName, final Map<Strin
704
702
705
703
// A tweak for very large resources, VirtualTempFile
706
704
final Map <String , Object > result = new HashMap <>();
707
- final VirtualTempPath tempFile = createVirtualTempPath ();
705
+ final ContentFile tempFile = filePool . borrowObject ();
708
706
709
707
if (document .getResourceType () == DocumentImpl .XML_FILE ) {
710
708
try (final OutputStream out = tempFile .newOutputStream ();
@@ -724,11 +722,11 @@ public Map<String, Object> getDocumentData(final String docName, final Map<Strin
724
722
if (tempFile .size () > MAX_DOWNLOAD_CHUNK_SIZE ) {
725
723
offset = firstChunk .length ;
726
724
727
- final int handle = factory .resultSets .add (new CachedContentFile (tempFile ));
725
+ final int handle = factory .resultSets .add (new CachedContentFile (tempFile , filePool :: returnObject ));
728
726
result .put ("handle" , Integer .toString (handle ));
729
727
result .put ("supports-long-offset" , Boolean .TRUE );
730
728
} else {
731
- tempFile . close ( );
729
+ filePool . returnObject ( tempFile );
732
730
}
733
731
result .put ("offset" , offset );
734
732
@@ -2180,7 +2178,7 @@ public Map<String, Object> retrieveFirstChunk(final String docName, final String
2180
2178
final NodeProxy node = new NodeProxy (null , document , nodeId );
2181
2179
2182
2180
final Map <String , Object > result = new HashMap <>();
2183
- final VirtualTempPath tempFile = createVirtualTempPath ();
2181
+ final ContentFile tempFile = filePool . borrowObject ();
2184
2182
2185
2183
if (compression && LOG .isDebugEnabled ()) {
2186
2184
LOG .debug ("retrieveFirstChunk with compression" );
@@ -2199,11 +2197,11 @@ public Map<String, Object> retrieveFirstChunk(final String docName, final String
2199
2197
if (tempFile .size () > MAX_DOWNLOAD_CHUNK_SIZE ) {
2200
2198
offset = firstChunk .length ;
2201
2199
2202
- final int handle = factory .resultSets .add (new CachedContentFile (tempFile ));
2200
+ final int handle = factory .resultSets .add (new CachedContentFile (tempFile , filePool :: returnObject ));
2203
2201
result .put ("handle" , Integer .toString (handle ));
2204
2202
result .put ("supports-long-offset" , Boolean .TRUE );
2205
2203
} else {
2206
- tempFile . close ( );
2204
+ filePool . returnObject ( tempFile );
2207
2205
}
2208
2206
result .put ("offset" , offset );
2209
2207
return result ;
@@ -2283,7 +2281,7 @@ public Map<String, Object> retrieveFirstChunk(final int resultId, final int num,
2283
2281
}
2284
2282
2285
2283
final Map <String , Object > result = new HashMap <>();
2286
- final VirtualTempPath tempFile = createVirtualTempPath ();
2284
+ final ContentFile tempFile = filePool . borrowObject ();
2287
2285
2288
2286
if (compression && LOG .isDebugEnabled ()) {
2289
2287
LOG .debug ("retrieveFirstChunk with compression" );
@@ -2312,11 +2310,11 @@ public Map<String, Object> retrieveFirstChunk(final int resultId, final int num,
2312
2310
if (tempFile .size () > MAX_DOWNLOAD_CHUNK_SIZE ) {
2313
2311
offset = firstChunk .length ;
2314
2312
2315
- final int handle = factory .resultSets .add (new CachedContentFile (tempFile ));
2313
+ final int handle = factory .resultSets .add (new CachedContentFile (tempFile , filePool :: returnObject ));
2316
2314
result .put ("handle" , Integer .toString (handle ));
2317
2315
result .put ("supports-long-offset" , Boolean .TRUE );
2318
2316
} else {
2319
- tempFile . close ( );
2317
+ filePool . returnObject ( tempFile );
2320
2318
}
2321
2319
result .put ("offset" , offset );
2322
2320
return result ;
@@ -2400,7 +2398,7 @@ public Map<String, Object> retrieveAllFirstChunk(final int resultId, final Map<S
2400
2398
try {
2401
2399
2402
2400
final Map <String , Object > result = new HashMap <>();
2403
- final VirtualTempPath tempFile = createVirtualTempPath ();
2401
+ final ContentFile tempFile = filePool . borrowObject ();
2404
2402
2405
2403
if (compression && LOG .isDebugEnabled ()) {
2406
2404
LOG .debug ("retrieveAllFirstChunk with compression" );
@@ -2454,11 +2452,11 @@ public Map<String, Object> retrieveAllFirstChunk(final int resultId, final Map<S
2454
2452
if (tempFile .size () > MAX_DOWNLOAD_CHUNK_SIZE ) {
2455
2453
offset = firstChunk .length ;
2456
2454
2457
- final int handle = factory .resultSets .add (new CachedContentFile (tempFile ));
2455
+ final int handle = factory .resultSets .add (new CachedContentFile (tempFile , filePool :: returnObject ));
2458
2456
result .put ("handle" , Integer .toString (handle ));
2459
2457
result .put ("supports-long-offset" , Boolean .TRUE );
2460
2458
} else {
2461
- tempFile . close ( );
2459
+ filePool . returnObject ( tempFile );
2462
2460
}
2463
2461
result .put ("offset" , offset );
2464
2462
return result ;
0 commit comments