Truncates binary value to <code> size </code>
500522
public void setLength(long size) throws IOException, RepositoryException
   {
      if (!changed)
      {
         internalData = createEditableCopy(this.getInternalData());
      }

      ((EditableValueData)internalData).setLength(size);
      invalidateStream();
   }
758025
private void resizeBuf(int size)
    {
        int capacity;
        if (size >= _capacity * 2)
        {
            capacity = size;
        }
        else
        {
            capacity = 1;
            while (capacity < size)
            {
                capacity <<= 1;
            }
        }
        byte[] buf = new byte[capacity];
        if (_size > 0)
        {
            System.arraycopy(_buf, 0, buf, 0, _size);
        }
        _buf = buf;
        _capacity = capacity;
    }
1189854
public void trimToSize(int maxSize) {
        while (true) {
            K key;
            V value;
            synchronized (this) {
                if (size < 0 || map.isEmpty() && size != 0) {
                    throw new IllegalStateException(getClass().getName() + ".sizeOf() is reporting inconsistent results!");
                }

                if (size <= maxSize || map.isEmpty()) {
                    break;
                }

                Map.Entry<K, V> toEvict = map.entrySet().iterator().next();
                key = toEvict.getKey();
                value = toEvict.getValue();
                map.remove(key);
                size -= safeSizeOf(key, value);
                evictionCount++;
            }

            entryRemoved(true, key, value, null);
        }
    }
861778
public void trimToSize() {
		modCount++;
		int oldCapacity = elementData.length;
		if (size < oldCapacity) {
			long oldData[] = elementData;
			elementData = new long[size];
			System.arraycopy(oldData, 0, elementData, 0, size);
		}
	}
620455
public static byte[] convertToExtendedUTF8(long value) {
    //calculate bytes needed
    int bytesNeeded = 1;
    for(int i = 0; i < 7; i++) {
      if(value >= limits[i] ) {
        bytesNeeded++;
      }
    }
    //create space
    byte [] result = new byte[bytesNeeded];
    int byteIndex = 0;
    int inputIndex = 0;
    int bytesLeft = bytesNeeded;
    while(bytesLeft > 1) {
      int midByteMarker = 0x80;//10 in leftmost bits
      int midByteMask = 0x3F;//00111111
      int val = ((int)(value >>> inputIndex) & midByteMask) | midByteMarker;
      result[byteIndex++] = (byte)val;
      inputIndex += 6;
      bytesLeft--;
    }
    int onesNeeded = inputIndex/6;
    if(onesNeeded > 0)
      onesNeeded++;
    int startMask = 255 >>> (onesNeeded + 1);
    int ones = 255 << (8-onesNeeded);
    int val = ((int)(value >>> inputIndex) & startMask) | ones;
    result[byteIndex++] = (byte)val;

    byte[] finalResult = new byte[bytesNeeded];
    for(int i = 0; i < bytesNeeded; i++) {
      int sourceIndex = bytesNeeded-1-i;
      int destIndex = i;
      finalResult[destIndex] = result[sourceIndex];
    }
    if(DEBUG_LEV > 10) {
      System.err.print("input:result_length:result :: " +value+":"+finalResult.length+"::");
      for(int i = 0; i < finalResult.length; i++)
        System.err.print(Integer.toHexString(finalResult[i])+":");
      System.err.println();
    }
    return finalResult;
  }
7295
@Override
    public FastStr trim() {
        char[] value = this.buf;
        int len = end;
        int st = begin;
        char[] val = value;    /* avoid getfield opcode */

        while ((st < len) && (val[st] <= ' ')) {
            st++;
        }
        while ((st < len) && (val[len - 1] <= ' ')) {
            len--;
        }
        return ((st > begin) || (len < size())) ? new FastStr(value, st, len) : this;
    }
865541
public void writeStringSmallLength(byte[] value) {
    int length = value.length;
    while (remaining() < length + 1) {
      grow();
    }
    buf[position++] = (byte) length;
    System.arraycopy(value, 0, buf, position, length);
    position += length;
  }
75878
public void clear(int size, int off) {
    if (size%4 != 4) size = (size/4+1)*4;
    next = null;
    previous = null;
    data = new byte[size];
    offset = off;
    for(int i = 0; i < data.length; i++)
      data[i] = 0;
    usableBits = off;
  }
796040
public void trimToSize() {
		if (_size < _data.length) {
			_data = _size == 0
				? EMPTY_ARRAY
				: copyOf(_data, _size);
		}
	}
