@Test public void test() throws Exception { Result result = (Result)manager.send(new Search(store, "Johnny Cash")); assertTrue(result.getTotalTracks() > 2000); assertEquals(100, result.getTracks().size()); System.currentTimeMillis(); }
public Result send(Connection connection) 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); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = GZIP.inflate(callback.getData("gzipped search response")); if (log.isInfoEnabled()) { log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log)); } data = Arrays.copyOfRange(data, 0, data.length - 1); String xml = new String(data, Charset.forName("UTF-8")); if (log.isDebugEnabled()) { log.debug(xml); } XMLElement root = XML.load(xml); return Result.fromXMLElement(root, store); }
Search extends Command<Result> { public Result send(Connection connection) 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); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = GZIP.inflate(callback.getData("gzipped search response")); if (log.isInfoEnabled()) { log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log)); } data = Arrays.copyOfRange(data, 0, data.length - 1); String xml = new String(data, Charset.forName("UTF-8")); if (log.isDebugEnabled()) { log.debug(xml); } XMLElement root = XML.load(xml); return Result.fromXMLElement(root, store); } }
Search extends Command<Result> { public Result send(Connection connection) 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); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = GZIP.inflate(callback.getData("gzipped search response")); if (log.isInfoEnabled()) { log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log)); } data = Arrays.copyOfRange(data, 0, data.length - 1); String xml = new String(data, Charset.forName("UTF-8")); if (log.isDebugEnabled()) { log.debug(xml); } XMLElement root = XML.load(xml); return Result.fromXMLElement(root, store); } Search(Store store, String query);  Search(Store store, String query, int offset, int maxResults); }
Search extends Command<Result> { public Result send(Connection connection) 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); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = GZIP.inflate(callback.getData("gzipped search response")); if (log.isInfoEnabled()) { log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log)); } data = Arrays.copyOfRange(data, 0, data.length - 1); String xml = new String(data, Charset.forName("UTF-8")); if (log.isDebugEnabled()) { log.debug(xml); } XMLElement root = XML.load(xml); return Result.fromXMLElement(root, store); } Search(Store store, String query);  Search(Store store, String query, int offset, int maxResults); Result send(Connection connection); }
Search extends Command<Result> { public Result send(Connection connection) 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); connection.getProtocol().sendPacket(PacketType.search, buffer, "search"); byte[] data = GZIP.inflate(callback.getData("gzipped search response")); if (log.isInfoEnabled()) { log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log)); } data = Arrays.copyOfRange(data, 0, data.length - 1); String xml = new String(data, Charset.forName("UTF-8")); if (log.isDebugEnabled()) { log.debug(xml); } XMLElement root = XML.load(xml); return Result.fromXMLElement(root, store); } Search(Store store, String query);  Search(Store store, String query, int offset, int maxResults); Result send(Connection connection);  }