Examples of DespotifyException


Examples of se.despotify.exceptions.DespotifyException

    PacketType packetType;
    int payloadLength, headerLength = 3, macLength = 4;

    /* Read header. */
    if(this.receive(header, headerLength, log.isDebugEnabled() ? "packet header" : null) != headerLength){
      throw new DespotifyException("Failed to read header.");
    }

    /* Set IV. */
    this.session.shannonRecv.nonce(IntegerUtilities.toBytes(this.session.keyRecvIv));

    /* Decrypt header. */
    this.session.shannonRecv.decrypt(header);

    /* Get command and payload length from header. */
    ByteBuffer headerBuffer = ByteBuffer.wrap(header);

    byte commandByte = headerBuffer.get();
    packetType = PacketType.valueOf(commandByte & 0xff);

    if (packetType == null) {
      log.info("Unknown command in received packet: " + packetType + " 0x" + Hex.toHex(new byte[]{commandByte}));
      // todo should we just ignore these?
    }

    payloadLength = headerBuffer.getShort() & 0xffff;

    /* Allocate buffer. Account for MAC. */
    byte[]     bytes  = new byte[payloadLength + macLength];
    ByteBuffer buffer = ByteBuffer.wrap(bytes);

    /* Limit buffer to payload length, so we can read the payload. */
    buffer.limit(payloadLength);

    try{
      for(int n = payloadLength, r; n > 0 && (r = this.channel.read(buffer)) > 0; n -= r);
    }
    catch(IOException e){
      throw new DespotifyException("Failed to read payload: " + e.getMessage());
    }

    /* Extend it again to payload and mac length. */
    buffer.limit(payloadLength + macLength);

    try{
      for(int n = macLength, r; n > 0 && (r = this.channel.read(buffer)) > 0; n -= r);
    }
    catch(IOException e){
      throw new DespotifyException("Failed to read MAC: " + e.getMessage());
    }

    /* Decrypt payload. */
    this.session.shannonRecv.decrypt(bytes);

 
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

        log.info("sent "+packetDescription+", "+array.length+" bytes:\n" + Hex.log(array, log));
      }

    }
    catch (IOException e){
      throw new DespotifyException("Error writing data to socket: " + e.getMessage());
    }
  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

      }

      return b & 0xff;
    }
    catch(IOException e){
      throw new DespotifyException("Error reading data from socket: " + e.getMessage());
    }
  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    try{
      for(int r; n < len && (r = this.channel.read(buffer)) > 0; n += r);
    }
    catch(IOException e){
      throw new DespotifyException("Error reading data from socket: " + e.getMessage());
    }

    if (packetDescription != null && log.isInfoEnabled()) {
      byte[] arr = buffer.array();
      log.info("received " + packetDescription + ", " + n + " bytes:\n" + Hex.log(arr, off, n, log));
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    XMLElement root = XML.load(xml);

    if (root.getElement().getNodeName().equals("artist")) {
      Artist.fromXMLElement(root, store);
    } else {
      throw new DespotifyException("Root element is not named <artist>: " + root.getElement().getNodeName());
    }


    artist.setLoaded(new Date());
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    // load tracks


    if (!"album".equals(root.getElement().getNodeName())) {
      throw new DespotifyException("Expected document root to be of type <album>");
    }
    Album album = Album.fromXMLElement(root, store);
    if (this.album != album) {
      throw new DespotifyException("Album in response has different UUID than the requested album!");
    }

    album.setLoaded(new Date());

    return true;
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

  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. */
 
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    Channel.register(channel);
    connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists");
    byte[] data = callback.getData("user playlists response");

    if (data.length == 0) {
      throw new DespotifyException("received an empty response!");
    }

    String xml =
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><playlist>" +
      new String(data, Charset.forName("UTF-8")) +
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

   */
  @Override
  public Track send(Connection connection) throws DespotifyException {

    if (!playlist.isCollaborative() && !playlist.getAuthor().equals(user.getId())) {
      throw new DespotifyException("Playlist must be collaborative or owned by the current user!");
    }

    if (user.getPlaylists() == null) {
      new LoadUserPlaylists(store, user).send(connection);
    }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    playlist.setName(playlistName);
    playlist.setId(hexUUID);
    if (new CreatePlaylistWithReservedUUID(store, user, playlist).send(connection)) {
      return playlist;
    } else {
      throw new DespotifyException();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.