| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
package org.jaudiotagger.logging; |
| 27 | |
|
| 28 | |
import java.util.HashMap; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 5 | public abstract class AbstractTagDisplayFormatter |
| 34 | |
{ |
| 35 | |
protected int level; |
| 36 | |
|
| 37 | 7 | private static HashMap<String, String> hexBinaryMap = new HashMap<String, String>(); |
| 38 | |
|
| 39 | |
public abstract void openHeadingElement(String type, String value); |
| 40 | |
|
| 41 | |
public abstract void openHeadingElement(String type, boolean value); |
| 42 | |
|
| 43 | |
public abstract void openHeadingElement(String type, int value); |
| 44 | |
|
| 45 | |
|
| 46 | |
public abstract void closeHeadingElement(String type); |
| 47 | |
|
| 48 | |
public abstract void addElement(String type, String value); |
| 49 | |
|
| 50 | |
public abstract void addElement(String type, int value); |
| 51 | |
|
| 52 | |
public abstract void addElement(String type, boolean value); |
| 53 | |
|
| 54 | |
public abstract String toString(); |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public static String displayAsBinary(byte buffer) |
| 60 | |
{ |
| 61 | |
|
| 62 | 100 | String hexValue = Integer.toHexString(buffer); |
| 63 | 100 | String char1 = ""; |
| 64 | 100 | String char2 = ""; |
| 65 | |
try |
| 66 | |
{ |
| 67 | 100 | if (hexValue.length() == 8) |
| 68 | |
{ |
| 69 | 74 | char1 = hexValue.substring(6, 7); |
| 70 | 74 | char2 = hexValue.substring(7, 8); |
| 71 | |
} |
| 72 | 26 | else if (hexValue.length() == 2) |
| 73 | |
{ |
| 74 | 25 | char1 = hexValue.substring(0, 1); |
| 75 | 25 | char2 = hexValue.substring(1, 2); |
| 76 | |
} |
| 77 | 1 | else if (hexValue.length() == 1) |
| 78 | |
{ |
| 79 | 1 | char1 = "0"; |
| 80 | 1 | char2 = hexValue.substring(0, 1); |
| 81 | |
} |
| 82 | |
} |
| 83 | 0 | catch (StringIndexOutOfBoundsException se) |
| 84 | |
{ |
| 85 | 0 | return ""; |
| 86 | 100 | } |
| 87 | 100 | return hexBinaryMap.get(char1) + hexBinaryMap.get(char2); |
| 88 | |
} |
| 89 | |
|
| 90 | |
static |
| 91 | |
{ |
| 92 | 7 | hexBinaryMap.put("0", "0000"); |
| 93 | 7 | hexBinaryMap.put("1", "0001"); |
| 94 | 7 | hexBinaryMap.put("2", "0010"); |
| 95 | 7 | hexBinaryMap.put("3", "0011"); |
| 96 | 7 | hexBinaryMap.put("4", "0100"); |
| 97 | 7 | hexBinaryMap.put("5", "0101"); |
| 98 | 7 | hexBinaryMap.put("6", "0110"); |
| 99 | 7 | hexBinaryMap.put("7", "0111"); |
| 100 | 7 | hexBinaryMap.put("8", "1000"); |
| 101 | 7 | hexBinaryMap.put("9", "1001"); |
| 102 | 7 | hexBinaryMap.put("a", "1010"); |
| 103 | 7 | hexBinaryMap.put("b", "1011"); |
| 104 | 7 | hexBinaryMap.put("c", "1100"); |
| 105 | 7 | hexBinaryMap.put("d", "1101"); |
| 106 | 7 | hexBinaryMap.put("e", "1110"); |
| 107 | 7 | hexBinaryMap.put("f", "1111"); |
| 108 | 7 | } |
| 109 | |
} |