Format the output string with maximum length

@param bits Maximum length of the output string
@param val the value of data
@param key the key of field in the map
@return formated string of number
973267
protected String formatStr(int bits, String val, Object key) {
        if (val.equals("")) {
            return val;
        } else if (val.length() > bits) {
            //throw new Exception();
            sbError.append("! Waring: There is a variable [").append(key).append("] with oversized content [").append(val).append("], only first ").append(bits).append(" bits will be applied.\r\n");
            return val.substring(0, bits);
        }

        return val;
    }
250913
public static String dump(final int displayOffset, final byte[] data, final int offset, final int len)
   {
      StringBuilder sb = new StringBuilder();
      Formatter formatter = new Formatter(sb);
      StringBuilder ascii = new StringBuilder();

      int dataNdx = offset;
      final int maxDataNdx = offset + len;
      final int lines = (len + 16) / 16;
      for (int i = 0; i < lines; i++) {
         ascii.append(" |");
         formatter.format("%08x  ", displayOffset + (i * 16));

         for (int j = 0; j < 16; j++) {
            if (dataNdx < maxDataNdx) {
               byte b = data[dataNdx++];
               formatter.format("%02x ", b);
               ascii.append((b > MIN_VISIBLE && b < MAX_VISIBLE) ? (char) b : ' ');
            }
            else {
               sb.append("   ");
            }

            if (j == 7) {
               sb.append(' ');
            }
         }

         ascii.append('|');
         sb.append(ascii).append('\n');
         ascii.setLength(0);
      }

      formatter.close();
      return sb.toString();
   }
510371
public Bits writeBoundedLong(final long value, final long max)
    throws IOException {
    final int bits = 0 >= max ? 0 : (int) (Math
      .floor(Math.log(max) / Math.log(2)) + 1);
    if (0 < bits) {
      Bits toWrite = new Bits(value, bits);
      this.write(toWrite);
      return toWrite;
    }
    else {
      return Bits.NULL;
    }
  }
532296
public String
getText(int val) {
	check(val);
	String str = (String) values.get(toInteger(val));
	if (str != null)
		return str;
	str = Integer.toString(val);
	if (prefix != null)
		return prefix + str;
	return str;
}
1000501
private static String digits(long val, int digits) {
		long hi = 1L << (digits * 4);
		return Long.toHexString(hi | (val & (hi - 1))).substring(1);
	}
188582
private void _writeStringCustom(final int len)
			throws IOException, JsonGenerationException
	{
		// And then we'll need to verify need for escaping etc:
		int end = _outputTail + len;
		final int[] escCodes = _outputEscapes;
		final int maxNonEscaped = (_maximumNonEscapedChar < 1) ? 0xFFFF : _maximumNonEscapedChar;
		final int escLimit = Math.min(escCodes.length, maxNonEscaped+1);
		int escCode = 0;
		final CharacterEscapes customEscapes = _characterEscapes;

		output_loop:
		while (_outputTail < end) {
			char c;
			// Fast loop for chars not needing escaping
			escape_loop:
			while (true) {
				c = _outputBuffer[_outputTail];
				if (c < escLimit) {
					escCode = escCodes[c];
					if (escCode != 0) {
						break escape_loop;
					}
				} else if (c > maxNonEscaped) {
					escCode = CharacterEscapes.ESCAPE_STANDARD;
					break escape_loop;
				} else {
					if ((_currentEscape = customEscapes.getEscapeSequence(c)) != null) {
						escCode = CharacterEscapes.ESCAPE_CUSTOM;
						break escape_loop;
					}
				}
				if (++_outputTail >= end) {
					break output_loop;
				}
			}
			int flushLen = (_outputTail - _outputHead);
			if (flushLen > 0) {
				_writer.write(_outputBuffer, _outputHead, flushLen);
			}
			++_outputTail;
			_prependOrWriteCharacterEscape(c, escCode);
		}
	}
644900
void splitKeyVal(byte[] line, int length, Text key, Text val)
  throws IOException {
    int numKeyFields = getNumOfKeyFields();
    byte[] separator = getFieldSeparator();
    
    // Need to find numKeyFields separators
    int pos = UTF8ByteArrayUtils.findBytes(line, 0, length, separator);
    for(int k=1; k<numKeyFields && pos!=-1; k++) {
      pos = UTF8ByteArrayUtils.findBytes(line, pos + separator.length, 
          length, separator);
    }
    try {
      if (pos == -1) {
        key.set(line, 0, length);
        val.set("");
      } else {
        StreamKeyValUtil.splitKeyVal(line, 0, length, key, val, pos, separator.length);
      }
    } catch (CharacterCodingException e) {
      LOG.warn(StringUtils.stringifyException(e));
    }
  }
1365831
public static String toStringUnsignedInt(byte[] key) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < key.length; i++) {
            result.append(key[i] & 0xFF);
            result.append(' ');
        }
        return result.toString();
    }
1081945
public Bits encode(final T key) {
    final Bits bits = this.reverseIndex.get(key);
    assert null != bits || this.verifyIndexes();
    return bits;
  }
1089751
public static void addString(ByteBuffer buffer, String val)
  {
    addBytes(buffer, StringUtils.toUtf8(val));
  }
882593
public ValueMap withBinarySet(String key, byte[] ... val) {
        super.put(key, new LinkedHashSet<byte[]>(Arrays.asList(val)));
        return this;
    }
731447
@Override
	public void setOutputOption(String key, String val) {
		setOutputOption(BlastOutputParameterEnum.valueOf(key), val);
	}
784095
private String format(final long bytes) {
        if (bytes > MB) {
            return String.valueOf(bytes / MB) + " MB";
        }
        return String.valueOf(bytes / KB) + " KB";
    }
635781
static long sizeForField(@Nonnull String key, @Nonnull Object value) {
        return key.length() + sizeForValue(value);
    }
398066
public static int bitLength (String string) {
        Objects.requireNonNull(string, Required.STRING.toString());
        int byteLength = string.getBytes(StandardCharsets.UTF_8).length;
        
        int length = 0;
        if (byteLength <= MAX_BYTE_LENGTH && byteLength > 0) {
            length = byteLength * BYTES;
        }
        
        return length;
    }
883035
public static byte[] intToBytesNoLeadZeroes(int val) {

        if (val == 0)
            return EMPTY_BYTE_ARRAY;

        int lenght = 0;

        int tmpVal = val;
        while (tmpVal != 0) {
            tmpVal = tmpVal >>> 8;
            ++lenght;
        }

        byte[] result = new byte[lenght];

        int index = result.length - 1;
        while (val != 0) {

            result[index] = (byte) (val & 0xFF);
            val = val >>> 8;
            index -= 1;
        }

        return result;
    }
541628
public ValueMap withStringSet(String key, Set<String> val) {
        super.put(key, val);
        return this;
    }