Package org.gudy.azureus2.core3.util

Examples of org.gudy.azureus2.core3.util.DirectByteBuffer


    PooledByteBuffer            data,
    final DiskManagerWriteRequestListener  listener )
 
    throws DiskManagerException
  {
    DirectByteBuffer buffer = ((PooledByteBufferImpl)data).getBuffer();
       
    if ( !disk_manager.checkBlockConsistencyForWrite( "plugin", piece_number, offset, buffer )){
     
      throw( new DiskManagerException( "write invalid - parameters incorrect" ));
    }
   
    final int  length = buffer.remaining( DirectByteBuffer.SS_EXTERNAL );
   
    final DMWR request = new DMWR( disk_manager.createWriteRequest( piece_number, offset, buffer, null ),length );
   
    disk_manager.enqueueWriteRequest(
      request.getDelegate(),
View Full Code Here


    }
   
    ByteBuffer[] bbs = plug_msg.getRawPayload();
    DirectByteBuffer[] dbbs = new DirectByteBuffer[ bbs.length ]//TODO cache it???
    for( int i=0; i < bbs.length; i++ ) {
      dbbs[i] = new DirectByteBuffer( bbs[i] );
    }
    return dbbs;
  }
View Full Code Here

      connection.setTimeStamp();
     
      SocketChannel  chan1 = sc;
      SocketChannel  chan2 = sc==source_channel?target_channel:source_channel;
     
      DirectByteBuffer  read_buffer = sc==source_channel?source_buffer:target_buffer;
                 
      int  len = read_buffer.read( DirectByteBuffer.SS_PROXY, chan1 );
     
      if ( len == -1 ){
       
          //means that the channel has been shutdown
       
        connection.close();
       
      }else{
       
        if ( read_buffer.position( DirectByteBuffer.SS_PROXY ) > 0 ){
         
          read_buffer.flip(DirectByteBuffer.SS_PROXY);
         
          int  written = read_buffer.write( DirectByteBuffer.SS_PROXY, chan2 );
                 
          if ( chan1 == source_channel ){
           
            outward_bytes += written;
           
          }else{
           
            inward_bytes += written;
          }
         
          if ( read_buffer.hasRemaining(DirectByteBuffer.SS_PROXY)){
           
            connection.cancelReadSelect( chan1 );
           
            connection.requestWriteSelect( chan2 );
           
          }else{
           
            read_buffer.position(DirectByteBuffer.SS_PROXY, 0);
           
            read_buffer.limit( DirectByteBuffer.SS_PROXY, read_buffer.capacity(DirectByteBuffer.SS_PROXY));
          }
        }
      }
     
      return( len > 0 );
View Full Code Here

        // so if SX = source_channel then BX is target buffer
     
      SocketChannel  chan1 = sc;
      SocketChannel  chan2 = sc==source_channel?target_channel:source_channel;
     
      DirectByteBuffer  read_buffer = sc==source_channel?target_buffer:source_buffer;
     
      int written = read_buffer.write( DirectByteBuffer.SS_PROXY, chan1 );
           
      if ( chan1 == target_channel ){
       
        outward_bytes += written;
       
      }else{
       
        inward_bytes += written;
      }
     
      if ( read_buffer.hasRemaining(DirectByteBuffer.SS_PROXY)){
               
        connection.requestWriteSelect( chan1 );
       
      }else{
       
        read_buffer.position(DirectByteBuffer.SS_PROXY,0);
       
        read_buffer.limit( DirectByteBuffer.SS_PROXY, read_buffer.capacity(DirectByteBuffer.SS_PROXY));
       
        connection.requestReadSelect( chan2 );
      }
     
      return( written > 0 );
