1 /* 2 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 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 com.sun.media.sound; 27 28 import java.security.AccessController; 29 30 import sun.security.action.GetPropertyAction; 31 32 /** 33 * Printer allows you to set up global debugging status and print 34 * messages accordingly. 35 * 36 * @author David Rivas 37 * @author Kara Kytle 38 */ 39 final class Printer { 40 41 static final boolean err = isBuildInternal(); 42 43 private static final boolean SHOW_THREADID = true; 44 private static final boolean SHOW_TIMESTAMP = true; 45 46 /** 47 * Suppresses default constructor, ensuring non-instantiability. 48 */ Printer()49 private Printer() { 50 } 51 52 /** 53 * This method is used in the special cases which "should never happen...". 54 * And in fact if should be implemented as an assertion, but for 55 * compatibility reason it just print an error only in case of "internal" 56 * build. In time its usage should be replaced by some kind of assertion or 57 * dropped completly. 58 */ err(String str)59 public static void err(String str) { 60 if (err) { 61 println(str); 62 } 63 } 64 65 /** 66 * Returns {@code true} if the build of the current jdk is "internal". 67 */ isBuildInternal()68 private static boolean isBuildInternal() { 69 String javaVersion = AccessController.doPrivileged( 70 new GetPropertyAction("java.version")); 71 return javaVersion != null && javaVersion.contains("internal"); 72 } 73 74 private static long startTime = 0; 75 println(String s)76 private static void println(String s) { 77 String prepend = ""; 78 if (SHOW_THREADID) { 79 prepend = "thread " + Thread.currentThread().getId() + " " + prepend; 80 } 81 if (SHOW_TIMESTAMP) { 82 if (startTime == 0) { 83 startTime = System.nanoTime() / 1000000l; 84 } 85 prepend = prepend + ((System.nanoTime()/1000000l) - startTime) + "millis: "; 86 } 87 System.out.println(prepend + s); 88 } 89 } 90