13
13
import com .tc .exception .TCRuntimeException ;
14
14
15
15
import java .io .UnsupportedEncodingException ;
16
- import java .text .DecimalFormat ;
17
- import java .text .DecimalFormatSymbols ;
18
16
import java .util .regex .Matcher ;
19
17
import java .util .regex .Pattern ;
20
18
21
19
/**
22
20
* Data conversion algorithms and whatnot can be found in java.io.DataInput and java.io.DataOutput. Contains methods for
23
21
* converting from one kind of thing to another.
24
- *
22
+ *
25
23
* @author orion
26
24
*/
27
25
public class Conversion {
@@ -31,11 +29,7 @@ public class Conversion {
31
29
32
30
private static final Pattern MEMORY_SIZE_PATTERN = Pattern .compile ("[0-9]*([.][0-9]+)? *([bkmg])?" );
33
31
private static final Pattern SIZE_MODIFIER_PATTERN = Pattern .compile ("[bkmg]" );
34
- private final static DecimalFormat twoDForm = new DecimalFormat ();
35
32
private static final byte [] EMPTY_BYTE_ARRAY = new byte [] {};
36
- static {
37
- twoDForm .applyLocalizedPattern ("#" + new DecimalFormatSymbols ().getDecimalSeparator () + "##" );
38
- }
39
33
40
34
private static int makeInt (byte b3 , byte b2 , byte b1 , byte b0 ) {
41
35
return ((((b3 & 0xff ) << 24 ) | ((b2 & 0xff ) << 16 ) | ((b1 & 0xff ) << 8 ) | ((b0 & 0xff ) << 0 )));
@@ -110,7 +104,7 @@ public static long bytes2uint(byte b[], int offset, int length) {
110
104
111
105
/**
112
106
* Helper method to write a 4 byte unsigned integer value into a given byte array at a given offset
113
- *
107
+ *
114
108
* @param l the unsigned int value to write
115
109
* @param dest the byte array to write the uint into
116
110
* @param index starting offset into the destination byte array
@@ -128,7 +122,7 @@ public static void writeUint(long l, byte[] dest, int index) {
128
122
129
123
/**
130
124
* Helper method to write a 4 byte java (signed) integer value into a given byte array at a given offset
131
- *
125
+ *
132
126
* @param i the signed int value to write
133
127
* @param dest the byte array to write the uint into
134
128
* @param index starting offset into the destination byte array
@@ -314,7 +308,7 @@ public static String bytesToHex(byte[] b) {
314
308
315
309
/**
316
310
* Converts a single byte to a hex string representation, can be decoded with Byte.parseByte().
317
- *
311
+ *
318
312
* @param b the byte to encode
319
313
* @return a
320
314
*/
@@ -421,13 +415,13 @@ public static String memoryBytesAsSize(final long bytes) throws NumberFormatExce
421
415
return bytes + "b" ;
422
416
} else if (bytes < MEGA .asBytes ()) {
423
417
double rv = (bytes / (KILO .asBytes () * 1.0 ));
424
- return twoDForm .format (rv ) + 'k' ;
418
+ return String .format ("%.2fk" , rv );
425
419
} else if (bytes < GIGA .asBytes ()) {
426
420
double rv = (bytes / (MEGA .asBytes () * 1.0 ));
427
- return twoDForm .format (rv ) + 'm' ;
421
+ return String .format ("%.2fm" , rv );
428
422
} else {
429
423
double rv = (bytes / (GIGA .asBytes () * 1.0 ));
430
- return twoDForm .format (rv ) + 'g' ;
424
+ return String .format ("%.2fg" , rv );
431
425
}
432
426
}
433
427
0 commit comments