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