Package java.nio

Examples of java.nio.ByteBuffer


     
      if ( pending_partial_writes == null ){
       
        pending_partial_writes = new ByteBuffer[1];
               
        ByteBuffer  copy = ByteBuffer.allocate( buffer_rem );
       
        copy.put( buffer );
       
        copy.position( 0 );
       
        pending_partial_writes[0] = copy;
       
        return( buffer_rem );
       
      }else{
       
        int  queued = 0;
       
        for ( int i=0;i<pending_partial_writes.length;i++){
         
          queued += pending_partial_writes[i].remaining();
        }
       
        if ( queued + buffer_rem <= UDPConnectionSet.MAX_BUFFERED_PAYLOAD ){
         
          ByteBuffer[] new_ppw = new ByteBuffer[ pending_partial_writes.length+1 ];
         
          for (int i=0;i<pending_partial_writes.length;i++){
           
            new_ppw[i] = pending_partial_writes[i];
          }
         
          ByteBuffer  copy = ByteBuffer.allocate( buffer_rem );
         
          copy.put( buffer );
         
          copy.position( 0 );
         
          new_ppw[pending_partial_writes.length] = copy;
         
          pending_partial_writes = new_ppw;
         
View Full Code Here


   
      long  total = 0;
     
      for (int i=array_offset;i<array_offset+length;i++){
       
        ByteBuffer  buffer = buffers[i];
       
        int  max = buffer.remaining();
       
        int  read = connection.read( buffer );
       
        total += read;
       
View Full Code Here

    byte[] signature = new PngSignatureChunk().getChunkPayload();
    byte[] ihdr = new IHDRChunk(width,height).getChunkPayload();
    byte[] idat = new IDATChunk(width,height).getChunkPayload();
    byte[] iend = new IENDChunk().getChunkPayload();
   
    ByteBuffer buffer = ByteBuffer.allocate(signature.length + ihdr.length + idat.length + iend.length);
    buffer.put(signature);
    buffer.put(ihdr);
    buffer.put(idat);
    buffer.put(iend);
   
    buffer.position(0);
    return buffer.array();
  }
View Full Code Here

        if ( rem == 0 ){
         
          break;
        }

        ByteBuffer  b = (ByteBuffer)read_buffers.get(0);
               
        int  old_limit = b.limit();
       
        if ( b.remaining() > rem ){
         
          b.limit( b.position() + rem );
        }
       
        buffer.put( b );
       
        b.limit( old_limit );
       
        total += rem - buffer.remaining();
       
        if ( b.hasRemaining()){
         
          break;
         
        }else{
         
View Full Code Here

    boolean shrink_remaining_buffers = false;
    int start_buff = reading_length_mode ? 1 : 0;
    boolean marked = false;   
   
    for( int i = start_buff; i < 2; i++ ) {  //set buffer limits according to bytes allowed
      ByteBuffer bb = decode_array[ i ];
     
      if( bb == null ) {
        Debug.out( "preReadProcess:: bb["+i+"] == null, decoder destroyed=" +destroyed );
      }
     
     
      if( shrink_remaining_buffers ) {
        bb.limit( 0 )//ensure no read into this next buffer is possible
      }
      else {
        int remaining = bb.remaining();
       
        if( remaining < 1 continue//skip full buffer

        if( !marked ) {
          pre_read_start_buffer = i;
          pre_read_start_position = bb.position();
          marked = true;
        }

        if( remaining > allowed ) {  //read only part of this buffer
          bb.limit( bb.position() + allowed )//limit current buffer
          bytes_available += bb.remaining();
          shrink_remaining_buffers = true//shrink any tail buffers
        }
        else //full buffer is allowed to be read
          bytes_available += remaining;
          allowed -= remaining;  //count this buffer toward allowed and move on to the next
View Full Code Here

   
    if ( partial_write && delayed_write == null ){
     
      if ( buffer.remaining() < MAX_PARTIAL_WRITE_RETAIN ){
       
        ByteBuffer  copy = ByteBuffer.allocate( buffer.remaining());
       
        copy.put( buffer );
       
        copy.position( 0 );
       
        delayed_write = copy;
       
        return( copy.remaining());
      }
    }
   
    long  written = 0;
   
View Full Code Here

  /**
   * Set the message stream decoder that will be used to decode incoming messages.
   * @param new_stream_decoder to use
   */
  public void setDecoder( MessageStreamDecoder new_stream_decoder ) {
    ByteBuffer already_read = stream_decoder.destroy();
    connection.getTransport().setAlreadyRead( already_read );
    stream_decoder = new_stream_decoder;
    stream_decoder.resumeDecoding();
  }
View Full Code Here

                 
                    bitfield_received = true;
                   
                    BTBitfield bitfield = (BTBitfield)message;
           
                    ByteBuffer bb = bitfield.getBitfield().getBuffer((byte)0);
                   
                    byte[]  contents = new byte[bb.remaining()];
                   
                    bb.get( contents );
                                       
                  }else if ( message_id.equals( BTMessage.ID_BT_HAVE  )){
                   
                    BTHave have = (BTHave)message;
                   
View Full Code Here

    glPixelStorei(GL_PACK_ROW_LENGTH, 0);
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glPixelStorei(GL_PACK_SKIP_ROWS, 0);
    glPixelStorei(GL_PACK_SKIP_PIXELS, 0);

    ByteBuffer image;
    int retVal = 0;
    boolean done = false;

    if ( w != width || h != height ) {
      // must rescale image to get "top" mipmap texture image
      image = BufferUtils.createByteBuffer((w + 4) * h * bpp);
      int error = gluScaleImage(format, width, height, type, data, w, h, type, image);
      if ( error != 0 ) {
        retVal = error;
        done = true;
      }

      /* set pixel unpacking */
      glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
      glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    } else {
      image = data;
    }

    ByteBuffer bufferA = null;
    ByteBuffer bufferB = null;

    int level = 0;
    while ( !done ) {
      if (image != data) {
        /* set pixel unpacking */
        glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
      }

      glTexImage2D(target, level, components, w, h, 0, format, type, image);

      if ( w == 1 && h == 1 )
        break;

      final int newW = (w < 2) ? 1 : w >> 1;
      final int newH = (h < 2) ? 1 : h >> 1;

      final ByteBuffer newImage;

      if ( bufferA == null )
        newImage = (bufferA = BufferUtils.createByteBuffer((newW + 4) * newH * bpp));
      else if ( bufferB == null )
        newImage = (bufferB = BufferUtils.createByteBuffer((newW + 4) * newH * bpp));
 
View Full Code Here

      length_buffer.position( SS, 4 );
      lbuff_read = 4;
      pbuff_read = payload_buffer == null ? 0 : payload_buffer.position( SS );
    }
   
    ByteBuffer unused = ByteBuffer.allocate( lbuff_read + pbuff_read );   //TODO convert to direct?
   
    length_buffer.flip( SS );
    unused.put( length_buffer.getBuffer( SS ) );
   
    if ( payload_buffer != null ) {
      payload_buffer.flip( SS );
      unused.put( payload_buffer.getBuffer( SS ) ); // Got a buffer overflow exception here in the past - related to PEX?
    }
   
    unused.flip();

    length_buffer.returnToPool();
   
    if( payload_buffer != null ) {
      payload_buffer.returnToPool();
View Full Code Here

TOP

Related Classes of java.nio.ByteBuffer

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.