Buffer flip - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Buffer flip method.

This code example shows how to use the following methods:clear, flip, put, slice
        Text startKey = partitioner.getRangeEndKey(partitioner.getRangeNum() - 2);
        byteBuffer.put(startKey.getBytes(), 0, startKey.getLength());
        byteBuffer.put(newline);
      } else { 
        Text startKey = partitioner.getRangeEndKey(range_no - 1);
        byteBuffer.put(startKey.getBytes(), 0, startKey.getLength());
        byteBuffer.put(newline);
        Text endKey = partitioner.getRangeEndKey(range_no);
        byteBuffer.put(endKey.getBytes(), 0, endKey.getLength());
        byteBuffer.put(newline);
      } 
    } 
 
    private void writeCurrentByteBuffer(boolean is_last) throws IOException {
      byteBuffer.flip();
      ByteBuffer tmpByteBuf = byteBuffer.slice();
      ByteBuffer output = sstableBuilder.append(tmpByteBuf, is_first, is_last, is_include_min, is_include_max);
      if (output != null) {
        byte[] reslutBuf = new byte[output.capacity()];
        output.get(reslutBuf);

8
CodeRank
This code example shows how to use the following methods:clear, flip, putLong
    return value;
  } 
 
  public void set(long newVal) throws IOException {
    lazyOpen(); 
    buf.clear();
    buf.putLong(newVal);
    buf.flip();
    IOUtils.writeFully(ch, buf, 0);
    value = newVal;
  } 
   
  private void lazyOpen() throws IOException { 
    if (ch != null) {
      return; 
    } 
 
    // Load current value. 
    byte[] data = null;
    try { 
8
CodeRank
This code example shows how to use the following methods:capacity, flip, isDirect
   
  private void reallocPacketBuf(int atLeastCapacity) {
    // Realloc the buffer if this packet is longer than the previous 
    // one. 
    if (curPacketBuf == null ||
        curPacketBuf.capacity() < atLeastCapacity) {
      ByteBuffer newBuf;
      if (useDirectBuffers) {
        newBuf = bufferPool.getBuffer(atLeastCapacity);
      } else { 
        newBuf = ByteBuffer.allocate(atLeastCapacity);
      } 
      // If reallocing an existing buffer, copy the old packet length 
      // prefixes over 
      if (curPacketBuf != null) {
        curPacketBuf.flip();
        newBuf.put(curPacketBuf);
      } 
       
      returnPacketBufToPool(); 

8
CodeRank
This code example shows how to use the following methods:clear, flip
        b.order(ByteOrder.LITTLE_ENDIAN);
        return b;
    } 
 
    private static void read(ByteBuffer bb, FileChannel ch) throws IOException {
        bb.clear();
        ch.read(bb);
        bb.flip();
    } 
 
    private static void read(ByteBuffer bb, FileChannel ch, long pos) throws IOException {
        bb.clear();
        ch.read(bb, pos);
        bb.flip();
    } 
 
    private static long getUnsignedInt(ByteBuffer bb, int offset) {
        return (bb.getInt(offset) & 0xffffffffL);
    } 
 
8
CodeRank
This code example shows how to use the following methods:flip, limit, array, put, putLong
    public final static int MessagePhysicOffsetPostion = 28;
    public final static int MessageStoreTimestampPostion = 56;
 
 
    public static String createMessageId(final ByteBuffer input, final ByteBuffer addr, final long offset) {
        input.flip();
        input.limit(MessageDecoder.MSG_ID_LENGTH);
 
        // 消息存储主机地址 IP PORT 8 
        input.put(addr);
        // 消息对应的物理分区 OFFSET 8 
        input.putLong(offset);
 
        return UtilAll.bytes2string(input.array());
    } 
 
 
    public static MessageId decodeMessageId(final String msgId) throws UnknownHostException {
        SocketAddress address;
        long offset;
8
CodeRank
This code example shows how to use the following methods:clear, flip, position, array
        throw new UnsupportedOperationException();
    } 
 
    private void flushBytes() throws IOException { 
        int position;
        if ((position = mBytes.position()) > 0) {
            mBytes.flip();
            mOutputStream.write(mBytes.array(), 0, position);
            mBytes.clear();
        } 
    } 
 
    public void flush() throws IOException { 
        //Log.i("PackageManager", "flush mPos=" + mPos); 
        if (mPos > 0) {
            if (mOutputStream != null) {
                CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
                CoderResult result = mCharset.encode(charBuffer, mBytes, true);
                while (true) { 
                    if (result.isError()) {
7
CodeRank
This code example shows how to use the following methods:flip, remaining, get, put, putInt
		ByteBuffer buffer = ByteBuffer.allocate(size);
		putData(buffer, state);
		putData(buffer, user);
		putData(buffer, description);
		 
		buffer.flip();
		byte[] data = new byte[buffer.remaining()];
		buffer.get(data);
		return data;
	} 
 
	private static void putData(ByteBuffer buffer, String state) {
		byte[] data = StandardConverters.convertToBytes(state);
		buffer.putInt(data.length);
		buffer.put(data);
	} 
 
	public static ColumnName parseName(byte[] namePrefix, byte[] nameRaw) {
		if(!startsWith(nameRaw, namePrefix))
			return null; 
7
CodeRank
This code example shows how to use the following methods:capacity, flip, limit, position, compact
		return length;
	} 
 
	@Override 
	public int put(byte[] chunk) {
		int startPosition = buf.position();
		int endPosition = buf.limit();
		//compact the buffer before every put operation... 
		int roomLeft = buf.capacity()-endPosition;
		if(chunk.length > roomLeft) {
			buf.compact();
			buf.flip();
			startPosition = buf.position();
			endPosition = buf.limit();
		} 
		 
		//prepare for more writing 
		buf.position(buf.limit());
		buf.limit(buf.capacity());
		buf.put(chunk);

7
CodeRank
This code example shows how to use the following methods:capacity, flip, hasRemaining, position, duplicate
7
CodeRank
This code example shows how to use the following methods:clear, flip, position, array
        throw new UnsupportedOperationException();
    } 
 
    private void flushBytes() throws IOException { 
        int position;
        if ((position = mBytes.position()) > 0) {
            mBytes.flip();
            mOutputStream.write(mBytes.array(), 0, position);
            mBytes.clear();
        } 
    } 
 
    public void flush() throws IOException { 
        //Log.i("PackageManager", "flush mPos=" + mPos); 
        if (mPos > 0) {
            if (mOutputStream != null) {
                CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
                CoderResult result = mCharset.encode(charBuffer, mBytes, true);
                while (true) { 
                    if (result.isError()) {
7
CodeRank

Related Buffer flip Questions & Answers:

flip Method Overview
Flips this buffer.
See Code Examples for other Java 8 Buffer Methods: