fix: correct loading for plain text XML files (PR #2537)

This commit is contained in:
Jan S.
2025-06-16 20:26:35 +02:00
committed by GitHub
parent ecb597a461
commit 1bb645d676
2 changed files with 19 additions and 5 deletions
@@ -65,7 +65,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
resourceIds = null;
is = new ParserStream(inputStream);
if (!isBinaryXml()) {
return ResourcesLoader.loadToCodeWriter(inputStream);
return ResourcesLoader.loadToCodeWriter(is);
}
nsMapGenerated = new HashSet<>();
nsMap = new HashMap<>();
@@ -9,7 +9,7 @@ import java.nio.charset.StandardCharsets;
import org.jetbrains.annotations.NotNull;
public class ParserStream {
public class ParserStream extends InputStream {
protected static final Charset STRING_CHARSET_UTF16 = StandardCharsets.UTF_16LE;
protected static final Charset STRING_CHARSET_UTF8 = StandardCharsets.UTF_8;
@@ -88,7 +88,8 @@ public class ParserStream {
return arr;
}
public void skip(long count) throws IOException {
@Override
public long skip(long count) throws IOException {
readPos += count;
long pos = input.skip(count);
while (pos < count) {
@@ -98,6 +99,7 @@ public class ParserStream {
}
pos += skipped;
}
return pos;
}
public void checkInt8(int expected, String error) throws IOException {
@@ -140,14 +142,16 @@ public class ParserStream {
checkPos(expectedOffset, error);
}
public void mark(int len) throws IOException {
@Override
public void mark(int len) {
if (!input.markSupported()) {
throw new IOException("Mark not supported for input stream " + input.getClass());
throw new RuntimeException("Mark not supported for input stream " + input.getClass());
}
input.mark(len);
markPos = readPos;
}
@Override
public void reset() throws IOException {
input.reset();
readPos = markPos;
@@ -172,6 +176,16 @@ public class ParserStream {
}
}
@Override
public int read() throws IOException {
return input.read();
}
@Override
public int read(@NotNull byte[] b, int off, int len) throws IOException {
return input.read(b, off, len);
}
@Override
public String toString() {
return "pos: 0x" + Long.toHexString(readPos);