@Override
public void decodingError(byte[] errorArray, int offset, int length)
throws DecodeException{
+ DecodedContent text = getContent();
+
+ switch(length){
+ case 1:
+ text.addDecodeError(errorArray[0]);
+ return;
+ case 2:
+ text.addDecodeError(errorArray[0], errorArray[1]);
+ return;
+ default:
+ break;
+ }
+
int limit = offset + length;
for(int bpos = offset; bpos < limit; bpos++){
byte bval = errorArray[bpos];
if(this.hasByte1st){
if(ShiftJis.isShiftJIS2ndByte(bval)){ // 文字集合エラー
- getContent().addDecodeError(this.byte1st, bval);
+ text.addDecodeError(this.byte1st, bval);
this.hasByte1st = false;
}else if(ShiftJis.isShiftJIS1stByte(bval)){
- getContent().addDecodeError(this.byte1st);
+ text.addDecodeError(this.byte1st);
this.byte1st = bval;
this.hasByte1st = true;
}else{
- getContent().addDecodeError(this.byte1st);
- getContent().addDecodeError(bval);
+ text.addDecodeError(this.byte1st);
+ text.addDecodeError(bval);
this.hasByte1st = false;
}
}else{
this.byte1st = bval;
this.hasByte1st = true;
}else{
- getContent().addDecodeError(bval);
+ text.addDecodeError(bval);
}
}
-
}
return;
return;
}
+
/**
* 1バイトのエラーをUnmap系2バイトエラーに統合できないか試す。
*
*
* @param result デコード異常系
* @return 修正されたデコード異常系。修正がなければ引数と同じものを返す。
- * @throws IOException 入力エラー
+ * @throws IOException 追加入力エラー
*/
private CoderResult modify1ByteError(CoderResult result)
throws IOException {
byte next = inbuffer.get(nextPos);
CoderResult newResult;
- if( ! ShiftJis.isShiftJIS(curr, next) ){
- newResult = CoderResult.malformedForLength(1);
- }else{
+ if( ShiftJis.isShiftJIS(curr, next) ){
newResult = result;
+ }else{
+ newResult = CoderResult.malformedForLength(1);
}
return newResult;
// GOOD
}
+ sjd = new SjisDecoder(4, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("41:8540:42");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]A[ER]8540[CH]B[EN]", handler.toString());
+
+ sjd = new SjisDecoder(4, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("414243:8540:44");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]ABC[ER]8540[CH]D[EN]", handler.toString());
+
+ sjd = new SjisDecoder(4, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("414243:85");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]ABC[ER]85[EN]", handler.toString());
+
+ sjd = new SjisDecoder(4, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("41:ff32:42");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]A[ER]ff[CH]2B[EN]", handler.toString());
+
+ sjd = new SjisDecoder(4, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("414243:ff32:44");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]ABC[ER]ff[CH]2D[EN]", handler.toString());
+
return;
}