merged BOM functionality in XMLtools
This commit is contained in:
@@ -98,7 +98,7 @@ public class XMLTools extends XMLWriter {
|
|||||||
* @param is the ByteArrayInputStream used
|
* @param is the ByteArrayInputStream used
|
||||||
* @throws IOException if can not be read from is
|
* @throws IOException if can not be read from is
|
||||||
* @see <a href="https://www.w3.org/TR/xml/#sec-guessing">Autodetection of Character Encodings</a>
|
* @see <a href="https://www.w3.org/TR/xml/#sec-guessing">Autodetection of Character Encodings</a>
|
||||||
*/
|
*
|
||||||
public static int guessBOMSize(ByteArrayInputStream is) throws IOException {
|
public static int guessBOMSize(ByteArrayInputStream is) throws IOException {
|
||||||
byte[] pad = new byte[4];
|
byte[] pad = new byte[4];
|
||||||
is.read(pad);
|
is.read(pad);
|
||||||
@@ -118,7 +118,7 @@ public class XMLTools extends XMLWriter {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* removes utf8 byte order marks from byte arrays, in case one is there
|
* removes utf8 byte order marks from byte arrays, in case one is there
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class ZUGFeRDImporter {
|
|||||||
xmlFact.setNamespaceAware(false);
|
xmlFact.setNamespaceAware(false);
|
||||||
DocumentBuilder builder = xmlFact.newDocumentBuilder();
|
DocumentBuilder builder = xmlFact.newDocumentBuilder();
|
||||||
ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
|
ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
|
||||||
is.skip(guessBOMSize(is));
|
/// is.skip(guessBOMSize(is));
|
||||||
document = builder.parse(is);
|
document = builder.parse(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,33 +187,6 @@ public class ZUGFeRDImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Skips over a BOM at the beginning of the given ByteArrayInputStream, if one exists.
|
|
||||||
*
|
|
||||||
* @param is the ByteArrayInputStream used
|
|
||||||
* @throws IOException if can not be read from is
|
|
||||||
* @see <a href="https://www.w3.org/TR/xml/#sec-guessing">Autodetection of Character Encodings</a>
|
|
||||||
*/
|
|
||||||
private int guessBOMSize(ByteArrayInputStream is) throws IOException {
|
|
||||||
byte[] pad = new byte[4];
|
|
||||||
is.read(pad);
|
|
||||||
is.reset();
|
|
||||||
int test2 = ((pad[0] & 0xFF) << 8) | (pad[1] & 0xFF);
|
|
||||||
int test3 = ((test2 & 0xFFFF) << 8) | (pad[2] & 0xFF);
|
|
||||||
int test4 = ((test3 & 0xFFFFFF) << 8) | (pad[3] & 0xFF);
|
|
||||||
//
|
|
||||||
if (test4 == 0x0000FEFF || test4 == 0xFFFE0000 || test4 == 0x0000FFFE || test4 == 0xFEFF0000) {
|
|
||||||
// UCS-4: BOM takes 4 bytes
|
|
||||||
return 4;
|
|
||||||
} else if (test3 == 0xEFBBFF) {
|
|
||||||
// UTF-8: BOM takes 3 bytes
|
|
||||||
return 3;
|
|
||||||
} else if (test2 == 0xFEFF || test2 == 0xFFFE) {
|
|
||||||
// UTF-16: BOM takes 2 bytes
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected String extractString(String xpathStr) {
|
protected String extractString(String xpathStr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user