X-Git-Url: http://git.osdn.net/view?p=mikutoga%2FTogaGem.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fjp%2Fsfjp%2Fmikutoga%2Fbin%2Fexport%2FTextExporter.java;fp=src%2Fmain%2Fjava%2Fjp%2Fsourceforge%2Fmikutoga%2Fbinio%2FTextExporter.java;h=bba9017263c7d28de2d09d74888f657d8e8707e3;hp=dc5a08e13b60b0ca0f0f14a6887f1a2bd02dd6b0;hb=2afbea9380c472bb23e76a29bd366cad1cb0465c;hpb=9bea9f0d9a2cd86cda19baf0690c3fda87cbf64d diff --git a/src/main/java/jp/sourceforge/mikutoga/binio/TextExporter.java b/src/main/java/jp/sfjp/mikutoga/bin/export/TextExporter.java similarity index 96% rename from src/main/java/jp/sourceforge/mikutoga/binio/TextExporter.java rename to src/main/java/jp/sfjp/mikutoga/bin/export/TextExporter.java index dc5a08e..bba9017 100644 --- a/src/main/java/jp/sourceforge/mikutoga/binio/TextExporter.java +++ b/src/main/java/jp/sfjp/mikutoga/bin/export/TextExporter.java @@ -5,7 +5,7 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.binio; +package jp.sfjp.mikutoga.bin.export; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -49,9 +49,13 @@ public class TextExporter { if(encoder == null) throw new NullPointerException(); this.encoder = encoder; + this.encoder.reset(); this.encoder.onMalformedInput(CodingErrorAction.REPORT); this.encoder.onUnmappableCharacter(CodingErrorAction.REPORT); + this.cbuf.clear(); + this.bbuf.clear(); + return; } @@ -80,8 +84,10 @@ public class TextExporter { public void setCharBufSize(int newSize) throws IllegalArgumentException { if(newSize <= 0) throw new IllegalArgumentException(); + this.cbuf = CharBuffer.allocate(newSize); this.cbuf.clear(); + return; } @@ -96,9 +102,11 @@ public class TextExporter { float ratio = this.encoder.maxBytesPerChar(); int minSz = (int)( StrictMath.floor(ratio) ); if(newSize < minSz) throw new IllegalArgumentException(); + this.barray = new byte[newSize]; this.bbuf = ByteBuffer.wrap(this.barray); this.bbuf.clear(); + return; } @@ -185,7 +193,8 @@ public class TextExporter { /** * 入力バッファに文字を埋める。 - *

入力バッファが一杯になるか入力文字列がなくなるまでバッファが埋められる。 + *

入力バッファが一杯になるか + * 入力文字列がなくなるまでバッファが埋められる。 */ private void loadCharBuffer(){ while(this.cbuf.hasRemaining() && hasMoreInput()){