package com.fsck.k9.mail;


import java.util.Locale;
import java.util.Random;

import android.support.annotation.VisibleForTesting;


public class BoundaryGenerator {
    private static final BoundaryGenerator INSTANCE = new BoundaryGenerator(new Random());


    private final Random random;


    public static BoundaryGenerator getInstance() {
        return INSTANCE;
    }

    @VisibleForTesting
    BoundaryGenerator(Random random) {
        this.random = random;
    }

    public String generateBoundary() {
        StringBuilder sb = new StringBuilder();
        sb.append("----");
        for (int i = 0; i < 30; i++) {
            sb.append(Integer.toString(random.nextInt(36), 36));
        }
        return sb.toString().toUpperCase(Locale.US);
    }
}

@@ -25,33 +25,8 @@
 ;%0A%0A%0A
-import java.util.Locale;%0A
 impo
@@ -226,16 +226,362 @@
 dom());%0A
+    %0A    private static final int BOUNDARY_CHARACTER_COUNT = 30;%0A    private static final char%5B%5D BASE36_MAP = %7B%0A            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',%0A            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',%0A            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',%0A            'U', 'V', 'W', 'X', 'Y', 'Z'%0A    %7D;%0A
 %0A%0A    pr
@@ -853,18 +853,23 @@
 Builder 
-s
 b
+uilder
  = new S
@@ -881,16 +881,44 @@
 Builder(
+4 + BOUNDARY_CHARACTER_COUNT
 );%0A     
@@ -912,34 +912,39 @@
 COUNT);%0A        
-s
 b
+uilder
 .append(%22----%22);
@@ -944,16 +944,25 @@
 ----%22);%0A
+        %0A
         
@@ -981,18 +981,40 @@
  0; i %3C 
-30
+BOUNDARY_CHARACTER_COUNT
 ; i++) %7B
@@ -1030,18 +1030,23 @@
     
-s
 b
+uilder
 .append(
 Inte
@@ -1045,25 +1045,19 @@
 end(
-Integer.toString(
+BASE36_MAP%5B
 rand
@@ -1074,13 +1074,9 @@
 (36)
-, 36)
+%5D
 );%0A 
@@ -1096,50 +1096,41 @@
     
-return sb.toString().toUpperCase(Locale.US
+%0A        return builder.toString(
 );%0A 

Optimize BoundaryGenerator