Z3950Client { public Iterable<byte[]> search(String query) throws Z3950ClientException { this.query = query; try { InitializeResponse_type conn = connect(host, port); logConnection(conn, host, port); if (!conn.result.booleanValue()) { throw new Z3950ClientException(this, "Connection failed."); } SearchResponse_type search = find(query); logSearchResponse(search); List<NamePlusRecord_type> result = Collections.emptyList(); if (search.records != null && search.numberOfRecordsReturned.intValue() > 0) { result = getRecords(search.records); } SearchResult searchResult = new SearchResult( Math.min(MAX_RESULTS, search.resultCount.intValue()), search.nextResultSetPosition.intValue(), result); return searchResult; } catch (Z3950ClientException ex) { throw ex; } catch (Exception ex) { throw new Z3950ClientException(this, ex); } } Z3950Client(String host, int port, String base); void close(); Iterable<byte[]> search(String query); static Document toMarcXml(byte[] marc21, String charset); @Override String toString();  }
@Test public void testSearch() throws Exception { String query = System.getProperty("Z3950ClientTest.testSearch.query"); Assume.assumeNotNull(query); Z3950Client client = new Z3950Client(host, Integer.parseInt(port), base); try { Iterable<byte[]> search = client.search(query); assertNotNull(search); assertTrue(search.iterator().hasNext()); Transformer t = TransformerFactory.newInstance().newTransformer(); for (byte[] content : search) { Document marcxml = Z3950Client.toMarcXml(content, "cp1250"); StringWriter dump = new StringWriter(); t.transform(new DOMSource(marcxml), new StreamResult(dump)); System.out.println("MarcXML:\n" + dump); } } finally { client.close(); } }