@@ -175,7 +175,14 @@ public virtual Stream RetrieveStyleSheet(String uri) {
175
175
[ Obsolete ]
176
176
public virtual byte [ ] RetrieveStream ( String src ) {
177
177
try {
178
- return StreamUtil . InputStreamToArray ( RetrieveResourceAsInputStream ( src ) ) ;
178
+ using ( Stream stream = RetrieveResourceAsInputStream ( src ) ) {
179
+ if ( stream != null ) {
180
+ return StreamUtil . InputStreamToArray ( stream ) ;
181
+ }
182
+ else {
183
+ return null ;
184
+ }
185
+ }
179
186
}
180
187
catch ( Exception e ) {
181
188
ILog logger = LogManager . GetLogger ( typeof ( iText . StyledXmlParser . Resolver . Resource . ResourceResolver ) ) ;
@@ -194,19 +201,20 @@ public virtual byte[] RetrieveStream(String src) {
194
201
/// <param name="src">either link to file or base64 encoded stream.</param>
195
202
/// <returns>byte[] on success, otherwise null.</returns>
196
203
public virtual byte [ ] RetrieveBytesFromResource ( String src ) {
197
- Stream stream = RetrieveResourceAsInputStream ( src ) ;
198
- if ( stream != null ) {
199
- try {
200
- return StreamUtil . InputStreamToArray ( stream ) ;
201
- }
202
- catch ( System . IO . IOException ioe ) {
203
- ILog logger = LogManager . GetLogger ( typeof ( iText . StyledXmlParser . Resolver . Resource . ResourceResolver ) ) ;
204
- logger . Error ( MessageFormatUtil . Format ( iText . StyledXmlParser . LogMessageConstant . UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI
205
- , uriResolver . GetBaseUri ( ) , src ) , ioe ) ;
206
- return null ;
204
+ try {
205
+ using ( Stream stream = RetrieveResourceAsInputStream ( src ) ) {
206
+ if ( stream != null ) {
207
+ return StreamUtil . InputStreamToArray ( stream ) ;
208
+ }
209
+ else {
210
+ return null ;
211
+ }
207
212
}
208
213
}
209
- else {
214
+ catch ( System . IO . IOException ioe ) {
215
+ ILog logger = LogManager . GetLogger ( typeof ( iText . StyledXmlParser . Resolver . Resource . ResourceResolver ) ) ;
216
+ logger . Error ( MessageFormatUtil . Format ( iText . StyledXmlParser . LogMessageConstant . UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI
217
+ , uriResolver . GetBaseUri ( ) , src ) , ioe ) ;
210
218
return null ;
211
219
}
212
220
}
0 commit comments