private byte[] convertStringToBinaryString(ValueMetaInterface v, String string)
      throws KettleValueException {
    int length = v.getLength();

    if (string == null) return new byte[] {};

    if (length > -1 && length < string.length()) {
      // we need to truncate
      String tmp = string.substring(0, length);
      if (Const.isEmpty(v.getStringEncoding())) {
        return tmp.getBytes();
      } else {
        try {
          return tmp.getBytes(v.getStringEncoding());
        } catch (UnsupportedEncodingException e) {
          throw new KettleValueException(
              "Unable to convert String to Binary with specified string encoding ["
                  + v.getStringEncoding()
                  + "]",
              e);
        }
      }
    } else {
      byte text[];
      if (Const.isEmpty(v.getStringEncoding())) {
        text = string.getBytes();
      } else {
        try {
          text = string.getBytes(v.getStringEncoding());
        } catch (UnsupportedEncodingException e) {
          throw new KettleValueException(
              "Unable to convert String to Binary with specified string encoding ["
                  + v.getStringEncoding()
                  + "]",
              e);
        }
      }
      if (length > string.length()) {
        // we need to pad this

        // Also for PDI-170: not all encoding use single characters, so we need to cope
        // with this.
        byte filler[] = " ".getBytes();
        int size = text.length + filler.length * (length - string.length());
        byte bytes[] = new byte[size];
        System.arraycopy(text, 0, bytes, 0, text.length);
        if (filler.length == 1) {
          java.util.Arrays.fill(bytes, text.length, size, filler[0]);
        } else {
          // need to copy the filler array in lots of times
          // TODO: this was not finished.
        }
        return bytes;
      } else {
        // do not need to pad or truncate
        return text;
      }
    }
  }
  public static ValueMetaInterface cloneValueMeta(ValueMetaInterface source, int targetType)
      throws KettlePluginException {
    ValueMetaInterface target = null;

    // If we're Cloneable and not changing types, call clone()
    if (source instanceof Cloneable && source.getType() == targetType) {
      target = source.clone();
    } else {
      target =
          createValueMeta(source.getName(), targetType, source.getLength(), source.getPrecision());
    }
    target.setConversionMask(source.getConversionMask());
    target.setDecimalSymbol(source.getDecimalSymbol());
    target.setGroupingSymbol(source.getGroupingSymbol());
    target.setStorageType(source.getStorageType());
    if (source.getStorageMetadata() != null) {
      target.setStorageMetadata(
          cloneValueMeta(source.getStorageMetadata(), source.getStorageMetadata().getType()));
    }
    target.setStringEncoding(source.getStringEncoding());
    target.setTrimType(source.getTrimType());
    target.setDateFormatLenient(source.isDateFormatLenient());
    target.setDateFormatLocale(source.getDateFormatLocale());
    target.setDateFormatTimeZone(source.getDateFormatTimeZone());
    target.setLenientStringToNumber(source.isLenientStringToNumber());
    target.setLargeTextField(source.isLargeTextField());
    target.setComments(source.getComments());
    target.setCaseInsensitive(source.isCaseInsensitive());
    target.setIndex(source.getIndex());

    target.setOrigin(source.getOrigin());

    target.setOriginalAutoIncrement(source.isOriginalAutoIncrement());
    target.setOriginalColumnType(source.getOriginalColumnType());
    target.setOriginalColumnTypeName(source.getOriginalColumnTypeName());
    target.setOriginalNullable(source.isOriginalNullable());
    target.setOriginalPrecision(source.getOriginalPrecision());
    target.setOriginalScale(source.getOriginalScale());
    target.setOriginalSigned(source.isOriginalSigned());

    return target;
  }