src/java.base/share/classes/sun/security/ssl/Debug.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.PrintStream;
  29 import java.security.AccessController;
  30 import java.util.Locale;
  31 



  32 import sun.security.action.GetPropertyAction;
  33 
  34 /**
  35  * This class has be shamefully lifted from sun.security.util.Debug
  36  *
  37  * @author Gary Ellison
  38  */
  39 public class Debug {
  40 
  41     private String prefix;
  42 
  43     private static String args;
  44 
  45     static {
  46         args = java.security.AccessController.doPrivileged(
  47             new GetPropertyAction("javax.net.debug", ""));
  48         args = args.toLowerCase(Locale.ENGLISH);
  49         if (args.equals("help")) {
  50             Help();
  51         }


 181      */
 182     static boolean getBooleanProperty(String propName, boolean defaultValue) {
 183         // if set, require value of either true or false
 184         String b = AccessController.doPrivileged(
 185                 new GetPropertyAction(propName));
 186         if (b == null) {
 187             return defaultValue;
 188         } else if (b.equalsIgnoreCase("false")) {
 189             return false;
 190         } else if (b.equalsIgnoreCase("true")) {
 191             return true;
 192         } else {
 193             throw new RuntimeException("Value of " + propName
 194                 + " must either be 'true' or 'false'");
 195         }
 196     }
 197 
 198     static String toString(byte[] b) {
 199         return sun.security.util.Debug.toString(b);
 200     }











































 201 }


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.PrintStream;
  29 import java.security.AccessController;
  30 import java.util.Locale;
  31 
  32 import sun.misc.HexDumpEncoder;
  33 import java.nio.ByteBuffer;
  34 
  35 import sun.security.action.GetPropertyAction;
  36 
  37 /**
  38  * This class has be shamefully lifted from sun.security.util.Debug
  39  *
  40  * @author Gary Ellison
  41  */
  42 public class Debug {
  43 
  44     private String prefix;
  45 
  46     private static String args;
  47 
  48     static {
  49         args = java.security.AccessController.doPrivileged(
  50             new GetPropertyAction("javax.net.debug", ""));
  51         args = args.toLowerCase(Locale.ENGLISH);
  52         if (args.equals("help")) {
  53             Help();
  54         }


 184      */
 185     static boolean getBooleanProperty(String propName, boolean defaultValue) {
 186         // if set, require value of either true or false
 187         String b = AccessController.doPrivileged(
 188                 new GetPropertyAction(propName));
 189         if (b == null) {
 190             return defaultValue;
 191         } else if (b.equalsIgnoreCase("false")) {
 192             return false;
 193         } else if (b.equalsIgnoreCase("true")) {
 194             return true;
 195         } else {
 196             throw new RuntimeException("Value of " + propName
 197                 + " must either be 'true' or 'false'");
 198         }
 199     }
 200 
 201     static String toString(byte[] b) {
 202         return sun.security.util.Debug.toString(b);
 203     }
 204 
 205     static void printHex(String prefix, byte[] bytes) {
 206         HexDumpEncoder dump = new HexDumpEncoder();
 207 
 208         synchronized (System.out) {
 209             System.out.println(prefix);
 210             try {
 211                 dump.encodeBuffer(bytes, System.out);
 212             } catch (Exception e) {
 213                 // ignore
 214             }
 215             System.out.flush();
 216         }
 217     }
 218 
 219     static void printHex(String prefix, ByteBuffer bb) {
 220         HexDumpEncoder dump = new HexDumpEncoder();
 221 
 222         synchronized (System.out) {
 223             System.out.println(prefix);
 224             try {
 225                 dump.encodeBuffer(bb.slice(), System.out);
 226             } catch (Exception e) {
 227                 // ignore
 228             }
 229             System.out.flush();
 230         }
 231     }
 232 
 233     static void printHex(String prefix, byte[] bytes, int offset, int length) {
 234         HexDumpEncoder dump = new HexDumpEncoder();
 235 
 236         synchronized (System.out) {
 237             System.out.println(prefix);
 238             try {
 239                 ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
 240                 dump.encodeBuffer(bb, System.out);
 241             } catch (Exception e) {
 242                 // ignore
 243             }
 244             System.out.flush();
 245         }
 246     }
 247 }