本文整理匯總了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());
}
示例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);
}
示例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()));
}
示例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));
}
示例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();
}
示例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());
}