public ByteBuf add( final byte[] array, final int length ) { if ( ( this.length + length ) < capacity ) { Byt._idx( buffer, this.length, array, length ); } else { buffer = Byt.grow( buffer, buffer.length * 2 + length ); capacity = buffer.length; Byt._idx( buffer, length, array, length ); } this.length += length; return this; }
public static byte idx( final byte[] array, final int index ) { final int i = calculateIndex( array, index ); return array[ i ]; }
public static byte[] insert( final byte[] array, final int idx, final byte v ) { if ( idx >= array.length ) { return add( array, v ); } final int index = calculateIndex( array, idx ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); byte[] newArray = new byte[ array.length + 1 ]; if ( index != 0 ) { /* Copy up to the length in the array before the index. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, 0, newArray, 0, index ); } boolean lastIndex = index == array.length - 1; int remainingIndex = array.length - index; if ( lastIndex ) { /* Copy the area after the insert. Make sure we don't write over the end. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + 1, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + 1, remainingIndex ); } newArray[ index ] = v; return newArray; }
private void doWriteFloatArray( float[] values, int byteSize ) { if ( !( byteSize + length < capacity ) ) { buffer = Byt.grow( buffer, buffer.length * 2 + byteSize ); } for ( int index = 0; index < values.length; index++ ) { this.add( values[ index ] ); } }
public ByteBuf add( String str ) { this.add( Byt.bytes( str ) ); return this; }
public void addUnsignedByte( short value ) { if ( 1 + length < capacity ) { Byt.unsignedByteTo( buffer, length, value ); } else { buffer = Byt.grow( buffer, buffer.length * 2 + 1 ); capacity = buffer.length; Byt.unsignedByteTo( buffer, length, value ); } length += 1; }
public ByteBuf addUnsignedInt( long value ) { if ( 4 + length < capacity ) { Byt.unsignedIntTo( buffer, length, value ); } else { buffer = Byt.grow( buffer, buffer.length * 2 + 4 ); capacity = buffer.length; Byt.unsignedIntTo( buffer, length, value ); } length += 4; return this; }