Package org.glassfish.tyrus.core

Examples of org.glassfish.tyrus.core.StrictUtf8$Encoder


  {
    CommandMessage commandMessage = new CommandMessage();
    commandMessage.setOperation( CommandMessage.LOGIN_OPERATION );

    String credString = username + ":" + password;
    Encoder encoder = new Encoder( credString.length() );
    encoder.encode( credString.getBytes() );

    commandMessage.setBody( encoder.drain() );
    commandMessage.setDestination( DESTINATION );
    return commandMessage;
  }
View Full Code Here


    private CommandMessage createLoginCommandMessage() {
        CommandMessage commandMessage = new CommandMessage();
        commandMessage.setOperation(CommandMessage.LOGIN_OPERATION);

        String credString = username + ":" + password;
        Encoder encoder = new Encoder(credString.length());
        encoder.encode(credString.getBytes());

        commandMessage.setBody(encoder.drain());
        commandMessage.setDestination(DESTINATION);
        return commandMessage;
    }
View Full Code Here

    pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
    pHandler.startElement("", BASE_64_TAG, BASE_64_TAG, ZERO_ATTRIBUTES);
    byte[] buffer = (byte[]) pObject;
    if (buffer.length > 0) {
      char[] charBuffer = new char[buffer.length >= 1024 ? 1024 : ((buffer.length+3)/4)*4];
      Encoder encoder = new Base64.SAXEncoder(charBuffer, 0, null, pHandler);
      try {
        encoder.write(buffer, 0, buffer.length);
        encoder.flush();
      } catch (Base64.SAXIOException e) {
        throw e.getSAXException();
      } catch (IOException e) {
        throw new SAXException(e);
      }
View Full Code Here

  public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
    pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
    pHandler.startElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG, ZERO_ATTRIBUTES);
    char[] buffer = new char[1024];
    Encoder encoder = new Base64.SAXEncoder(buffer, 0, null, pHandler);
    try {
      OutputStream ostream = new EncoderOutputStream(encoder);
      ObjectOutputStream oos = new ObjectOutputStream(ostream);
      oos.writeObject(pObject);
      oos.close();
View Full Code Here

    pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
    pHandler.startElement("", BASE_64_TAG, BASE_64_TAG, ZERO_ATTRIBUTES);
    byte[] buffer = (byte[]) pObject;
    if (buffer.length > 0) {
      char[] charBuffer = new char[buffer.length >= 1024 ? 1024 : ((buffer.length+3)/4)*4];
      Encoder encoder = new Base64.SAXEncoder(charBuffer, 0, null, pHandler);
      try {
        encoder.write(buffer, 0, buffer.length);
        encoder.flush();
      } catch (Base64.SAXIOException e) {
        throw e.getSAXException();
      } catch (IOException e) {
        throw new SAXException(e);
      }
View Full Code Here

  public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
    pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
    pHandler.startElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG, ZERO_ATTRIBUTES);
    char[] buffer = new char[1024];
    Encoder encoder = new Base64.SAXEncoder(buffer, 0, null, pHandler);
    try {
      OutputStream ostream = new EncoderOutputStream(encoder);
      ObjectOutputStream oos = new ObjectOutputStream(ostream);
      oos.writeObject(pObject);
      oos.close();
View Full Code Here

  public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
    pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
    pHandler.startElement("", BASE_64_TAG, BASE_64_TAG, ZERO_ATTRIBUTES);
    byte[] buffer = (byte[]) pObject;
    char[] charBuffer = new char[buffer.length >= 1024 ? 1024 : ((buffer.length+3)/4)*4];
    Encoder encoder = new Base64.SAXEncoder(charBuffer, 0, null, pHandler);
    try {
      encoder.write(buffer, 0, buffer.length);
      encoder.flush();
    } catch (Base64.SAXIOException e) {
      throw e.getSAXException();
    } catch (IOException e) {
      throw new SAXException(e);
    }
View Full Code Here

     * @param continuation {@code true} when this frame is continuation frame, {@code false} otherwise.
     * @param fin          {@code true} when this frame is last in current partial message batch. Standard (non-continuous)
     *                     frames have this bit set to {@code true}.
     */
    public TextFrame(String message, boolean continuation, boolean fin) {
        super(Frame.builder().payloadData(encode(new StrictUtf8(), message)).opcode(continuation ? (byte) 0x00 : (byte) 0x01).fin(fin).build(), continuation ? FrameType.TEXT_CONTINUATION : FrameType.TEXT);
        this.continuation = continuation;
        this.textPayload = message;
    }
View Full Code Here

    }

    private String utf8Decode(byte[] data) {
        String reason;
        final ByteBuffer b = ByteBuffer.wrap(data, 2, data.length - 2);
        Charset charset = new StrictUtf8();
        final CharsetDecoder decoder = charset.newDecoder();
        int n = (int) (b.remaining() * decoder.averageCharsPerByte());
        CharBuffer cb = CharBuffer.allocate(n);
        while (true) {
            CoderResult result = decoder.decode(b, cb, true);
            if (result.isUnderflow()) {
View Full Code Here

        if (closeCode == -1) {
            return EMPTY_BYTES;
        }

        final byte[] bytes = Utils.toArray(closeCode);
        final byte[] reasonBytes = closeReason == null ? EMPTY_BYTES : closeReason.getBytes(new StrictUtf8());
        final byte[] frameBytes = new byte[2 + reasonBytes.length];
        System.arraycopy(bytes, bytes.length - 2, frameBytes, 0, 2);
        System.arraycopy(reasonBytes, 0, frameBytes, 2, reasonBytes.length);

        return frameBytes;
View Full Code Here

TOP

Related Classes of org.glassfish.tyrus.core.StrictUtf8$Encoder

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.