2 * License : The MIT License
3 * Copyright(c) 2018 olyutorskii
6 package jp.osdn.jindolf.parser.content;
8 import io.bitbucket.olyutorskii.jiocema.CharDecodeListener;
9 import io.bitbucket.olyutorskii.jiocema.DecodeBreakException;
10 import java.nio.charset.CharsetDecoder;
13 * Test listener for {@link CharDecodeListener}
15 class TestListener implements CharDecodeListener{
17 private final StringBuilder text = new StringBuilder();
21 public void startDecoding(CharsetDecoder decoder)
22 throws DecodeBreakException {
28 public void endDecoding() throws DecodeBreakException {
34 public void charContent(char[] charArray, int offset, int length)
35 throws DecodeBreakException {
37 this.text.append(charArray, offset, length);
42 public void rawBytes(byte[] byteArray, int offset, int length)
43 throws DecodeBreakException {
49 public void malformedError(byte[] errorArray, int offset, int length)
50 throws DecodeBreakException {
52 dumpHex(errorArray, offset, length);
57 public void unmapError(byte[] errorArray, int offset, int length)
58 throws DecodeBreakException {
60 dumpHex(errorArray, offset, length);
64 protected void append(CharSequence seq){
65 this.text.append(seq);
69 protected void dumpHex(byte[] errorArray, int offset, int length){
70 for(int ct = 0; ct < length; ct++){
71 dumpHex(errorArray[offset + ct]);
76 private void dumpHex(byte bVal){
77 int val = bVal & 0xff;
78 if(val <= 0xf) this.text.append('0');
79 append(Integer.toHexString(val));
89 public String toString(){
90 return text.toString();