}
/* Search music. The response comes as GZIP compressed XML. */
public void sendSearchQuery(ChannelListener listener, String query, int offset, int limit) throws DespotifyException {
/* Create channel and buffer. */
Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, listener);
ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + query.getBytes().length);
/* Check offset and limit. */
if(offset < 0){
throw new IllegalArgumentException("Offset needs to be >= 0");
}
else if((limit < 0 && limit != -1) || limit == 0){
throw new IllegalArgumentException("Limit needs to be either -1 for no limit or > 0");
}
/* Append channel id, some values, query length and query. */
buffer.putShort((short)channel.getId());
buffer.putInt(offset); /* Result offset. */
buffer.putInt(limit); /* Reply limit. */
buffer.putShort((short)0x0000);
buffer.put((byte)query.length());
buffer.put(query.getBytes());