Package net.bnubot.util

Examples of net.bnubot.util.ByteArray


    }

    if(text.length() == 0)
      return;

    ByteArray baPrefix = null;
    if(prefix != null)
      baPrefix = new ByteArray(prefix);
    enqueueChat(baPrefix, text, priority);
  }
View Full Code Here


    boolean firstPiece = (current_position == 0);

    // This is the pieceSize accomadating for the unprepended ellipsis
    int maxByteCount = (firstPiece ? pieceSize : pieceSize - 3);

    ByteArray piece = new ByteArray(text.substring(current_position, current_position + chars_pulled));
    while(piece.length() > maxByteCount) {
      // Estimate that we need to remove half the overflow, since most unicode chars are 2-bytes
      int deltaEstimate = (piece.length() - pieceSize + 1) / 2;
      // Don't remove less than 1 character
      if(deltaEstimate < 1)
        deltaEstimate = 1;
      Out.debug(getClass(), "deltaEstimate=" + deltaEstimate);
      chars_pulled -= deltaEstimate;
      piece = new ByteArray(text.substring(current_position, current_position + chars_pulled));
    }

    boolean lastPiece = (current_position + chars_pulled >= text.length());
    if(!lastPiece) {
      // This is not the last piece; append ellipsis
      chars_pulled -= 3;
      piece = new ByteArray(text.substring(current_position, current_position + chars_pulled)).concat("...".getBytes());
    }

    if(!firstPiece) {
      // This is not the first piece; prepend ellipsis
      piece = new ByteArray("...".getBytes()).concat(piece);
    }

    // Cryptos
    if(enabledCryptos != 0)
      piece = GenericCrypto.encode(piece, enabledCryptos);
View Full Code Here

  public static ByteArray decode(ByteArray text) {
    if(text.length() <= 1)
      return text;

    switch(text.byteAt(0)) {
    case (byte)0xB7: return new ByteArray("{Reverse} ").concat(decode(ReverseCrypto.decode(text.removeFirst())));
    case (byte)0xB8: return new ByteArray("{MC} ").concat(decode(MCCrypto.decode(text.removeFirst())));
    case (byte)0xA4: return new ByteArray("{DM} ").concat(decode(DMCrypto.decode(text.removeFirst())));
    case (byte)0xA3:
      try {
        return new ByteArray("{HEX} ").concat(decode(HexDump.decode(text.removeFirst())));
      } catch(Exception e) {
        return new ByteArray("{INVALID HEX} ").concat(text);
      }
    case (byte)0xE6: return new ByteArray("{B64} ").concat(decode(Base64.decode(text.removeFirst())));
    }
    return text;
  }
View Full Code Here

    return text;
  }

  public static ByteArray encode(ByteArray data, int crypto) {
    if((crypto & CRYPTO_REVERSE) != 0)
      data = new ByteArray((byte)0xB7).concat(ReverseCrypto.encode(data));
    if((crypto & CRYPTO_MC) != 0)
      data = new ByteArray((byte)0xB8).concat(MCCrypto.encode(data));
    if((crypto & CRYPTO_DM) != 0)
      data = new ByteArray((byte)0xA4).concat(DMCrypto.encode(data));
    if((crypto & CRYPTO_HEX) != 0)
      data = new ByteArray((byte)0xA3).concat(HexDump.encode(data));
    if((crypto & CRYPTO_BASE64) != 0)
      data = new ByteArray((byte)0xE6).concat(Base64.encode(data));
    return data;
  }
View Full Code Here

   *
   * @param in an array containing the data bytes to be encoded.
   * @return A character array with the Base64 encoded data.
   */
  public static ByteArray encode(ByteArray in) {
    return new ByteArray(encode(in.getBytes(), in.length()));
  }
View Full Code Here

   * @param s a Base64 String to be decoded.
   * @return A String containing the decoded data.
   * @throws IllegalArgumentException if the input is not valid Base64 encoded data.
   */
  public static ByteArray decode(ByteArray s) {
    return new ByteArray(decode(s.getBytes()));
  }
View Full Code Here

        }
        case PACKET_BOTNETCHAT: {
          int command = is.readDWord();
          int action = is.readDWord();
          BotNetUser user = users.get(is.readDWord());
          ByteArray data = new ByteArray(is.readNTBytes());

          switch(command) {
          case 0: //broadcast
            // TODO: change this to recieveBroadcast()
            dispatchRecieveChat(user, data);
            break;
          case 1: // chat
            if(action == 0)
              dispatchRecieveChat(user, data);
            else
              dispatchRecieveEmote(user, data.toString());
            break;
          case 2: //whisper
            dispatchWhisperRecieved(user, data.toString());
            break;
          default:
            dispatchRecieveError("Unknown PACKET_BOTNETCHAT command 0x" + Integer.toHexString(command));
            disconnect(ConnectionState.LONG_PAUSE_BEFORE_CONNECT);
            break;
View Full Code Here

  public static ByteArray encode(ByteArray data) {
    String output = new String();
    for(byte element : data.getBytes())
      output += toHex(element);
    return new ByteArray(output.getBytes());
  }
View Full Code Here

   * @param text Text to send
   * @throws Exception
   */
  public void sendChat(boolean emote, String text) throws Exception {
    sendBotNetChat(1, emote, 0, text);
    super.dispatchRecieveChat(myUser, new ByteArray(text));
  }
View Full Code Here

      output[offset] = decode(data[pos++], data[pos++]);
    return output;
  }

  public static ByteArray decode(ByteArray data) throws Exception {
    return new ByteArray(decode(data.getBytes(), 0, data.length()));
  }
View Full Code Here

TOP

Related Classes of net.bnubot.util.ByteArray

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.