Package java.nio

Examples of java.nio.ByteBuffer


    }else{
      int  rem = max_bytes;
     
      byte[]  bytes = new byte[1];
     
      ByteBuffer    bb  = ByteBuffer.wrap( bytes );
     
      ByteBuffer[]  bbs = { bb };
     
      while( rem > 0 && !( paused || paused_internally )){
       
        if ( transport.read( bbs,0, 1 ) == 0 ){
         
          break;
        }
       
        rem--;
       
        protocol_bytes_read++;
       
        bb.flip();
       
        char  c = (char)(bytes[0]&0xff);
       
        header_so_far.append( c );
       
View Full Code Here


    this.width = width;
    this.height = height;
  }
 
  public byte[] getContentPayload() {
    ByteBuffer buffer = ByteBuffer.allocate(13);
   
    //width : 4 bytes
    buffer.putInt(width);
   
    //height : 4 bytes
    buffer.putInt(height);
   
    //color depth : 1 byte
    buffer.put((byte)8);
   
    //color type : 1 byte
    buffer.put((byte)0);
   
    //compression method : 1 byte
    buffer.put((byte)0);
   
    //filter method : 1 byte
    buffer.put((byte)0);
   
    //interlace method : 1 byte
    buffer.put((byte)0);
   
    return buffer.array();
   
  }
View Full Code Here

    if (filter == null) {
      return (this.global < length ? OK : NOT_OK);
    }

    ByteBuffer buffer = null;

    long nextPosition = this.global;

    do {
View Full Code Here

    final long p = this.getPosition(); // remember current position

    // 1st aquire the buffers for both records
    this.setPosition(r1);
    final ByteBuffer b1 = BufferUtils.slice(this.next()); // Remember the buffer

    this.setPosition(r2);
    final ByteBuffer b2 = BufferUtils.slice(this.next()); // Remember the buffer

    // Replace r2 first, as its replacement won't affect position of r1
    this.setPosition(r2);
    this.replace(b1);

    // Lastly replace r1, it might affect r2 position, but r2 has already been
    // replaced, so no big deal
    this.setPosition(r1);
    this.replace(b2);

    /*
     * Try to get back to roughly the same position, the position might only
     * change if r1 < position < r2 and if r1.length != r2.length, otherwise the
     * position should still end up on same record's start position
     */
    this.seek(p);

    this.autoflush.autoflushChange(b1.capacity() + b2.capacity());
  }
View Full Code Here

      return ByteBuffer.allocate(bufferSize);
  }

  //Uninitialize an instance to be returned to the pool.
    public void passivateObject(Object obj) {
    ByteBuffer ch = (ByteBuffer)obj;
    ch.clear();
    }
View Full Code Here

      dst.position(saved_position);
    }
  }

  private static ByteBuffer doNoCopyWrap(ByteBuffer buffer) {
    ByteBuffer direct_buffer = lookupBuffer(buffer);
    direct_buffer.limit(buffer.limit());
    direct_buffer.position(buffer.position());
    return direct_buffer;
  }
View Full Code Here

  private static ByteBuffer lookupBuffer(ByteBuffer buffer) {
    return getCachedBuffers(buffer.remaining()).byte_buffer;
  }

  private static ByteBuffer doWrap(ByteBuffer buffer) {
    ByteBuffer direct_buffer = lookupBuffer(buffer);
    direct_buffer.clear();
    int saved_position = buffer.position();
    direct_buffer.put(buffer);
    buffer.position(saved_position);
    direct_buffer.flip();
    return direct_buffer;
  }
View Full Code Here

  }

  public int getInfoInt(final T object, final int param_name) {
    object.checkValid();

    final ByteBuffer buffer = APIUtil.getBufferByte(4);
    getInfo(object, param_name, buffer, null);

    return buffer.getInt(0);
  }
View Full Code Here

  }

  public long getInfoLong(final T object, final int param_name) {
    object.checkValid();

    final ByteBuffer buffer = APIUtil.getBufferByte(8);
    getInfo(object, param_name, buffer, null);

    return buffer.getLong(0);
  }
View Full Code Here

    final int bytes = getSizeRet(object, param_name);
    if ( bytes <= 1 )
      return null;

    final ByteBuffer buffer = APIUtil.getBufferByte(bytes);
    getInfo(object, param_name, buffer, null);

    buffer.limit(bytes - 1); // Exclude null-termination
    return APIUtil.getString(buffer);
  }
View Full Code Here

TOP

Related Classes of java.nio.ByteBuffer

Copyright © 2015 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.