class Encoder {

    public static String substring(String tail, int startIndex, int endIndex) {
        if (tail == null) {
            return "";
        }
        if (tail.length() <= startIndex) {
            return "";
        } else {
            if (endIndex > tail.length() - 1) {
                return tail.substring(startIndex, tail.length());
            } else {
                return tail.substring(startIndex, endIndex);
            }
        }
    }

}