View Javadoc

1   package com.healthmarketscience.jackcess.scsu;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   
6   /*
7    * This sample software accompanies Unicode Technical Report #6 and
8    * distributed as is by Unicode, Inc., subject to the following:
9    *
10   * Copyright 1996-1997 Unicode, Inc.. All Rights Reserved.
11   *
12   * Permission to use, copy, modify, and distribute this software
13   * without fee is hereby granted provided that this copyright notice
14   * appears in all copies.
15   *
16   * UNICODE, INC. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
17   * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
18   * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
20   * UNICODE, INC., SHALL NOT BE LIABLE FOR ANY ERRORS OR OMISSIONS, AND
21   * SHALL NOT BE LIABLE FOR ANY DAMAGES, INCLUDING CONSEQUENTIAL AND
22   * INCIDENTAL DAMAGES, SUFFERED BY YOU AS A RESULT OF USING, MODIFYING
23   * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
24   *
25   *  @author Asmus Freytag
26   *
27   *  @version 001 Dec 25 1996
28   *  @version 002 Jun 25 1997
29   *  @version 003 Jul 25 1997
30   *  @version 004 Aug 25 1997
31   *
32   * Unicode and the Unicode logo are trademarks of Unicode, Inc.,
33   * and are registered in some jurisdictions.
34   **/
35  
36  /**
37   * A number of helpful output routines for debugging. Output can be
38   * centrally enabled or disabled by calling Debug.set(true/false);
39   * All methods are statics;
40   */
41  
42  public class Debug
43  {
44    
45      private static final Log LOG = LogFactory.getLog(Debug.class); 
46    
47      // debugging helper
48      public static void out(char [] chars)
49      {
50           out(chars, 0);
51      }
52  
53      public static void out(char [] chars, int iStart)
54      {
55          if (!LOG.isDebugEnabled()) return;
56          StringBuilder msg = new StringBuilder();
57  
58          for (int i = iStart; i < chars.length; i++)
59          {
60              if (chars[i] >= 0 && chars[i] <= 26)
61              {
62                  msg.append("^"+(char)(chars[i]+0x40));
63              }
64              else if (chars[i] <= 255)
65              {
66                  msg.append(chars[i]);
67              }
68              else
69              {
70                  msg.append("\\u"+Integer.toString(chars[i],16));
71              }
72          }
73          LOG.debug(msg.toString());
74      }
75  
76      public static void out(byte [] bytes)
77      {
78          out(bytes, 0);
79      }
80      public static void out(byte [] bytes, int iStart)
81      {
82          if (!LOG.isDebugEnabled()) return;
83          StringBuilder msg = new StringBuilder();
84  
85          for (int i = iStart; i < bytes.length; i++)
86          {
87              msg.append(bytes[i]+",");
88          }
89          LOG.debug(msg.toString());
90      }
91  
92      public static void out(String str)
93      {
94          if (!LOG.isDebugEnabled()) return;
95  
96          LOG.debug(str);
97      }
98  
99      public static void out(String msg, int iData)
100     {
101         if (!LOG.isDebugEnabled()) return;
102 
103         LOG.debug(msg + iData);
104     }
105     public static void out(String msg, char ch)
106     {
107         if (!LOG.isDebugEnabled()) return;
108 
109         LOG.debug(msg + "[U+"+Integer.toString(ch,16)+"]" + ch);
110     }
111     public static void out(String msg, byte bData)
112     {
113         if (!LOG.isDebugEnabled()) return;
114 
115         LOG.debug(msg + bData);
116     }
117     public static void out(String msg, String str)
118     {
119         if (!LOG.isDebugEnabled()) return;
120 
121         LOG.debug(msg + str);
122     }
123     public static void out(String msg, char [] data)
124     {
125         if (!LOG.isDebugEnabled()) return;
126 
127         LOG.debug(msg);
128         out(data);
129     }
130     public static void out(String msg, byte [] data)
131     {
132         if (!LOG.isDebugEnabled()) return;
133 
134         LOG.debug(msg);
135         out(data);
136     }
137     public static void out(String msg, char [] data, int iStart)
138     {
139         if (!LOG.isDebugEnabled()) return;
140 
141         LOG.debug(msg +"("+iStart+"): ");
142         out(data, iStart);
143     }
144     public static void out(String msg, byte [] data, int iStart)
145     {
146         if (!LOG.isDebugEnabled()) return;
147 
148         LOG.debug(msg+"("+iStart+"): ");
149         out(data, iStart);
150     }
151 }