Codota Logo
Message
Code IndexAdd Codota to your IDE (free)

How to use
Message
in
com.wizzardo.http.websocket

Best Java code snippets using com.wizzardo.http.websocket.Message (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: wizzardo/http

public void broadcast(CommandPojo command) {
  broadcast(new Message()
      .append(command.getClass().getSimpleName())
      .append(JsonTools.serializeToBytes(command))
  );
}
origin: com.wizzardo/simple-websocket-client

public Message append(byte[] bytes, int offset, int length) {
  add(new Frame(bytes, offset, length));
  return this;
}
origin: com.wizzardo/simple-websocket-client

public String asString() {
  return new String(asBytes(), UTF_8);
}
origin: com.wizzardo/simple-websocket-client

public byte[] asBytes() {
  byte[] data = new byte[getBytesLength()];
  asBytes(data);
  return data;
}
origin: com.wizzardo/simple-websocket-client

public Message(String message) {
  append(message);
}
origin: com.wizzardo/simple-websocket-client

public void waitForMessage() throws IOException {
  if (!connectIfNot())
    return;
  while (!message.isComplete()) {
    if (!onFrame(readFrame()))
      break;
  }
  if (!message.isComplete())
    return;
  try {
    onMessage(message);
  } catch (Exception e) {
    onError(e);
  }
  message = new Message();
}
origin: wizzardo/http

    continue;
  message.add(frame);
  this.tempFrame = null;
if (message.isComplete()) {
  webSocketHandler.onMessage(this, message);
  releaseByteBuffers(message);
  message.clear();
origin: wizzardo/http

public void broadcast(byte[] bytes, int offset, int length) {
  broadcast(new Message(bytes, offset, length));
}
origin: com.wizzardo/simple-websocket-client

  @Override
  public void run() throws IOException {
    for (Frame frame : message.getFrames()) {
      frame.mask().write(out);
    }
    out.flush();
  }
});
origin: wizzardo/http

  @Override
  public void onMessage(Message message) {
    messageHolder.set(message.asString());
  }
};
origin: com.wizzardo/simple-websocket-client

public Message(byte[] message, int offset, int length) {
  append(message, offset, length);
}
origin: com.wizzardo/simple-websocket-client

out.flush();
message = new Message();
limit = 0;
int response = 0;
origin: wizzardo/http

public synchronized void sendMessage(Message message) {
  for (Frame frame : message.getFrames()) {
    connection.write(convertFrameToReadableData(frame), (ByteBufferProvider) Thread.currentThread());
  }
}
origin: wizzardo/http

  @Override
  public void onMessage(Message message) {
    messageHolder.set(message.asString());
  }
};
origin: wizzardo/http

@Test
public void testFrames() throws IOException, URISyntaxException, InterruptedException {
  handler = new WebSocketHandler() {
    @Override
    public void onMessage(WebSocketListener listener, Message message) {
      listener.sendMessage(message);
    }
  };
  AtomicReference<String> messageHolder = new AtomicReference<>();
  SimpleWebSocketClient client = new SimpleWebSocketClient("ws://localhost:" + getPort()) {
    @Override
    public void onMessage(Message message) {
      messageHolder.set(message.asString());
    }
  };
  Message message = new Message().append("foo").append(" ").append("bar");
  client.send(message);
  client.waitForMessage();
  Assert.assertEquals("foo bar", messageHolder.get());
}
origin: com.wizzardo/simple-websocket-client

public Message(byte[] message) {
  append(message);
}
origin: com.wizzardo/simple-websocket-client

public void onMessage(T listener, Message message) {
  try {
    byte[] bytes = message.asBytes();
    int[] holder = new int[1];
    int position = readInt(holder, bytes, 0, bytes.length);
    int nameLength = holder[0];
    String commandName;
    if (nameLength != -1) {
      commandName = new String(bytes, position, nameLength);
    } else {
      position = 0;
      nameLength = indexOf((byte) '{', bytes, position, bytes.length);
      commandName = new String(bytes, position, nameLength);
    }
    int offset = position + nameLength;
    Map.Entry<Class<? extends CommandPojo>, CommandHandler<? extends T, ? extends CommandPojo>> commandHandlerPair = handlers.get(commandName);
    if (commandHandlerPair == null)
      throw new IllegalArgumentException("Unknown command: " + commandName);
    CommandHandler<T, CommandPojo> handler = (CommandHandler<T, CommandPojo>) commandHandlerPair.getValue();
    Class<? extends CommandPojo> commandClass = commandHandlerPair.getKey();
    CommandPojo command = (CommandPojo) reader.read(commandClass, bytes, offset, bytes.length - offset);
    handler.handle(listener, command);
  } catch (Exception e) {
    onError(e);
  }
}
origin: wizzardo/http

protected void releaseByteBuffers(Message message) {
  for (Frame frame : message.getFrames()) {
    ((ByteArrayHolder) frame.getByteArraySupplier()).release(webSocketHandler.byteArrayHolderPool);
  }
}
origin: com.wizzardo/simple-websocket-client

protected boolean onFrame(Frame frame) {
  if (frame.isPing())
    return true;
  if (frame.isClose()) {
    connected = false;
    onClose();
    return false;
  }
  message.add(frame);
  return true;
}
origin: wizzardo/http

@Override
public void onMessage(WebSocketListener listener, Message message) {
  if ("close".equals(message.asString()))
    listener.close();
}
com.wizzardo.http.websocketMessage

Most used methods

  • <init>
  • append
  • add
  • asBytes
  • getFrames
  • isComplete
  • asString
  • clear
  • getBytesLength

Popular in Java

  • Start an intent from android
  • setScale (BigDecimal)
  • addToBackStack (FragmentTransaction)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Notification (javax.management)
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Option (scala)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now