Package reactor.io

Examples of reactor.io.Buffer$View


  @Test
  @Ignore
  public void clockRegexExtraction() {
    final String[] months = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    final Pattern pattern = Pattern.compile("([A-Z][a-z]{2})[\\s]+(\\d{1,2})[\\s](\\d{2}):(\\d{2}):(\\d{2})");
    final Buffer date = Buffer.wrap("Oct 11 22:14:15");

    Consumer<Integer> test = new Consumer<Integer>() {
      Calendar cal = Calendar.getInstance();

      @Override
      public void accept(Integer integer) {
        Matcher m = pattern.matcher(date.asString());
        m.matches();

        int month = Arrays.binarySearch(months, m.group(1));
        int day = Integer.valueOf(m.group(2));
        int hr = Integer.valueOf(m.group(2));
View Full Code Here


            ch.consume(new Consumer<Frame>() {
              @Override
              public void accept(Frame frame) {
                short prefix = frame.getPrefix().readShort();
                assertThat("prefix is 0", prefix == 0);
                Buffer data = frame.getData();
                assertThat("len is 128", data.remaining() == 128);

                latch.countDown();
              }
            });
          }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Override
  protected void write(Object data, Promise<Void> onComplete, boolean flush) {
    Buffer buff = getEncoder().apply((OUT) data);
    write(buff.byteBuffer(), onComplete, flush);
  }
View Full Code Here

    @Override
    public void accept(OUT data) {
      try {
        if (null != encoder) {
          Buffer bytes = encoder.apply(data);
          if (bytes.remaining() > 0) {
            write(bytes, onComplete, autoflush);
          }
        } else {
          if (Buffer.class.isInstance(data)) {
            write((Buffer) data, onComplete, autoflush);
View Full Code Here

    @Override
    public Buffer apply(String s) {
      try {
        ByteBuffer bb = encoder.encode(CharBuffer.wrap(s));
        return new Buffer(bb);
      } catch (CharacterCodingException e) {
        throw new IllegalStateException(e);
      }
    }
View Full Code Here

  }

  private Buffer writeTypeName(Class<?> type, byte[] bytes) {
    String typeName = type.getName();
    int len = typeName.length();
    Buffer buffer = new Buffer(4 + len + bytes.length, true);
    return buffer.append(len)
                 .append(typeName)
                 .append(bytes)
                 .flip();

  }
View Full Code Here

    public Buffer apply(OUT out) {
      if(null == out) {
        return null;
      }

      Buffer encoded = encoder.apply(out);
      if(null != encoded && encoded.remaining() > 0) {
        int len = encoded.remaining();
        ByteBuffer bb = null;
        if(lengthFieldLength == 4) {
          bb = ByteBuffer.allocate(len + 4);
          bb.putInt(len);
        } else if(lengthFieldLength == 2) {
          bb = ByteBuffer.allocate(len + 2);
          bb.putShort((short)len);
        } else if(lengthFieldLength == 8) {
          bb = ByteBuffer.allocate(len + 8);
          bb.putLong((long)len);
        }
        if(null != bb) {
          bb.put(encoded.byteBuffer()).flip();
          return new Buffer(bb);
        }
      }
      return encoded;
    }
View Full Code Here

      int limit = bytes.limit();
      int position = bytes.position();

      for (Buffer.View view : views) {
        Buffer b = view.get();
        decoder.apply(b);
      }

      bytes.limit(limit);
      bytes.position(position);
View Full Code Here

    Function<OUT, Buffer> encoder = delegate.encoder();

    @Override
    @SuppressWarnings("resource")
    public Buffer apply(OUT out) {
      Buffer buffer = new Buffer();
      Buffer encoded = encoder.apply(out);
      if (null != encoded && encoded.remaining() > 0) {
        buffer.append(encoded).append(delimiter);
      }
      return buffer.flip();
    }
View Full Code Here

      @Override
      public IN apply(Buffer buffer) {
        try {
          ByteArrayInputStream bin = new ByteArrayInputStream(buffer.asBytes());
          InputStream zin = createInputStream(bin);
          Buffer newBuff = new Buffer();
          while(zin.available() > 0) {
            newBuff.append((byte)zin.read());
          }
          zin.close();
          IN in = delegate.decoder(null).apply(newBuff.flip());
          if(null != next) {
            next.accept(in);
            return null;
          } else {
            return in;
View Full Code Here

TOP

Related Classes of reactor.io.Buffer$View

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.