Skip to content

Instantly share code, notes, and snippets.

@philard
Last active September 18, 2021 08:37
Show Gist options
  • Save philard/b92214e230e3c1de5f6d65b952b3de14 to your computer and use it in GitHub Desktop.
Save philard/b92214e230e3c1de5f6d65b952b3de14 to your computer and use it in GitHub Desktop.
String className = (this != null) ? this.getClass().getSimpleName() : "";
int wavFilesCount = new java.io.File("sounds").listFiles().length;
int clipIndex = (className.hashCode() & 0x7FFFFFFF) % wavFilesCount;
javax.sound.sampled.Clip clip = javax.sound.sampled.AudioSystem.getClip();
java.io.File wavFile = new java.io.File("sounds" + java.io.File.separator + "sound" + clipIndex + ".wav");
javax.sound.sampled.AudioInputStream audio = javax.sound.sampled.AudioSystem.getAudioInputStream(wavFile);
clip.open(audio);
clip.start();
String metaMessage = new java.util.Date().toString() + " clip:" + clipIndex + " class:" + className + System.lineSeparator();
java.io.PrintWriter writer = new java.io.PrintWriter(new java.io.File("stack-trace.log"));
writer.append(metaMessage);
new Throwable().printStackTrace(writer);
writer.close();
This file has been truncated, but you can view the full file.
@philard
Copy link
Author

philard commented Sep 11, 2017

Find your JVM's base directory (.../tomcat/bin) and extract the sounds zip there. Then add the script to your Idea's breakpoints under "Evaluate and log". Sounds based on the class name will play. Latest stack trace is written to "stack-trace.log".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment