OSDN Git Service

ホレリス文字列読み込みに対応
authorOlyutorskii <olyutorskii@users.osdn.me>
Wed, 25 May 2011 14:25:51 +0000 (23:25 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Wed, 25 May 2011 14:25:51 +0000 (23:25 +0900)
src/main/java/jp/sourceforge/mikutoga/parser/CommonParser.java

index d64b52e..6e3369a 100644 (file)
@@ -259,7 +259,6 @@ public class CommonParser {
      * IO入力は指定バイト数だけ読み進められる。
      * ゼロ終端が見つからないまま指定バイト数が読み込み終わった場合、
      * そこまでのデータから文字列を構成する。
-     *
      * @param maxlen 読み込みバイト数
      * @return デコードされた文字列
      * @throws IOException IOエラー
@@ -278,4 +277,48 @@ public class CommonParser {
         return result;
     }
 
+    /**
+     * 4byte整数によるバイト列長とそれに続くUTF8バイト列を
+     * 文字にデコードする。
+     * @return デコードされた文字列。
+     * @throws IOException IOエラー
+     * @throws MmdEofException 予期せぬ入力終端
+     * @throws MmdFormatException 不正な文字エンコーディングが検出された。
+     */
+    protected String parseHollerithUtf8()
+            throws IOException,
+                   MmdEofException,
+                   MmdFormatException {
+        int byteLen = this.source.parseInteger();
+
+        CharBuffer encoded =
+                this.decoderUTF8.parseString(this.source, byteLen);
+
+        String result = encoded.toString();
+
+        return result;
+    }
+
+    /**
+     * 4byte整数によるバイト列長とそれに続くUTF16-LEバイト列を
+     * 文字にデコードする。
+     * @return デコードされた文字列。
+     * @throws IOException IOエラー
+     * @throws MmdEofException 予期せぬ入力終端
+     * @throws MmdFormatException 不正な文字エンコーディングが検出された。
+     */
+    protected String parseHollerithUtf16LE()
+            throws IOException,
+                   MmdEofException,
+                   MmdFormatException {
+        int byteLen = this.source.parseInteger();
+
+        CharBuffer encoded =
+                this.decoderUTF16LE.parseString(this.source, byteLen);
+
+        String result = encoded.toString();
+
+        return result;
+    }
+
 }