当前位置: 首页>>代码示例>>Java>>正文


Java SocketHandler类代码示例

本文整理汇总了Java中java.util.logging.SocketHandler的典型用法代码示例。如果您正苦于以下问题:Java SocketHandler类的具体用法?Java SocketHandler怎么用?Java SocketHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SocketHandler类属于java.util.logging包,在下文中一共展示了SocketHandler类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConstructor_InvalidPort

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testConstructor_InvalidPort() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.level", "FINE");
	p.put("java.util.logging.SocketHandler.filter", className
			+ "$MockFilter");
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.encoding", "iso-8859-1");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666i");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	try {
		h = new SocketHandler();
		fail("Should throw IllegalArgumentException!");
	} catch (IllegalArgumentException e) {

	}
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SocketHandlerTest.java

示例2: testClose_SufficientPrivilege_NormalClose

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);

	h = new SocketHandler();
	h.publish(new LogRecord(Level.SEVERE,
			"testClose_SufficientPrivilege_NormalClose msg"));
	h.close();
	assertEquals("MockFormatter_Head"
			+ "testClose_SufficientPrivilege_NormalClose msg"
			+ "MockFormatter_Tail", thread.getReadString());
	h.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:24,代码来源:SocketHandlerTest.java

示例3: testClose_SufficientPrivilege_DirectClose

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);

	h = new SocketHandler();
	h.setLevel(Level.INFO);

	h.close();
	assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
			.getReadString());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:SocketHandlerTest.java

示例4: testPublish_WithFilter

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testPublish_WithFilter() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);
	h = new SocketHandler();
	h.setLevel(Level.INFO);
	h.setFilter(new MockFilter());

	System.setErr(new PrintStream(new ByteArrayOutputStream()));

	LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
	h.setLevel(Level.INFO);
	h.publish(r);
	h.close();
	assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
			.getReadString());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:SocketHandlerTest.java

示例5: testPublish_Null

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testPublish_Null() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);
	h = new SocketHandler();
	h.setLevel(Level.INFO);
	try {
		h.publish(null);
	} finally {
		h.close();
		// ensure the thread exits and the port becomes available again
		thread.getReadString();
	}
}
 
开发者ID:shannah,项目名称:cn1,代码行数:24,代码来源:SocketHandlerTest.java

示例6: testPublish_EmptyMsg

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testPublish_EmptyMsg() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);
	h = new SocketHandler();
	h.setLevel(Level.INFO);
	LogRecord r = new LogRecord(Level.INFO, "");
	h.publish(r);
	h.close();
	assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
			.getReadString());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:SocketHandlerTest.java

示例7: testPublish_NullMsg

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testPublish_NullMsg() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);
	h = new SocketHandler();
	h.setLevel(Level.INFO);
	LogRecord r = new LogRecord(Level.INFO, null);
	h.publish(r);
	h.close();
	assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
			.getReadString());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:SocketHandlerTest.java

示例8: run

import java.util.logging.SocketHandler; //导入依赖的package包/类
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.ALL, null, null, SimpleFormatter.class,
        ConfiguredHandler.class, 1000, Level.SEVERE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.ALL, null, null, SimpleFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.INFO, null, null, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.ALL, null, null, XMLFormatter.class);
    } catch (IOException e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:HandlersConfigTest.java

示例9: main

import java.util.logging.SocketHandler; //导入依赖的package包/类
public static void main(String argv[]) {
	FileAppender fa = new FileAppender();
	RollingFileAppender rfa = new RollingFileAppender();
	DailyRollingFileAppender drfa = new DailyRollingFileAppender();
	FileHandler fh = new FileHandler();
	SocketHandler sh = new SocketHandler("host", 1);
}
 
开发者ID:windup,项目名称:windup-rulesets,代码行数:8,代码来源:Logging.java

示例10: testClose_InsufficientPrivilege

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testClose_InsufficientPrivilege() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);

	h = new SocketHandler();
	h.setLevel(Level.INFO);

	SecurityManager oldMan = System.getSecurityManager();
	System.setSecurityManager(new MockSecurityManager());
	try {
		h.close();
		fail("Should throw SecurityException!");
	} catch (SecurityException e) {
	} finally {
		System.setSecurityManager(oldMan);
		h.close();
		// ensure the thread exits and the port becomes available again
		thread.getReadString();
	}
}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:SocketHandlerTest.java

示例11: testPublish_NoFilter

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testPublish_NoFilter() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);

	h = new SocketHandler();
	h.setLevel(Level.INFO);

	LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
	h.setLevel(Level.INFO);
	h.publish(r);

	h.setLevel(Level.WARNING);
	h.publish(r);

	h.setLevel(Level.CONFIG);
	h.publish(r);

	r.setLevel(Level.OFF);
	h.setLevel(Level.OFF);
	h.publish(r);
	h.close();
	assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
			+ "testPublish_NoFilter" + "MockFormatter_Tail", thread
			.getReadString());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:36,代码来源:SocketHandlerTest.java

示例12: testPublish_AfterClose

import java.util.logging.SocketHandler; //导入依赖的package包/类
public void testPublish_AfterClose() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.SocketHandler.formatter", className
			+ "$MockFormatter");
	p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
	p.put("java.util.logging.SocketHandler.port", "6666");
	LOG_MANAGER.readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	// start the server to be ready to accept log messages
	ServerThread thread = new ServerThread();
	thread.start();
	Thread.sleep(2000);
	h = new SocketHandler();
	h.setLevel(Level.FINE);

	assertSame(h.getLevel(), Level.FINE);
	LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFormatter");
	assertTrue(h.isLoggable(r));
	h.close();
	// ensure the thread exits and the port becomes available again
	thread.getReadString();
	// assertFalse(h.isLoggable(r));
	h.publish(r);
	h.flush();
	// assertEquals("MockFormatter_Head",
	// this.errSubstituteStream.toString());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:SocketHandlerTest.java


注:本文中的java.util.logging.SocketHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。