當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamHandler.setEncoding方法代碼示例

本文整理匯總了Java中java.util.logging.StreamHandler.setEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamHandler.setEncoding方法的具體用法?Java StreamHandler.setEncoding怎麽用?Java StreamHandler.setEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.logging.StreamHandler的用法示例。


在下文中一共展示了StreamHandler.setEncoding方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSetEncoding_Unsupported

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_Unsupported() {
	StreamHandler h = new StreamHandler();
	try {
		h.setEncoding("impossible");
		fail("Should throw UnsupportedEncodingException!");
	} catch (UnsupportedEncodingException e) {
		// expected
	}
	assertNull(h.getEncoding());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:11,代碼來源:StreamHandlerTest.java

示例2: testSetEncoding_FlushBeforeSetting

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_FlushBeforeSetting() throws Exception {
	ByteArrayOutputStream aos = new ByteArrayOutputStream();
	StreamHandler h = new StreamHandler(aos, new MockFormatter());
	LogRecord r = new LogRecord(Level.INFO, "abcd");
	h.publish(r);
	assertFalse(aos.toString().indexOf("abcd") > 0);
	h.setEncoding("iso-8859-1");
	assertTrue(aos.toString().indexOf("abcd") > 0);
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:10,代碼來源:StreamHandlerTest.java

示例3: testSetEncoding_Normal

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_Normal() throws Exception {
	ByteArrayOutputStream aos = new ByteArrayOutputStream();
	StreamHandler h = new StreamHandler(aos, new MockFormatter());
	h.setEncoding("iso-8859-1");
	assertEquals("iso-8859-1", h.getEncoding());
	LogRecord r = new LogRecord(Level.INFO, "\u6881\u884D\u8F69");
	h.publish(r);
	h.flush();

	byte[] bytes = encoder.encode(
			CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"))
			.array();
	assertTrue(Arrays.equals(bytes, aos.toByteArray()));
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:15,代碼來源:StreamHandlerTest.java

示例4: testSetEncoding_AfterPublish

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_AfterPublish() throws Exception {
	ByteArrayOutputStream aos = new ByteArrayOutputStream();
	StreamHandler h = new StreamHandler(aos, new MockFormatter());
	h.setEncoding("iso-8859-1");
	assertEquals("iso-8859-1", h.getEncoding());
	LogRecord r = new LogRecord(Level.INFO, "\u6881\u884D\u8F69");
	h.publish(r);
	h.flush();
	assertTrue(Arrays.equals(aos.toByteArray(), encoder.encode(
			CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"))
			.array()));

	h.setEncoding("iso8859-1");
	assertEquals("iso8859-1", h.getEncoding());
	r = new LogRecord(Level.INFO, "\u6881\u884D\u8F69");
	h.publish(r);
	h.flush();
	assertFalse(Arrays.equals(aos.toByteArray(), encoder.encode(
			CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"
					+ "testSetEncoding_Normal2")).array()));
	byte[] b0 = aos.toByteArray();
	byte[] b1 = encoder.encode(
			CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"))
			.array();
	byte[] b2 = encoder.encode(CharBuffer.wrap("\u6881\u884D\u8F69"))
			.array();
	byte[] b3 = new byte[b1.length + b2.length];
	System.arraycopy(b1, 0, b3, 0, b1.length);
	System.arraycopy(b2, 0, b3, b1.length, b2.length);
	assertTrue(Arrays.equals(b0, b3));
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:32,代碼來源:StreamHandlerTest.java

示例5: testSetGetEncoding

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public Result testSetGetEncoding() throws SecurityException, UnsupportedEncodingException {

        StreamHandler handler = new StreamHandler();
        
        for (int i=0; i< encodings.length; i++) {
            handler.setEncoding(encodings[i]);
            String enc = handler.getEncoding();
            if (!enc.equals(encodings[i])) {
                return failed ("wrong encoding: " + enc + ", should be " + encodings[i]);
            }
        }
        
        return passed();
    }
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:15,代碼來源:StreamHandlerTest.java

示例6: testSetEncoding_Null

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_Null() throws Exception {
	StreamHandler h = new StreamHandler();
	h.setEncoding(null);
	assertNull(h.getEncoding());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:6,代碼來源:StreamHandlerTest.java


注:本文中的java.util.logging.StreamHandler.setEncoding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。