Merge pull request #1565 from k9mail/boundary_generator_optimization
Optimize BoundaryGenerator
This commit is contained in:
commit
8def88afcb
1 changed files with 15 additions and 6 deletions
|
@ -1,7 +1,6 @@
|
|||
package com.fsck.k9.mail;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
@ -9,6 +8,14 @@ import android.support.annotation.VisibleForTesting;
|
|||
|
||||
public class BoundaryGenerator {
|
||||
private static final BoundaryGenerator INSTANCE = new BoundaryGenerator(new Random());
|
||||
|
||||
private static final int BOUNDARY_CHARACTER_COUNT = 30;
|
||||
private static final char[] BASE36_MAP = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z'
|
||||
};
|
||||
|
||||
|
||||
private final Random random;
|
||||
|
@ -24,11 +31,13 @@ public class BoundaryGenerator {
|
|||
}
|
||||
|
||||
public String generateBoundary() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("----");
|
||||
for (int i = 0; i < 30; i++) {
|
||||
sb.append(Integer.toString(random.nextInt(36), 36));
|
||||
StringBuilder builder = new StringBuilder(4 + BOUNDARY_CHARACTER_COUNT);
|
||||
builder.append("----");
|
||||
|
||||
for (int i = 0; i < BOUNDARY_CHARACTER_COUNT; i++) {
|
||||
builder.append(BASE36_MAP[random.nextInt(36)]);
|
||||
}
|
||||
return sb.toString().toUpperCase(Locale.US);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue