1. /*
  2. * @(#)NamingUtils.java 1.16 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.CosNaming;
  8. import java.io.*;
  9. public class NamingUtils {
  10. // Do not instantiate this class
  11. private NamingUtils() {};
  12. /**
  13. * Debug flag which must be true for debug streams to be created and
  14. * dprint output to be generated.
  15. */
  16. public static boolean debug = false;
  17. /**
  18. * Prints the message to the debug stream if debugging is enabled.
  19. * @param msg the debug message to print.
  20. */
  21. public static void dprint(String msg) {
  22. if (debug && debugStream != null)
  23. debugStream.println(msg);
  24. }
  25. /**
  26. * Prints the message to the error stream (System.err is default).
  27. * @param msg the error message to print.
  28. */
  29. public static void errprint(String msg) {
  30. if (errStream != null)
  31. errStream.println(msg);
  32. else
  33. System.err.println(msg);
  34. }
  35. /**
  36. * Prints the stacktrace of the supplied exception to the error stream.
  37. * @param e any Java exception.
  38. */
  39. public static void printException(java.lang.Exception e) {
  40. if (errStream != null)
  41. e.printStackTrace(errStream);
  42. else
  43. e.printStackTrace();
  44. }
  45. /**
  46. * Create a debug print stream to the supplied log file.
  47. * @param logFile the file to which debug output will go.
  48. * @exception IOException thrown if the file cannot be opened for output.
  49. */
  50. public static void makeDebugStream(File logFile)
  51. throws java.io.IOException {
  52. // Create an outputstream for debugging
  53. java.io.OutputStream logOStream =
  54. new java.io.FileOutputStream(logFile);
  55. java.io.DataOutputStream logDStream =
  56. new java.io.DataOutputStream(logOStream);
  57. debugStream = new java.io.PrintStream(logDStream);
  58. // Emit first message
  59. debugStream.println("Debug Stream Enabled.");
  60. }
  61. /**
  62. * Create a error print stream to the supplied file.
  63. * @param logFile the file to which error messages will go.
  64. * @exception IOException thrown if the file cannot be opened for output.
  65. */
  66. public static void makeErrStream(File errFile)
  67. throws java.io.IOException {
  68. if (debug) {
  69. // Create an outputstream for errors
  70. java.io.OutputStream errOStream =
  71. new java.io.FileOutputStream(errFile);
  72. java.io.DataOutputStream errDStream =
  73. new java.io.DataOutputStream(errOStream);
  74. errStream = new java.io.PrintStream(errDStream);
  75. dprint("Error stream setup completed.");
  76. }
  77. }
  78. /**
  79. * The debug printstream.
  80. */
  81. public static java.io.PrintStream debugStream;
  82. /**
  83. * The error printstream.
  84. */
  85. public static java.io.PrintStream errStream;
  86. }