Skip to content

Commit 831e0fb

Browse files
committed
WIP 2
1 parent 120f601 commit 831e0fb

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

metafacture-io/src/main/java/org/metafacture/io/SruOpener.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.xml.sax.SAXException;
1616

1717
import java.io.ByteArrayInputStream;
18-
import java.io.ByteArrayOutputStream;
1918
import java.io.IOException;
2019
import java.io.InputStream;
2120
import java.io.InputStreamReader;
@@ -176,10 +175,10 @@ public void process(final String baseUrl) {
176175

177176
private InputStream getXmlDocsViaSru(final StringBuilder srUrl) {
178177
try {
179-
ByteArrayInputStream byteArrayInputStream = retrieve(srUrl, startRecord, maximumRecords);
178+
InputStream inputStreamOfURl = retrieveUrl(srUrl, startRecord, maximumRecords);
180179
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
181180
DocumentBuilder docBuilder = factory.newDocumentBuilder();
182-
Document xmldoc = docBuilder.parse(byteArrayInputStream);
181+
Document xmldoc = docBuilder.parse(inputStreamOfURl);
183182

184183
Transformer t = TransformerFactory.newInstance().newTransformer();
185184
StringWriter stringWriter = new StringWriter();
@@ -193,6 +192,7 @@ private InputStream getXmlDocsViaSru(final StringBuilder srUrl) {
193192
startRecord = nextRecordPosition; // grenzwert : wenn maximumRcords > als in echt
194193

195194
return new ByteArrayInputStream(stringWriter.toString().getBytes());
195+
196196
}
197197
catch (final IOException | TransformerException | SAXException | ParserConfigurationException e) {
198198
throw new MetafactureException(e);
@@ -207,7 +207,7 @@ private int getIntegerValueFromElement(final Document xmlDoc, final String tagNa
207207
return 0;
208208
}
209209

210-
private ByteArrayInputStream retrieve(StringBuilder srUrl, int startRecord, int maximumRecords) throws IOException {
210+
private InputStream retrieveUrl(StringBuilder srUrl, int startRecord, int maximumRecords) throws IOException {
211211
final URL urlToOpen =
212212
new URL(srUrl.toString() + "&maximumRecords=" + maximumRecords + "&startRecord=" + startRecord);
213213
final HttpURLConnection connection = (HttpURLConnection) urlToOpen.openConnection();
@@ -218,10 +218,7 @@ private ByteArrayInputStream retrieve(StringBuilder srUrl, int startRecord, int
218218
}
219219
InputStream inputStream = getInputStream(connection);
220220

221-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
222-
223-
inputStream.transferTo(outputStream);
224-
return new ByteArrayInputStream(outputStream.toByteArray());
221+
return inputStream;
225222
}
226223

227224
private InputStream getInputStream(final HttpURLConnection connection) {

metafacture-io/src/test/java/org/metafacture/io/SruOpenerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void process(final XmlReceiver obj) {
4444
// sruOpener.setQuery("WVN%3D24A05");
4545
sruOpener.setRecordSchema("MARC21plus-xml");
4646
sruOpener.setVersion("1.1");
47-
sruOpener.setStartRecord("2800");
48-
sruOpener.setMaximumRecords("200");
47+
sruOpener.setStartRecord("3029");
48+
sruOpener.setMaximumRecords("1");
4949
sruOpener.setTotal("1");
5050
// sruOpener.process("https://services.dnb.de/sru/dnb");
5151
sruOpener.process("https://services.dnb.de/sru/zdb");

0 commit comments

Comments
 (0)