Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ public static String getKey(String s3KeyFormat, int sequence, long timestamp, St
}

if (s3KeyFormat.contains("%m")) {
s3KeyFormat = s3KeyFormat.replace("%m", getDayOrMonth(getMonth(calendar)));
s3KeyFormat = s3KeyFormat.replace("%m", padTwoDigitNumber(getMonth(calendar)));
}

if (s3KeyFormat.contains("%d")) {
s3KeyFormat = s3KeyFormat.replace("%d", getDayOrMonth(calendar.get(Calendar.DAY_OF_MONTH)));
s3KeyFormat = s3KeyFormat.replace("%d", padTwoDigitNumber(calendar.get(Calendar.DAY_OF_MONTH)));
}

if (s3KeyFormat.contains("%H")) {
s3KeyFormat = s3KeyFormat.replace("%H", padTwoDigitNumber(calendar.get(Calendar.HOUR_OF_DAY)));
}

if (s3KeyFormat.contains("%s")) {
Expand Down Expand Up @@ -116,7 +120,7 @@ private static String getYear(int year) {
return Integer.toString(year);
}

private static String getDayOrMonth(int value) {
private static String padTwoDigitNumber(int value) {
return String.format("%02d", value);
}

Expand Down Expand Up @@ -152,8 +156,9 @@ private static Collection<String> getS3KeyPrefixes(String s3KeyFormat, List<Stri
int indexOfY = trimKeyFormat.indexOf("%Y");
int indexOfM = trimKeyFormat.indexOf("%m");
int indexOfD = trimKeyFormat.indexOf("%d");
int indexOfH = trimKeyFormat.indexOf("%H");

if (indexOfY == -1 && indexOfM == -1 && indexOfD == -1) {
if (indexOfY == -1 && indexOfM == -1 && indexOfD == -1 && indexOfH == -1) {
return Collections.singleton(trimKeyFormat);
}

Expand All @@ -165,6 +170,9 @@ private static Collection<String> getS3KeyPrefixes(String s3KeyFormat, List<Stri
if (indexOfD > -1) {
indexOfD += 2;
}
if (indexOfH > -1) {
indexOfH += 2;
}
}

StringBuilder keyBuilder = new StringBuilder(trimKeyFormat);
Expand All @@ -185,18 +193,24 @@ private static Collection<String> getS3KeyPrefixes(String s3KeyFormat, List<Stri
}

if (indexOfM > -1) {
keyBuilder.replace(indexOfM, indexOfM + 2, getDayOrMonth(getMonth(calendar)));
keyBuilder.replace(indexOfM, indexOfM + 2, padTwoDigitNumber(getMonth(calendar)));
}

if (indexOfD > -1) {
keyBuilder.replace(indexOfD, indexOfD + 2, getDayOrMonth(calendar.get(Calendar.DAY_OF_MONTH)));
keyBuilder.replace(indexOfD, indexOfD + 2, padTwoDigitNumber(calendar.get(Calendar.DAY_OF_MONTH)));
}

if (indexOfH > -1) {
keyBuilder.replace(indexOfH, indexOfH + 2, padTwoDigitNumber(calendar.get(Calendar.HOUR_OF_DAY)));
}

if (prefixWhitelist.isEmpty() || prefixWhitelist.stream().anyMatch(allowedPrefix -> keyBuilder.toString().startsWith(allowedPrefix))) {
keyPrefixes.add(keyBuilder.toString());
}

if (indexOfD > -1) {
if (indexOfH > -1) {
calendar.add(Calendar.HOUR_OF_DAY, 1);
} else if (indexOfD > -1) {
calendar.add(Calendar.DAY_OF_YEAR, 1);
} else if (indexOfM > -1) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
Expand Down