Package hamsam.exception

Examples of hamsam.exception.IllegalArgumentException


   * @throws IllegalArgumentException if the data does not form a valid packet.
   */
  public Packet(char[] data) throws IllegalArgumentException
  {
    if(data.length < 20)
      throw new IllegalArgumentException("Yahoo packet is too small, size = " + data.length);

    /* header starts with 'YMSG' */
    if(data[0] != 'Y' || data[1] != 'M' || data[2] != 'S' || data[3] != 'G')
      throw new IllegalArgumentException("Invalid yahoo packet header (No YMSG found)");

    /* get the version */
    version = ((long)toUnsigned(data[4]) << 24) +
          ((long)toUnsigned(data[5]) << 16) +
          ((long)toUnsigned(data[6]) << 8) +
          toUnsigned(data[7]);

    /* get the length of the data portion */
    int dataLength = (toUnsigned(data[8]) << 8) + toUnsigned(data[9]);

    if(data.length != dataLength + 20)
      throw new IllegalArgumentException("Yahoo packet size is not correct, header specifies a packet size of " + (dataLength + 20) + ", but actual packet size is " + data.length);

    /* get the service type */
    service = (toUnsigned(data[10]) << 8) + toUnsigned(data[11]);

    /* get the status */
    status = ((long)toUnsigned(data[12]) << 24) +
          ((long)toUnsigned(data[13]) << 16) +
          ((long)toUnsigned(data[14]) << 8) +
          toUnsigned(data[15]);

    /* get the status */
    sessionID = ((long)toUnsigned(data[16]) << 24) +
          ((long)toUnsigned(data[17]) << 16) +
          ((long)toUnsigned(data[18]) << 8) +
          toUnsigned(data[19]);

    /* create the hashtable */
    boolean gettingKey = true;
    int key = 0, valueStart = 20;
    String value;

    int i = 20;
    while(i < data.length - 1)
    {
      int dataCurrent = toUnsigned(data[i]);
      int dataNext = toUnsigned(data[i + 1]);

      if(gettingKey)
      {
        // check for a key
        if(dataCurrent != 0xc0)
          key = key * 10 + dataCurrent - '0';
        else if(dataNext == 0x80)
        {
          gettingKey = false;
          valueStart = i + 2;
          i++;
        }
        else
          throw new IllegalArgumentException("Invalid packet (No end signature found)");
      }
      else
      {
        // get value
        if(dataCurrent == 0xc0 && dataNext == 0x80)
View Full Code Here


    /* Read the header */
    while(count != header.length)
    {
      int ret = conn.read(header, count, header.length - count);
      if(ret == -1)
        throw new IllegalArgumentException("Stream closed without enough data");
      count += ret;
    }

    /* header starts with 'YMSG' */
    if(header[0] != 'Y' || header[1] != 'M' || header[2] != 'S' || header[3] != 'G')
      throw new IllegalArgumentException("Invalid yahoo packet header (No YMSG found)");

    /* get the version */
    version = ((long)toUnsigned(header[4]) << 24) +
          ((long)toUnsigned(header[5]) << 16) +
          ((long)toUnsigned(header[6]) << 8) +
          toUnsigned(header[7]);

    /* get the length of the data portion */
    int dataLength = (toUnsigned(header[8]) << 8) + toUnsigned(header[9]);

    /* get the service type */
    service = (toUnsigned(header[10]) << 8) + toUnsigned(header[11]);

    /* get the status */
    status = ((long)toUnsigned(header[12]) << 24) +
          ((long)toUnsigned(header[13]) << 16) +
          ((long)toUnsigned(header[14]) << 8) +
          toUnsigned(header[15]);

    /* get the status */
    sessionID = ((long)toUnsigned(header[16]) << 24) +
          ((long)toUnsigned(header[17]) << 16) +
          ((long)toUnsigned(header[18]) << 8) +
          toUnsigned(header[19]);

    /* now load the data portion */
    byte[] dataArray = new byte[dataLength];
    count = 0;

    while(count != dataArray.length)
    {
      count += conn.read(dataArray, count, dataArray.length - count);
    }

    /* create the hashtable */
    boolean gettingKey = true;
    int key = 0, valueStart = 0;
    String value;

    int i = 0;
    while(i < count - 1)
    {
      int data = toUnsigned(dataArray[i]);
      int dataNext = toUnsigned(dataArray[i + 1]);

      if(gettingKey)
      {
        // check for a key
        if(data != 0xc0)
          key = key * 10 + data - '0';
        else if(dataNext == 0x80)
        {
          gettingKey = false;
          valueStart = i + 2;
          i++;
        }
        else
          throw new IllegalArgumentException("Invalid packet (No end signature found)");
      }
      else
      {
        // get value
        if(data == 0xc0 && dataNext == 0x80)
View Full Code Here

   */
  void addBuddyToForwardList(Buddy buddy) throws IllegalArgumentException
  {
    String group = buddy.getGroup();
    if(group == null)
      throw new IllegalArgumentException("Group name of the buddy is not specified");

    Command add = new Command("ADD");
    add.addParam("FL");

    String username = buddy.getUsername();
View Full Code Here

   */
  void removeBuddyFromForwardList(Buddy buddy) throws IllegalArgumentException
  {
    String group = buddy.getGroup();
    if(group == null)
      throw new IllegalArgumentException("Group name of the buddy is not specified");

    Command add = new Command("REM");
    add.addParam("FL");

    String username = buddy.getUsername();
View Full Code Here

    pack.putData(1, yahooID);
    pack.putData(7, buddy.getUsername());

    String group = buddy.getGroup();
    if(group == null)
      throw new IllegalArgumentException("Buddy's group is unknown.");
     
    pack.putData(65, group);

    sendToWriterThread(pack);
  }
View Full Code Here

    pack.putData(1, yahooID);
    pack.putData(7, buddy.getUsername());

    String group = buddy.getGroup();
    if(group == null)
      throw new IllegalArgumentException("Buddy's group is unknown.");
     
    pack.putData(65, group);

    sendToWriterThread(pack);
  }
View Full Code Here

   * @throws IllegalArgumentException If <code>type</code> is <code>DIRECT</code>.
   */
  public ProxyInfo(int type, String serverName, int serverPort) throws IllegalArgumentException
  {
    if(type == DIRECT)
      throw new IllegalArgumentException("Proxy type can not be DIRECT.");

    this.type = type;
    this.serverName = serverName;
    this.serverPort = serverPort;
    this.username = null;
View Full Code Here

   */
  public void changeStatus(String status) throws IllegalArgumentException, IllegalStateException
  {
    String code = Util.getStatusCode(status);
    if(code == null)
      throw new IllegalArgumentException("Invalid status message - " + status);

    if(server instanceof NotificationServer)
    {
      NotificationServer ns = (NotificationServer) server;
      ns.changeStatus(code);
View Full Code Here

     */
    public FlapHeader(byte[] bytes) throws IllegalArgumentException {
        super();

        if (bytes == null || bytes.length < FLAP_HDR_LENGTH) {
            throw new IllegalArgumentException("FlapHeader constructor bytes parm length must be " + FLAP_HDR_LENGTH);
        }

        // check for preamble byte value
        if (bytes[0] != FlapConstants.FLAP_PREAMBLE) {
            throw new IllegalArgumentException("FlagHeader first byte=" + Integer.toHexString(bytes[0]) + " and not 0x2A");
        }

        channelId = bytes[1];

        //set the sequence number and data length from the bytes
View Full Code Here

    {
      this.buddies = new Vector();
      this.protocol = protocol;

      if(host.getProtocol() != protocol)
        throw new IllegalArgumentException("Protocol is not same for all participants");
      this.host = host;

      for(int i = 0; i < buddies.length; i++)
        if(buddies[i].getProtocol() != protocol)
          throw new IllegalArgumentException("Protocol is not same for all participants");
        else
          addParticipant(buddies[i]);

    }
    else
View Full Code Here

TOP

Related Classes of hamsam.exception.IllegalArgumentException

Copyright © 2018 www.massapicom. 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.