@Test public void test() throws Exception { Result result = new Search(store, "Johnny Cash").send(manager); assertTrue(result.getTotalTracks() > 2000); assertEquals(100, result.getTracks().size()); System.currentTimeMillis(); }
public Result send(ConnectionManager connectionManager) throws DespotifyException { ChannelCallback callback = new ChannelCallback(); byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8")); Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback); ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length); if (offset < 0) { throw new IllegalArgumentException("Offset needs to be >= 0"); } buffer.putShort((short) channel.getId()); buffer.putInt(offset); buffer.putInt(maxResults); buffer.putShort((short) 0x0000); buffer.put((byte) utf8Bytes.length); buffer.put(utf8Bytes); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = callback.getData("gzipped search response"); connection.close(); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"result".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <result>"); } Result result = responseUnmarshaller.unmarshallSearchResult(); xmlr.close(); return result; } catch (XMLStreamException e) { throw new DespotifyException(e); } catch (IOException e) { throw new DespotifyException(e); } }
Search extends Command<Result> { public Result send(ConnectionManager connectionManager) throws DespotifyException { ChannelCallback callback = new ChannelCallback(); byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8")); Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback); ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length); if (offset < 0) { throw new IllegalArgumentException("Offset needs to be >= 0"); } buffer.putShort((short) channel.getId()); buffer.putInt(offset); buffer.putInt(maxResults); buffer.putShort((short) 0x0000); buffer.put((byte) utf8Bytes.length); buffer.put(utf8Bytes); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = callback.getData("gzipped search response"); connection.close(); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"result".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <result>"); } Result result = responseUnmarshaller.unmarshallSearchResult(); xmlr.close(); return result; } catch (XMLStreamException e) { throw new DespotifyException(e); } catch (IOException e) { throw new DespotifyException(e); } } }
Search extends Command<Result> { public Result send(ConnectionManager connectionManager) throws DespotifyException { ChannelCallback callback = new ChannelCallback(); byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8")); Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback); ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length); if (offset < 0) { throw new IllegalArgumentException("Offset needs to be >= 0"); } buffer.putShort((short) channel.getId()); buffer.putInt(offset); buffer.putInt(maxResults); buffer.putShort((short) 0x0000); buffer.put((byte) utf8Bytes.length); buffer.put(utf8Bytes); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = callback.getData("gzipped search response"); connection.close(); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"result".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <result>"); } Result result = responseUnmarshaller.unmarshallSearchResult(); xmlr.close(); return result; } catch (XMLStreamException e) { throw new DespotifyException(e); } catch (IOException e) { throw new DespotifyException(e); } } Search(Store store, String query);  Search(Store store, String query, int offset, int maxResults); }
Search extends Command<Result> { public Result send(ConnectionManager connectionManager) throws DespotifyException { ChannelCallback callback = new ChannelCallback(); byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8")); Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback); ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length); if (offset < 0) { throw new IllegalArgumentException("Offset needs to be >= 0"); } buffer.putShort((short) channel.getId()); buffer.putInt(offset); buffer.putInt(maxResults); buffer.putShort((short) 0x0000); buffer.put((byte) utf8Bytes.length); buffer.put(utf8Bytes); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = callback.getData("gzipped search response"); connection.close(); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"result".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <result>"); } Result result = responseUnmarshaller.unmarshallSearchResult(); xmlr.close(); return result; } catch (XMLStreamException e) { throw new DespotifyException(e); } catch (IOException e) { throw new DespotifyException(e); } } Search(Store store, String query);  Search(Store store, String query, int offset, int maxResults); Result send(ConnectionManager connectionManager); }
Search extends Command<Result> { public Result send(ConnectionManager connectionManager) throws DespotifyException { ChannelCallback callback = new ChannelCallback(); byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8")); Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback); ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length); if (offset < 0) { throw new IllegalArgumentException("Offset needs to be >= 0"); } buffer.putShort((short) channel.getId()); buffer.putInt(offset); buffer.putInt(maxResults); buffer.putShort((short) 0x0000); buffer.put((byte) utf8Bytes.length); buffer.put(utf8Bytes); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = callback.getData("gzipped search response"); connection.close(); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"result".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <result>"); } Result result = responseUnmarshaller.unmarshallSearchResult(); xmlr.close(); return result; } catch (XMLStreamException e) { throw new DespotifyException(e); } catch (IOException e) { throw new DespotifyException(e); } } Search(Store store, String query);  Search(Store store, String query, int offset, int maxResults); Result send(ConnectionManager connectionManager);  }