Skip to content

Commit afcdaed

Browse files
Merge pull request Samuel-Oliveira#250 from tryflaviosantos/feature/stream-fix-with-try-resources
Feature/stream fix with try resources
2 parents 45e82c5 + ea91257 commit afcdaed

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
/target/
1+
2+
target/
3+
.idea/
4+
*.iml
5+
/target/

src/main/java/br/com/swconsultoria/nfe/Assinar.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,16 @@ private static void loadCertificates(ConfiguracoesNfe config, XMLSignatureFactor
157157

158158
private static String outputXML(Document doc) throws NfeException {
159159

160-
try {
161-
ByteArrayOutputStream os = new ByteArrayOutputStream();
160+
try (ByteArrayOutputStream os = new ByteArrayOutputStream()){
162161
TransformerFactory tf = TransformerFactory.newInstance();
163162
Transformer trans = tf.newTransformer();
164163
trans.transform(new DOMSource(doc), new StreamResult(os));
165164
String xml = os.toString();
166165
xml = xml.replaceAll("\\r\\n", "");
167166
xml = xml.replaceAll(" standalone=\"no\"", "");
168167
return xml;
169-
} catch (TransformerException e) {
170-
throw new NfeException("Erro ao Transformar Documento:" + e.getMessage());
168+
} catch (TransformerException | IOException e) {
169+
throw new NfeException("Erro ao Transformar Documento:" + e.getMessage(),e);
171170
}
172-
173171
}
174-
175172
}

0 commit comments

Comments
 (0)