File tree Expand file tree Collapse file tree 5 files changed +42
-8
lines changed
itext.tests/itext.io.tests/itext/io/util
itext.styledxmlparser/itext/styledxmlparser/resolver/resource Expand file tree Collapse file tree 5 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -42,9 +42,11 @@ source product.
42
42
*/
43
43
using System ;
44
44
using System . IO ;
45
+ using System . Net ;
45
46
using System . Text ;
46
47
using iText . Commons . Utils ;
47
48
using iText . Test ;
49
+ using NUnit . Framework ;
48
50
49
51
namespace iText . IO . Util {
50
52
public class UrlUtilTest : ExtendedITextTest {
@@ -64,6 +66,27 @@ public virtual void GetFinalURLDoesNotLockFileTest() {
64
66
NUnit . Framework . Assert . IsTrue ( FileUtil . DeleteFile ( tempFile ) ) ;
65
67
}
66
68
69
+ // This test checks that when we pass invalid url and trying get stream related to final redirected url,exception
70
+ // would be thrown.
71
+ [ NUnit . Framework . Test ]
72
+ public virtual void GetInputStreamOfFinalConnectionThrowExceptionTest ( ) {
73
+ Uri invalidUrl = new Uri ( "http://itextpdf" ) ;
74
+
75
+ NUnit . Framework . Assert . That ( ( ) => {
76
+ UrlUtil . GetInputStreamOfFinalConnection ( invalidUrl ) ;
77
+ } , NUnit . Framework . Throws . InstanceOf < WebException > ( ) ) ;
78
+ }
79
+
80
+ // This test checks that when we pass valid url and trying get stream related to final redirected url, it would
81
+ // not be null.
82
+ [ NUnit . Framework . Test ]
83
+ public virtual void GetInputStreamOfFinalConnectionTest ( ) {
84
+ Uri initialUrl = new Uri ( "http://itextpdf.com" ) ;
85
+ Stream streamOfFinalConnectionOfInvalidUrl = UrlUtil . GetInputStreamOfFinalConnection ( initialUrl ) ;
86
+
87
+ NUnit . Framework . Assert . NotNull ( streamOfFinalConnectionOfInvalidUrl ) ;
88
+ }
89
+
67
90
[ NUnit . Framework . Test ]
68
91
public void GetBaseUriTest ( ) {
69
92
String absolutePathRoot = new Uri ( new Uri ( "file://" ) , destinationFolder ) . AbsoluteUri ;
Original file line number Diff line number Diff line change @@ -114,8 +114,10 @@ public static Uri ToNormalizedURI(FileInfo file) {
114
114
/// <summary>
115
115
/// This method gets the last redirected url.
116
116
/// </summary>
117
- /// <param name="uri">an initial url</param>
118
- /// <returns>the last redirected url</returns>
117
+ /// <param name="uri">an initial url.</param>
118
+ ///
119
+ /// <returns>the last redirected url.</returns>
120
+ [ Obsolete ]
119
121
public static Uri GetFinalURL ( Uri uri ) {
120
122
return uri ;
121
123
}
@@ -139,5 +141,16 @@ public static String GetNormalizedFileUriString(String filename)
139
141
{
140
142
return "file://" + UrlUtil . ToNormalizedURI ( filename ) . AbsolutePath ;
141
143
}
144
+
145
+ /// <summary>
146
+ /// Gets the input stream of connection related to last redirected url. You should manually close input stream after
147
+ /// calling this method to not hold any open resources.
148
+ /// </summary>
149
+ /// <param name="url">an initial URL.</param>
150
+ ///
151
+ /// <returns>an input stream of connection related to the last redirected url.</returns>
152
+ public static Stream GetInputStreamOfFinalConnection ( Uri url ) {
153
+ return UrlUtil . OpenStream ( url ) ;
154
+ }
142
155
}
143
156
}
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ public virtual Stream GetInputStreamByUrl(Uri url) {
96
96
, url ) ) ;
97
97
return null ;
98
98
}
99
- return new LimitedInputStream ( UrlUtil . OpenStream ( url ) , resourceSizeByteLimit ) ;
99
+ return new LimitedInputStream ( UrlUtil . GetInputStreamOfFinalConnection ( url ) , resourceSizeByteLimit ) ;
100
100
}
101
101
102
102
/// <summary>Gets the byte array that are retrieved from the source URL.</summary>
Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ source product.
46
46
using iText . Commons ;
47
47
using iText . Commons . Utils ;
48
48
using iText . IO . Image ;
49
- using iText . IO . Util ;
50
49
using iText . Kernel . Pdf . Xobject ;
51
50
52
51
namespace iText . StyledXmlParser . Resolver . Resource {
@@ -278,7 +277,6 @@ protected internal virtual PdfXObject TryResolveBase64ImageSource(String src) {
278
277
protected internal virtual PdfXObject TryResolveUrlImageSource ( String uri ) {
279
278
try {
280
279
Uri url = uriResolver . ResolveAgainstBaseUri ( uri ) ;
281
- url = UrlUtil . GetFinalURL ( url ) ;
282
280
String imageResolvedSrc = url . ToExternalForm ( ) ;
283
281
PdfXObject imageXObject = imageCache . GetImage ( imageResolvedSrc ) ;
284
282
if ( imageXObject == null ) {
@@ -295,11 +293,11 @@ protected internal virtual PdfXObject TryResolveUrlImageSource(String uri) {
295
293
}
296
294
297
295
/// <summary>Create a iText XObject based on the image stored at the passed location.</summary>
298
- /// <param name="url">location of the Image file</param>
296
+ /// <param name="url">location of the Image file. </param>
299
297
/// <returns>
300
298
///
301
299
/// <see cref="iText.Kernel.Pdf.Xobject.PdfXObject"/>
302
- /// containing the Image loaded in
300
+ /// containing the Image loaded in.
303
301
/// </returns>
304
302
protected internal virtual PdfXObject CreateImageByUrl ( Uri url ) {
305
303
byte [ ] bytes = retriever . GetByteArrayByUrl ( url ) ;
Original file line number Diff line number Diff line change 1
- 22758a9a14a188fe166c90befcc99fdbde473415
1
+ 0847044410e8b1c1eb0f1536d1ff2e282bc9d62d
You can’t perform that action at this time.
0 commit comments