|
28 | 28 | import java.net.URL; |
29 | 29 | import java.net.URLConnection; |
30 | 30 | import java.nio.file.Files; |
| 31 | +import java.nio.file.Path; |
31 | 32 | import java.text.MessageFormat; |
32 | 33 | import java.util.Locale; |
33 | 34 | import java.util.Objects; |
@@ -275,9 +276,8 @@ static boolean isTextXml(final String mime) { |
275 | 276 | * @param file File to create a Reader from. |
276 | 277 | * @throws IOException thrown if there is a problem reading the file. |
277 | 278 | */ |
278 | | - @SuppressWarnings("resource") // FileInputStream is managed through another reader in this instance. |
279 | 279 | public XmlStreamReader(final File file) throws IOException { |
280 | | - this(Files.newInputStream(Objects.requireNonNull(file, "file").toPath())); |
| 280 | + this(Objects.requireNonNull(file, "file").toPath()); |
281 | 281 | } |
282 | 282 |
|
283 | 283 | /** |
@@ -387,7 +387,6 @@ public XmlStreamReader(final InputStream inputStream, final String httpContentTy |
387 | 387 | this(inputStream, httpContentType, true); |
388 | 388 | } |
389 | 389 |
|
390 | | - |
391 | 390 | /** |
392 | 391 | * Creates a Reader using an InputStream and the associated content-type |
393 | 392 | * header. This constructor is lenient regarding the encoding detection. |
@@ -426,6 +425,7 @@ public XmlStreamReader(final InputStream inputStream, final String httpContentTy |
426 | 425 | this(inputStream, httpContentType, lenient, null); |
427 | 426 | } |
428 | 427 |
|
| 428 | + |
429 | 429 | /** |
430 | 430 | * Creates a Reader using an InputStream and the associated content-type |
431 | 431 | * header. This constructor is lenient regarding the encoding detection. |
@@ -471,6 +471,24 @@ public XmlStreamReader(final InputStream inputStream, final String httpContentTy |
471 | 471 | this.reader = new InputStreamReader(pis, encoding); |
472 | 472 | } |
473 | 473 |
|
| 474 | + /** |
| 475 | + * Creates a Reader for a File. |
| 476 | + * <p> |
| 477 | + * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset, |
| 478 | + * if this is also missing defaults to UTF-8. |
| 479 | + * <p> |
| 480 | + * It does a lenient charset encoding detection, check the constructor with |
| 481 | + * the lenient parameter for details. |
| 482 | + * |
| 483 | + * @param file File to create a Reader from. |
| 484 | + * @throws IOException thrown if there is a problem reading the file. |
| 485 | + * @since 2.11.0 |
| 486 | + */ |
| 487 | + @SuppressWarnings("resource") // InputStream is managed through another reader in this instance. |
| 488 | + public XmlStreamReader(final Path file) throws IOException { |
| 489 | + this(Files.newInputStream(Objects.requireNonNull(file, "file"))); |
| 490 | + } |
| 491 | + |
474 | 492 | /** |
475 | 493 | * Creates a Reader using the InputStream of a URL. |
476 | 494 | * <p> |
|
0 commit comments