protected static String replaceShorthand(char c, Map<String, String> headers,
      TimeZone timeZone, boolean needRounding, int unit, int roundDown,
      boolean useLocalTimestamp, long ts) {

    String timestampHeader = null;
    try {
      if (!useLocalTimestamp) {
        timestampHeader = headers.get("timestamp");
        Preconditions.checkNotNull(timestampHeader, "Expected timestamp in " +
            "the Flume event headers, but it was null");
        ts = Long.valueOf(timestampHeader);
      } else {
        timestampHeader = String.valueOf(ts);
      }
    } catch (NumberFormatException e) {
      throw new RuntimeException("Flume wasn't able to parse timestamp header"
        + " in the event to resolve time based bucketing. Please check that"
        + " you're correctly populating timestamp header (for example using"
        + " TimestampInterceptor source interceptor).", e);
    }

    if (needRounding) {
      ts = roundDown(roundDown, unit, ts, timeZone);
    }

    // It's a date
    String formatString = "";
    switch (c) {
      case '%':
        return "%";
      case 'a':
        formatString = "EEE";
        break;
      case 'A':
        formatString = "EEEE";
        break;
      case 'b':
        formatString = "MMM";
        break;
      case 'B':
        formatString = "MMMM";
        break;
      case 'c':
        formatString = "EEE MMM d HH:mm:ss yyyy";
        break;
      case 'd':
        formatString = "dd";
        break;
      case 'e':
        formatString = "d";
        break;
      case 'D':
        formatString = "MM/dd/yy";
        break;
      case 'H':
        formatString = "HH";
        break;
      case 'I':
        formatString = "hh";
        break;
      case 'j':
        formatString = "DDD";
        break;
      case 'k':
        formatString = "H";
        break;
      case 'l':
        formatString = "h";
        break;
      case 'm':
        formatString = "MM";
        break;
      case 'M':
        formatString = "mm";
        break;
      case 'n':
        formatString = "M";
        break;
      case 'p':
        formatString = "a";
        break;
      case 's':
        return "" + (ts / 1000);
      case 'S':
        formatString = "ss";
        break;
      case 't':
        // This is different from unix date (which would insert a tab character
        // here)
        return timestampHeader;
      case 'y':
        formatString = "yy";
        break;
      case 'Y':
        formatString = "yyyy";
        break;
      case 'z':
        formatString = "ZZZ";
        break;
      default:
        // LOG.warn("Unrecognized escape in event format string: %" + c);
        return "";
    }

    SimpleDateFormat format = getSimpleDateFormat(formatString);
    if (timeZone != null) {
      format.setTimeZone(timeZone);
    } else {
      format.setTimeZone(TimeZone.getDefault());
    }

    Date date = new Date(ts);
    return format.format(date);
  }
protected static String replaceShorthand ( char c , Map < String , String > headers , TimeZone timeZone , boolean needRounding , int unit , int roundDown , boolean useLocalTimestamp , long ts ) { String timestampHeader = null ; try { if ( ! useLocalTimestamp ) { timestampHeader = headers . get ( "timestamp" ) ; Preconditions . checkNotNull ( timestampHeader , "Expected timestamp in " + "the Flume event headers, but it was null" ) ; ts = Long . valueOf ( timestampHeader ) ; } else { timestampHeader = String . valueOf ( ts ) ; } } catch ( NumberFormatException e ) { throw new RuntimeException ( "Flume wasn't able to parse timestamp header" + " in the event to resolve time based bucketing. Please check that" + " you're correctly populating timestamp header (for example using" + " TimestampInterceptor source interceptor)." , e ) ; } if ( needRounding ) { ts = roundDown ( roundDown , unit , ts , timeZone ) ; } String formatString = "" ; switch ( c ) { case '%' : return "%" ; case 'a' : formatString = "EEE" ; break ; case 'A' : formatString = "EEEE" ; break ; case 'b' : formatString = "MMM" ; break ; case 'B' : formatString = "MMMM" ; break ; case 'c' : formatString = "EEE MMM d HH:mm:ss yyyy" ; break ; case 'd' : formatString = "dd" ; break ; case 'e' : formatString = "d" ; break ; case 'D' : formatString = "MM/dd/yy" ; break ; case 'H' : formatString = "HH" ; break ; case 'I' : formatString = "hh" ; break ; case 'j' : formatString = "DDD" ; break ; case 'k' : formatString = "H" ; break ; case 'l' : formatString = "h" ; break ; case 'm' : formatString = "MM" ; break ; case 'M' : formatString = "mm" ; break ; case 'n' : formatString = "M" ; break ; case 'p' : formatString = "a" ; break ; case 's' : return "" + ( ts / 1000 ) ; case 'S' : formatString = "ss" ; break ; case 't' : return timestampHeader ; case 'y' : formatString = "yy" ; break ; case 'Y' : formatString = "yyyy" ; break ; case 'z' : formatString = "ZZZ" ; break ; default : return "" ; } SimpleDateFormat format = getSimpleDateFormat ( formatString ) ; if ( timeZone != null ) { format . setTimeZone ( timeZone ) ; } else { format . setTimeZone ( TimeZone . getDefault ( ) ) ; } Date date = new Date ( ts ) ; return format . format ( date ) ; }
Not intended as a public API