View Full Code Here

    int payload_size = 0;
    for( int i=0; i < payload.length; i++ ) {
      payload_size += payload[i].remaining( DirectByteBuffer.SS_MSG );
   
       
    DirectByteBuffer header = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_MSG_BT_HEADER, 5 );
    header.putInt( DirectByteBuffer.SS_MSG, 1 + payload_size );
    header.put( DirectByteBuffer.SS_MSG, ld.bt_id );
    header.flip( DirectByteBuffer.SS_MSG );
   
    DirectByteBuffer[] raw_buffs = new DirectByteBuffer[ payload.length + 1 ];
    raw_buffs[0] = header;
    for( int i=0; i < payload.length; i++ ) {
      raw_buffs[i+1] = payload[i];
View Full Code Here

     
      decoder.addMessage( new BTHandshake( control.getHash(), peer_id, false, (byte)1 ));
     
      byte[]  bits = new byte[(control.getPieces().length +7) /8];
     
      DirectByteBuffer buffer = new DirectByteBuffer( ByteBuffer.wrap( bits ));
     
      decoder.addMessage( new BTBitfield( buffer, (byte)1 ));
    }
   
    synchronized( outstanding_requests ){
View Full Code Here

   
        http_request.setSentFirstReply();
           
        String  header = encodeHeader( http_request );
     
        buffers[0] = new DirectByteBuffer( ByteBuffer.wrap( header.getBytes()));
     
      }else{
     
          // we have to do this as core code assumes buffer entry 0 is protocol
     
        buffers[0] = new DirectByteBuffer( ByteBuffer.allocate(0));
      }
         
      req  = (pendingRequest)ready_requests.get(i);

      BTPiece  this_piece = req.getBTPiece();
View Full Code Here

    Message  message )
  {   
    return(
      new RawMessageImpl(
          message,
          new DirectByteBuffer[]{ new DirectByteBuffer( ByteBuffer.allocate(0))},
          RawMessage.PRIORITY_HIGH,
          true,
          new Message[0] ));
  }
View Full Code Here

      payload_size += payload[i].remaining( bss );
    }
      
    //create and fill header buffer
   
    DirectByteBuffer header;
   
    if ( version >= MESSAGE_VERSION_SUPPORTS_PADDING ){
         
      boolean enable_padding = padding_mode != AZMessageEncoder.PADDING_MODE_NONE;
     
      short   padding_length;
     
      if ( enable_padding ){
       
        if ( padding_mode == AZMessageEncoder.PADDING_MODE_MINIMAL ){
         
             padding_length = (short)(( Math.random() * SMALL_PAD_MAX  ));

        }else{
         
          padding_length = (short)(( Math.random() * ( payload_size>256?SMALL_PAD_MAX:BIG_PAD_MAX )));
        }
       
        if ( padding_length == 0 ){
         
          enable_padding = false;
        }
      }else{
       
        padding_length = 0;
      }
             
      byte  flags = enable_padding?(byte)0x01:(byte)0x00;
     
      int  header_size = 4 + 4 + id_bytes.length + 1 + (enable_padding?(2+padding_length):0);
     
        header = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_MSG_AZ_HEADER, header_size );
       
      header.putInt( bss, header_size - 4 + payload_size );
      header.putInt( bss, id_bytes.length );
      header.put( bss, id_bytes );
     
      byte version_and_flags = (byte)( ( flags << 4 ) | version );
     
      header.put( bss, version_and_flags );
     
      if ( enable_padding ){
       
        byte[]  padding = new byte[padding_length];
       
        header.putShort( bss, padding_length );
        header.put( bss, padding );
      }
    }else{
     
       int  header_size = 4 + 4 + id_bytes.length + 1;

      header = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_MSG_AZ_HEADER, header_size );
     
      header.putInt( bss, header_size - 4 + payload_size );
      header.putInt( bss, id_bytes.length );
      header.put( bss, id_bytes );
      header.put( bss, version );
    }
   
    header.flip( bss );
   
    DirectByteBuffer[] raw_buffs = new DirectByteBuffer[ payload.length + 1 ];
    raw_buffs[0] = header;
    for( int i=0; i < payload.length; i++ ) {
      raw_buffs[i+1] = payload[i];
View Full Code Here

          bToSend = bToSend << (8 - (i % 8));
         
          bits[pos++] = (byte)bToSend;
        }
               
        DirectByteBuffer buffer = new DirectByteBuffer( ByteBuffer.wrap( bits ));

        connection.getOutgoingMessageQueue().addMessage(
          new BTBitfield( buffer, BTMessageFactory.MESSAGE_VERSION_INITIAL ),
          false );
      }
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.util.DirectByteBuffer

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.