Skip to content

Commit 207479a

Browse files
committed
close XML cursors
1 parent f601aff commit 207479a

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

src/main/java/org/kopi/ebics/xml/DefaultEbicsRootElement.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ public void insertSchemaLocation(String namespaceURI,
102102
String value)
103103
{
104104

105-
XmlCursor cursor = document.newCursor();
106-
while (cursor.hasNextToken()) {
107-
if (cursor.isStart()) {
108-
cursor.toNextToken();
109-
cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value);
110-
break;
111-
} else {
112-
cursor.toNextToken();
105+
try (XmlCursor cursor = document.newCursor()) {
106+
while (cursor.hasNextToken()) {
107+
if (cursor.isStart()) {
108+
cursor.toNextToken();
109+
cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix),
110+
value);
111+
break;
112+
} else {
113+
cursor.toNextToken();
114+
}
113115
}
114116
}
115117
}
@@ -149,18 +151,17 @@ public byte[] toByteArray() {
149151

150152
@Override
151153
public void addNamespaceDecl(String prefix, String uri) {
152-
XmlCursor cursor;
153-
154-
cursor = document.newCursor();
155-
while (cursor.hasNextToken()) {
156-
if (cursor.isStart()) {
157-
cursor.toNextToken();
158-
cursor.insertNamespace(prefix, uri);
159-
break;
160-
} else {
161-
cursor.toNextToken();
154+
try (XmlCursor cursor = document.newCursor()) {
155+
while (cursor.hasNextToken()) {
156+
if (cursor.isStart()) {
157+
cursor.toNextToken();
158+
cursor.insertNamespace(prefix, uri);
159+
break;
160+
} else {
161+
cursor.toNextToken();
162+
}
163+
}
162164
}
163-
}
164165
}
165166

166167
@Override
@@ -185,16 +186,14 @@ public void validate() throws EbicsException {
185186

186187
@Override
187188
public void save(OutputStream out) throws EbicsException {
188-
try {
189-
byte[] element;
190-
191-
element = prettyPrint();
192-
out.write(element);
193-
out.flush();
194-
out.close();
195-
} catch (IOException e) {
196-
throw new EbicsException(e.getMessage());
197-
}
189+
try {
190+
byte[] element = prettyPrint();
191+
out.write(element);
192+
out.flush();
193+
out.close();
194+
} catch (IOException e) {
195+
throw new EbicsException(e.getMessage());
196+
}
198197
}
199198

200199
@Override

0 commit comments

Comments
 (0)