Skip to content

Commit 66e1c77

Browse files
author
Thiago M Sayao
committed
Otimiza XML
1 parent b9ee7eb commit 66e1c77

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main/java/br/com/swconsultoria/nfe/util/XmlNfeUtil.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,15 @@ public static <T> String objectToXml(Object obj) throws JAXBException, NfeExcept
311311
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
312312
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
313313

314-
StringWriter sw = new StringWriter();
314+
StringWriter sw = new StringWriter(4096);
315+
sw.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
315316

316317
marshaller.marshal(element, sw);
317-
StringBuilder xml = new StringBuilder();
318-
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(sw.toString());
319318

320319
if ((obj.getClass().getSimpleName().equals(TPROCEVENTO))) {
321-
return replacesNfe(xml.toString().replaceAll("procEvento", "procEventoNFe"));
320+
return replacesNfe(sw.toString().replace("procEvento", "procEventoNFe"));
322321
} else {
323-
return replacesNfe(xml.toString());
322+
return replacesNfe(sw.toString());
324323
}
325324

326325
}

0 commit comments

Comments
 (0)