Coverage Report - org.jaudiotagger.logging.AbstractTagDisplayFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractTagDisplayFormatter
94%
33/35
83%
5/6
1.556
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: AbstractTagDisplayFormatter.java 836 2009-11-12 15:44:07Z paultaylor $
 6  
  *
 7  
  *  MusicTag Copyright (C)2003,2004
 8  
  *
 9  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 10  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 11  
  *  or (at your option) any later version.
 12  
  *
 13  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 14  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
  *  See the GNU Lesser General Public License for more details.
 16  
  *
 17  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 18  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 19  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20  
  *
 21  
  * Description:
 22  
  *  This abstract class defines methods for writing out the contents of a tag in a user-friendly way
 23  
  * Concrete subclasses could implement different versions such as XML Output, PDF and so on. The tag
 24  
  * in all cases is diaplyed as a sort of tree hierachy.
 25  
  */
 26  
 package org.jaudiotagger.logging;
 27  
 
 28  
 import java.util.HashMap;
 29  
 
 30  
 /**
 31  
  * Abstract class that provides structure to use for displaying a files metadata content
 32  
  */
 33  32
 public abstract class AbstractTagDisplayFormatter
 34  
 {
 35  
     protected int level;
 36  
 
 37  4
     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  
      * Use to display headers as their binary representation
 58  
      * @param buffer
 59  
      * @return
 60  
      */
 61  
     public static String displayAsBinary(byte buffer)
 62  
     {
 63  
         //Convert buffer to hex representation
 64  380
         String hexValue = Integer.toHexString(buffer);
 65  380
         String char1 = "";
 66  380
         String char2 = "";
 67  
         try
 68  
         {
 69  380
             if (hexValue.length() == 8)
 70  
             {
 71  284
                 char1 = hexValue.substring(6, 7);
 72  284
                 char2 = hexValue.substring(7, 8);
 73  
             }
 74  96
             else if (hexValue.length() == 2)
 75  
             {
 76  91
                 char1 = hexValue.substring(0, 1);
 77  91
                 char2 = hexValue.substring(1, 2);
 78  
             }
 79  5
             else if (hexValue.length() == 1)
 80  
             {
 81  5
                 char1 = "0";
 82  5
                 char2 = hexValue.substring(0, 1);
 83  
             }
 84  
         }
 85  0
         catch (StringIndexOutOfBoundsException se)
 86  
         {
 87  0
             return "";
 88  380
         }
 89  380
         return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
 90  
     }
 91  
 
 92  
     static
 93  
     {
 94  4
         hexBinaryMap.put("0", "0000");
 95  4
         hexBinaryMap.put("1", "0001");
 96  4
         hexBinaryMap.put("2", "0010");
 97  4
         hexBinaryMap.put("3", "0011");
 98  4
         hexBinaryMap.put("4", "0100");
 99  4
         hexBinaryMap.put("5", "0101");
 100  4
         hexBinaryMap.put("6", "0110");
 101  4
         hexBinaryMap.put("7", "0111");
 102  4
         hexBinaryMap.put("8", "1000");
 103  4
         hexBinaryMap.put("9", "1001");
 104  4
         hexBinaryMap.put("a", "1010");
 105  4
         hexBinaryMap.put("b", "1011");
 106  4
         hexBinaryMap.put("c", "1100");
 107  4
         hexBinaryMap.put("d", "1101");
 108  4
         hexBinaryMap.put("e", "1110");
 109  4
         hexBinaryMap.put("f", "1111");
 110  4
     }
 111  
 }