1083029
static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException {
        if (value > MAX_LENGTH_LIMIT || value < 0) {
            throw new CorruptedFrameException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value);
        }

        ByteBuf encoded = Unpooled.buffer(4);
        byte digit;
        do {
            digit = (byte) (value % 128);
            value = value / 128;
            // if there are more digits to encode, set the top bit of this digit
            if (value > 0) {
                digit = (byte) (digit | 0x80);
            }
            encoded.writeByte(digit);
        } while (value > 0);
        return encoded;
    }
829856
private static BigDecimal convertBinaryToDecimal(Binary value, int precision, int scale)
  {
    // based on parquet-mr pig conversion which is based on spark conversion... yo dawg?
    if (precision <= 18) {
      ByteBuffer buffer = value.toByteBuffer();
      byte[] bytes = buffer.array();
      int start = buffer.arrayOffset() + buffer.position();
      int end = buffer.arrayOffset() + buffer.limit();
      long unscaled = 0L;
      int i = start;
      while (i < end) {
        unscaled = (unscaled << 8 | bytes[i] & 0xff);
        i++;
      }
      int bits = 8 * (end - start);
      long unscaledNew = (unscaled << (64 - bits)) >> (64 - bits);
      if (unscaledNew <= -Math.pow(10, 18) || unscaledNew >= Math.pow(10, 18)) {
        return new BigDecimal(unscaledNew);
      } else {
        return BigDecimal.valueOf(unscaledNew / Math.pow(10, scale));
      }
    } else {
      return new BigDecimal(new BigInteger(value.getBytes()), scale);
    }
  }
221939
private String sizeToString(final long aSizeInBytes) {
        final String size = sizeFromBytes(aSizeInBytes, true).replace(" ", "");
        return size.substring(0, size.length() - 1);
    }
1010018
public static byte[] toNullTerminatedFixedSizeByteArray(String s, int length) {
        if (s.length() >= length) {
            s = s.substring(0, length - 1);
        }
        while (s.length() < length) {
            s += '\0';
        }
        return s.getBytes();
    }
344966
public static ByteBuf copyLong(long value) {
        ByteBuf buf = buffer(8);
        buf.writeLong(value);
        return buf;
    }
353545
public void writeLong(long value) {
		try {
			buffer.writeInt(8);
			buffer.writeLong(value);
		} catch (Exception e) {
			throw new BinaryWriteFailedException(e);
		}
	}
1134833
static void putLong(ByteBuffer buffer, long value) {
        value = (value << 1) ^ (value >> 63);
        if (value >>> 7 == 0) {
            buffer.put((byte) value);
        } else {
            buffer.put((byte) ((value & 0x7F) | 0x80));
            if (value >>> 14 == 0) {
                buffer.put((byte) (value >>> 7));
            } else {
                buffer.put((byte) (value >>> 7 | 0x80));
                if (value >>> 21 == 0) {
                    buffer.put((byte) (value >>> 14));
                } else {
                    buffer.put((byte) (value >>> 14 | 0x80));
                    if (value >>> 28 == 0) {
                        buffer.put((byte) (value >>> 21));
                    } else {
                        buffer.put((byte) (value >>> 21 | 0x80));
                        if (value >>> 35 == 0) {
                            buffer.put((byte) (value >>> 28));
                        } else {
                            buffer.put((byte) (value >>> 28 | 0x80));
                            if (value >>> 42 == 0) {
                                buffer.put((byte) (value >>> 35));
                            } else {
                                buffer.put((byte) (value >>> 35 | 0x80));
                                if (value >>> 49 == 0) {
                                    buffer.put((byte) (value >>> 42));
                                } else {
                                    buffer.put((byte) (value >>> 42 | 0x80));
                                    if (value >>> 56 == 0) {
                                        buffer.put((byte) (value >>> 49));
                                    } else {
                                        buffer.put((byte) (value >>> 49 | 0x80));
                                        buffer.put((byte) (value >>> 56));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
833414
function truncateStack ( stack ) {
  	if ( !stack ) return '';

  	var lines = stack.split( '\n' );
  	var name = Computation.name + '.getValue';

  	var truncated = [];

  	var len = lines.length;
  	for ( var i = 1; i < len; i += 1 ) {
  		var line = lines[i];

  		if ( ~line.indexOf( name ) ) {
  			return truncated.join( '\n' );
  		} else {
  			truncated.push( line );
  		}
  	}
  }