OSDN Git Service

41c32065fb84f02ecf80ffef797e119230fc3af5
[jindolf/JinParser.git] / src / main / java / jp / sourceforge / jindolf / parser / DecodeHandler.java
1 /*
2  * decode handler
3  *
4  * License : The MIT License
5  * Copyright(c) 2009 olyutorskii
6  */
7
8 package jp.sourceforge.jindolf.parser;
9
10 import java.nio.charset.CharsetDecoder;
11
12 /**
13  * 文字デコードハンドラ。
14  * {@link StreamDecoder}により呼ばれる。
15  * メソッドが呼ばれる順番は
16  * {@link #startDecoding}が最初で
17  * {@link #endDecoding}が最後。
18  * その間、{@link #charContent}
19  * または{@link #decodingError}が複数回呼ばれる。
20  * 各メソッドは、{@link DecodeException}をスローすることで
21  * デコード処理を中止させることができる。
22  */
23 public interface DecodeHandler{
24
25     /**
26      * デコード開始の通知を受け取る。
27      * @param decoder デコーダ
28      * @throws DecodeException デコードエラー
29      */
30     void startDecoding(CharsetDecoder decoder)
31             throws DecodeException;
32
33     /**
34      * 正常にデコードした文字列の通知を受け取る。
35      * seqの内容は、ハンドラ呼び出し元で随時変更されうる。
36      * seqの内容を後々再利用するつもりなら、
37      * 制御を呼び出し元に戻すまでの間に必要な箇所をコピーする必要がある。
38      * @param seq 文字列
39      * @throws DecodeException デコードエラー
40      */
41     void charContent(CharSequence seq)
42             throws DecodeException;
43
44     /**
45      * デコードエラーの通知を受け取る。
46      * errorArrayの内容は、ハンドラ呼び出し元で随時変更されうる。
47      * errorArrayの内容を後々再利用するつもりなら、
48      * 制御を呼び出し元に戻すまでの間に必要な箇所をコピーする必要がある。
49      * @param errorArray エラーを引き起こした入力バイトシーケンス。
50      * @param offset errorArrayに含まれるエラーの開始位置。
51      * @param length errorArrayに含まれるエラーのバイト長。
52      * @throws DecodeException デコードエラー
53      */
54     void decodingError(byte[] errorArray, int offset, int length)
55             throws DecodeException;
56
57     /**
58      * デコード終了の通知を受け取る。
59      * @throws DecodeException デコードエラー
60      */
61     void endDecoding()
62             throws DecodeException;
63
64 }