Here you can find the source of createKey(int instance, int year, int month, int day, int hour, int min, int sec, int milli, String uuid, boolean rolling)
Parameter | Description |
---|---|
instance | The stack instance number must be padded with |
year | a parameter |
month | a parameter |
day | a parameter |
hour | a parameter |
uuid | a parameter |
static String createKey(int instance, int year, int month, int day, int hour, int min, int sec, int milli, String uuid, boolean rolling)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**//ww w . j av a 2 s.co m * This template is used to generated a key for a batch of AccessRecords: * <stack_instance>/<year><month><day>/<hour>/<uuid>.csv.gz */ private static final String INSTANCE_PREFIX_TEMPLATE = "%1$09d"; private static final String DATE_TEMPLATE = "%1$04d-%2$02d-%3$02d"; private static final String KEY_TEMPLATE = "%1$S/%2$S/%3$02d-%4$02d-%5$02d-%6$03d-%7$s%8$s.csv.gz"; public static final String ROLLING = "-rolling"; /** * Create a key from all of the parts. * @param instance The stack instance number must be padded with * @param year * @param month * @param day * @param hour * @param uuid * @return */ static String createKey(int instance, int year, int month, int day, int hour, int min, int sec, int milli, String uuid, boolean rolling) { String roll = rolling ? ROLLING : ""; return String.format(KEY_TEMPLATE, getInstancePrefix(instance), getDateString(year, month, day), hour, min, sec, milli, uuid, roll); } /** * Get the prefix used for this instance. * @param instance * @return */ public static String getInstancePrefix(int instance) { return String.format(INSTANCE_PREFIX_TEMPLATE, instance); } /** * Get the date string * @param timeMS * @return */ public static String getDateString(long timeMS) { Calendar cal = getCalendarUTC(timeMS); int year = cal.get(Calendar.YEAR); // We do a +1 because JANUARY=0 int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); return getDateString(year, month, day); } /** * Get the date String * @param year * @param month * @param day * @return */ public static String getDateString(int year, int month, int day) { return String.format(DATE_TEMPLATE, year, month, day); } /** * Get a new UTC calendar set to the given time. * @param timeMS * @return */ public static Calendar getCalendarUTC(long timeMS) { Calendar cal = getClaendarUTC(); cal.setTime(new Date(timeMS)); return cal; } /** * Get a new Calendar Set to UTC time zone. * @return */ public static Calendar getClaendarUTC() { return Calendar.getInstance(TimeZone.getTimeZone("GMT+0:00")); } }