public Boolean send(Connection connection) throws DespotifyException {
// todo send multiple requests if more than 200 tracks!
if (tracks.length > 240) {
throw new DespotifyException("Can only load up to 240 track at the time.");
}
/* Create channel callback */
ChannelCallback callback = new ChannelCallback();
/* Send browse request. */
/* Create channel and buffer. */
Channel channel = new Channel("Browse-Channel", Channel.Type.TYPE_BROWSE, callback);
ByteBuffer buffer = ByteBuffer.allocate(2 + 1 + tracks.length * 16); //+ ((type == BrowseType.artist || type == BrowseType.album)?4:0));
// if(ids.size() > 1 && type != BrowseType.track){
// throw new IllegalArgumentException("Only BrowserType.track accepts multiple ids.");
// }
/* Append channel id and type. */
buffer.putShort((short) channel.getId());
buffer.put((byte)BrowseType.track.getValue());
/* Append (16 byte) ids. */
for (Track track : tracks) {
buffer.put(Arrays.copyOfRange(track.getByteUUID(), 0, 16));
}
// /* Append zero. */
// if(type == BrowseType.artist || type == BrowseType.album){
// buffer.putInt(0);
// }
buffer.flip();
/* Register channel. */
Channel.register(channel);
/* Send packet. */
connection.getProtocol().sendPacket(PacketType.browse, buffer, "load track");
/* Get data and inflate it. */
byte[] data = GZIP.inflate(callback.getData("gzipped load track response"));
if (log.isInfoEnabled()) {
log.info("load track response, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
}
if (data.length == 0) {
throw new DespotifyException("Received an empty response");
}
/* Cut off that last 0xFF byte... */
data = Arrays.copyOfRange(data, 0, data.length - 1);
/* Load XML. */