syslogmedia.java

来自「與 unix 上相似的syslog daemon, 沒有 log4j 複雜」· Java 代码 · 共 110 行

JAVA
110
字号
package com.ice.syslogd;import java.net.*;import java.util.*;import java.applet.*;import  sun.audio.*;    //import the sun.audio packageimport  java.io.*;/* * This class will need to be changed for every new * environment that the syslogd package is used in. * Specifically, the audio currently depends on an * available Applet, which is provided by the SyslogD * application in this instance. */public classSyslogMedia	{	public static final String		RCS_ID = "$Id: SyslogMedia.java,v 1.2 1998/07/29 02:15:10 time Exp $";	public static final String		RCS_REV = "$Revision: 1.2 $";	public static final String		RCS_NAME = "$Name:  $";	static public final String		sunAudioAPIName = "SunAudio";	static public final String		jmfAudioAPIName = "JMFAudio";	static private Hashtable		audioCache;	static		{		SyslogMedia.audioCache = new Hashtable();		}	static public void	loadAudioClip( String apiName, String audioPath )		{		if ( apiName.equalsIgnoreCase( SyslogMedia.sunAudioAPIName ) )			{			SyslogMedia.loadSunAudioClip( audioPath );			}		else			{			System.err.println				( "ERROR loading, unknown audio API '" + apiName + "'" );			}		}	static public void	playAudioClip( String apiName, String audioPath )		{		if ( apiName.equalsIgnoreCase( SyslogMedia.sunAudioAPIName ) )			{			SyslogMedia.playSunAudioClip( audioPath );			}		else			{			System.err.println				( "ERROR playing, unknown audio API '" + apiName + "'" );			}		}	static public void	loadSunAudioClip( String audioPath )		{		//** add this into your application code as appropriate		File audioFile = new File( audioPath );		if ( ! audioFile.exists() )			{			System.err.println				( "ERROR could not load audio clip '"					+ audioPath + "', it does not exist." );			}		else			{			SyslogMedia.audioCache.put( audioPath, audioFile );			}		}	static public void	playSunAudioClip( String audioPath )		{		File audioFile = (File)			SyslogMedia.audioCache.get( audioPath );		if ( audioFile != null )			{			InputStream in = null;			AudioStream audioClip = null;						try {				in = new FileInputStream( audioFile );				audioClip = new AudioStream( in );				AudioPlayer.player.start( audioClip );            				}			catch ( IOException ex )				{				System.err.println					( "ERROR playing audioClip '" + audioPath						+ "':\n\t" + ex.getMessage() );				}			}		}	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?