*/
public class SjisDecoder extends StreamDecoder{
- /** 入力バッファに必要な最小サイズ(={@value})。 */
- public static final int MIN_INBUFSZ = ShiftJis.MAX_BYTES_PER_CHAR * 2 + 1;
-
- static{
- assert MIN_INBUFSZ <= BYTEBUF_DEFSZ;
- }
-
/**
* コンストラクタ。
*/
public SjisDecoder(int inbufSz, int outbufSz)
throws IllegalArgumentException{
super(ShiftJis.CHARSET.newDecoder(), inbufSz, outbufSz);
- if(inbufSz < MIN_INBUFSZ){
- throw new IllegalArgumentException();
- }
return;
}
sjd.decode(is);
assertEquals("[ST][CH]ABC[EN]", handler.toString());
+ sjd = new SjisDecoder(10, 2);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("414243");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]AB[CH]C[EN]", handler.toString());
+
+ sjd = new SjisDecoder(2, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("82a0:82a1");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]あぃ[EN]", handler.toString());
+
+ sjd = new SjisDecoder(2, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("41:82a0:82a1");
+ handler.clear();
+ sjd.decode(is);
+ assertEquals("[ST][CH]Aあぃ[EN]", handler.toString());
+
+ sjd = new SjisDecoder(1, 10);
+ sjd.setDecodeHandler(handler);
+ is = byteIs("82a0:82a1");
+ handler.clear();
+ try{
+ sjd.decode(is);
+ fail();
+ }catch(DecodeException e){
+ // GOOD
+ }
+
return;
}