Package etch.util

Examples of etch.util.FlexBuffer


  /** @throws Exception */
  @Test
  public void doubleSingle_HeaderSplit_Data1() throws Exception
  {
    // length = 1
    FlexBuffer buf = new FlexBuffer( new byte[]
    {
      // packet 1 header (partial):
      -34, -83, -66, -17, 0, 0
    } );

    p.sessionData( who, buf );

    assertNull( session.what );
    assertTrue( session.check( null ) );
    assertNull( session.sender );

    FlexBuffer buf2 = new FlexBuffer( new byte[]
    {
      // packet 1 header (remainder):
        0, 1,
        // packet 1 data:
        1,
View Full Code Here


  /** @throws Exception */
  @Test
  public void doubleSingle_HeaderSplit_Data2() throws Exception
  {
    // length = 2
    FlexBuffer buf = new FlexBuffer( new byte[]
    {
      -34, -83, -66, -17, 0, 0
    } );

    p.sessionData( who, buf );

    assertNull( session.what );
    assertTrue( session.check( null ) );
    assertNull( session.sender );

    FlexBuffer buf2 = new FlexBuffer( new byte[]
    {
        0, 2, 3, 4, -34, -83, -66, -17, 0, 0, 0, 2, 5, 6
    } );
    byte[][] result2 = new byte[][]
    {
View Full Code Here

  /** @throws Exception */
  @Test
  public void doubleSingle_BodySplit_Data2() throws Exception
  {
    // length = 2
    FlexBuffer buf = new FlexBuffer( new byte[]
    {
      -34, -83, -66, -17, 0, 0, 0, 2, 1
    } );

    p.sessionData( who, buf );

    assertNull( session.what );
    assertTrue( session.check( null ) );
    assertNull( session.sender );

    FlexBuffer buf2 = new FlexBuffer( new byte[]
    {
        2, -34, -83, -66, -17, 0, 0, 0, 2, 3, 4
    } );
    byte[][] result2 = new byte[][]
    {
View Full Code Here

  /** @throws Exception */
  @Test
  public void doubleSingle_BodySplit_Data3() throws Exception
  {
    // length = 3
    FlexBuffer buf = new FlexBuffer( new byte[]
    {
      -34, -83, -66, -17, 0, 0, 0, 3, 5, 6
    } );

    p.sessionData( who, buf );

    assertNull( session.what );
    assertTrue( session.check( null ) );
    assertNull( session.sender );

    FlexBuffer buf2 = new FlexBuffer( new byte[]
    {
        7, -34, -83, -66, -17, 0, 0, 0, 3, 8, 9, 10
    } );
    byte[][] result2 = new byte[][]
    {
View Full Code Here

    final InputStream is = inputStream;
    if (is == null)
      throw new IOException( "socket closed" );
   
    // TODO allow setting input buffer size.
    final FlexBuffer buf = new FlexBuffer( new byte[8192] );
   
    try
    {
      while (isStarted())
      {
//        System.out.println( "reading" );
        int n = is.read( buf.getBuf() );
//        System.out.println( "read "+n );
       
        if (n <= 0)
          break;
       
        buf.setLength( n );
        buf.setIndex( 0 );
        fireData( buf );
      }
    }
    catch ( SocketException e )
    {
View Full Code Here

  @Override
  protected void readSocket() throws Exception
  {
    final DatagramSocket s = checkSocket();
    // TODO allow buffer size to be specified.
    final FlexBuffer buf = new FlexBuffer( new byte[8192] );
    final DatagramPacket p = new DatagramPacket( new byte[0], 0 );
   
    try
    {
      while (isStarted())
      {
        p.setData( buf.getBuf() );
       
        s.receive( p );
       
        buf.setIndex( 0 );
        buf.setLength( p.getLength() );
       
        if (s.isConnected())
          session.sessionPacket( null, buf );
        else
          session.sessionPacket( getWho( p.getAddress(), p.getPort() ), buf );
View Full Code Here

    final InputStream is = inputStream;
    if (is == null)
      throw new IOException( "socket closed" );
   
    // TODO allow setting input buffer size.
    final FlexBuffer buf = new FlexBuffer( new byte[8192] );
   
    try
    {
      while (isStarted())
      {
//        System.out.println( "reading" );
        int n = is.read( buf.getBuf() );
//        System.out.println( "read "+n );
       
        if (n <= 0)
          break;
       
        buf.setLength( n );
        buf.setIndex( 0 );
        fireData( buf );
      }
    }
    catch ( SSLHandshakeException ex )
    {
View Full Code Here

   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    c.transportData( null, new FlexBuffer( new byte[] { 21, 22, 23 } ) );
//    c.flush();
   
    assertEquals( 21, read( t ) );
    assertEquals( 22, read( t ) );
    assertEquals( 23, read( t ) );
View Full Code Here

  @Test @Ignore
  public void blah() throws Exception
  {
    assertEquals( What.UP, aph.what );
    assertEquals( What.UP, bph.what );
    FlexBuffer buf = new FlexBuffer();
    buf.put( 1 );
    buf.put( 2 );
    buf.put( 3 );
    buf.put( 4 );
    buf.put( 5 );
    buf.setIndex( 0 );
    ac.transportPacket( null, buf );
    Thread.sleep( 500 );
    assertEquals( What.PACKET, bph.what );
    assertNotNull( bph.xsender );
    assertNotSame( buf, bph.xbuf );
View Full Code Here

   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    c.transportData( null, new FlexBuffer( new byte[] { 21, 22, 23 } ) );
    c.flush();
   
    InputStream is = t.getInputStream();
    assertEquals( 21, is.read() );
    assertEquals( 22, is.read() );
View Full Code Here

TOP

Related Classes of etch.util.FlexBuffer

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.