[
https://issues.apache.org/jira/browse/IO-893?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18131973#comment-18131973
]
Kapil Verma commented on IO-893:
--------------------------------
Thank you!
> BOMInputStream: problems with keep track of last read position for
> ByteArrayInputStream
> ---------------------------------------------------------------------------------------
>
> Key: IO-893
> URL: https://issues.apache.org/jira/browse/IO-893
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.22.0
> Environment: openJdk 24
> junit-jupiter-api-5.10.1
> Reporter: Kapil Verma
> Priority: Major
> Fix For: 2.23.0
>
> Attachments: CommonsIOTest.java
>
>
> The following test case fails with commons-io-2.22.0. It passes in 2.21.0 and
> earlier versions.[^CommonsIOTest.java]
> {code:java}
> @Test
> public void testCommonsIO() throws IOException {
> String text = "<?xml version='1.0' encoding='UTF-8'?>\n"
> + "<xbrli:xbrl
> xmlns='http://www.xbrl.org/2003/instance'";
>
> InputStream i = new ByteArrayInputStream(text
> .getBytes("UTF-8"));
> BOMInputStream is = BOMInputStream.builder().setInputStream(i)
> .setByteOrderMarks(ByteOrderMark.UTF_8,
> ByteOrderMark.UTF_16BE,
> ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE,
> ByteOrderMark.UTF_32LE)
> .setInclude(false).get();
>
> is.reset();
>
> String str1 = new String(read(is, new byte[4]));
>
> byte[] b2 = new byte[64];
> is.read(b2, 0, 64);
>
> String str2 = str1 + new String(b2);
> System.out.print(str2);
>
> assertTrue(str2.startsWith("<?xml version"), "String does not
> start with \"<?xml version\"");
> }
>
> public byte[] read(BOMInputStream is, byte[] b) throws IOException {
> for(int i=0; i<4; i++) {
> int bit = is.read();
> if(bit == -1) {
> break;
> }
> b[i] = (byte)bit;
> }
> return b;
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)