4 * Copyright(c) 2009 olyutorskii
\r
5 * $Id: DecodeException.java 894 2009-11-04 07:26:59Z olyutorskii $
\r
8 package jp.sourceforge.jindolf.parser;
\r
12 * {@link DecodeHandler}の各メソッドは、この例外をスローすることで
\r
13 * デコード処理の即時停止を{@link StreamDecoder}に指示することができる。
\r
14 * デコード元(バイトストリーム)の中のエラー発生位置と
\r
15 * デコード先(CharSequence)の中のエラー発生位置を保持することができる。
\r
16 * いずれの値も、エラー発生位置が不明な場合は負の値が設定される。
\r
18 @SuppressWarnings("serial")
\r
19 public class DecodeException extends Exception{
\r
21 private final int bytePos;
\r
22 private final int charPos;
\r
27 public DecodeException(){
\r
34 * @param message メッセージ
\r
36 public DecodeException(String message){
\r
37 this(message, -1, -1);
\r
43 * 位置情報が不明な場合は負の値を渡す。
\r
44 * @param bytePos デコード元エラー発生バイト位置
\r
45 * @param charPos デコード先エラー発生文字位置
\r
47 public DecodeException(int bytePos, int charPos){
\r
48 this(null, bytePos, charPos);
\r
54 * 位置情報が不明な場合は負の値を渡す。
\r
55 * @param message メッセージ
\r
56 * @param bytePos デコード元エラー発生バイト位置
\r
57 * @param charPos デコード先エラー発生文字位置
\r
59 public DecodeException(String message, int bytePos, int charPos){
\r
61 this.bytePos = bytePos;
\r
62 this.charPos = charPos;
\r
69 * @return エラー発生位置。不明な場合は負の値。
\r
71 public int getBytePos(){
\r
72 return this.bytePos;
\r
78 * @return エラー発生位置。不明な場合は負の値。
\r
80 public int getCharPos(){
\r
81 return this.charPos;
\r
86 * @return {@inheritDoc}
\r
89 public String getMessage(){
\r
90 StringBuilder result = new StringBuilder();
\r
92 String message = super.getMessage();
\r
93 if(message != null && message.length() > 0){
\r
94 result.append(message).append(' ');
\r
97 result.append("bytePos=").append(this.bytePos);
\r
99 result.append("charPos=").append(this.charPos);
\r
101 return result.toString();
\r