00001 package Decoder.iterators; 00002 00003 import java.io.IOException; 00004 import java.util.ArrayList; 00005 00006 import debuggingCode.Debug; 00007 00008 import junit.framework.Assert; 00009 00010 import CodingUtils.ByteConvertor; 00011 import Decoder.MyDataInPutStream; 00012 import HuffMan.NotEnoughBytesException; 00013 import ImageStuff.GenericEdge; 00014 import TxTPackage.DecodedFileWithRealValues; 00015 00016 00023 public class NormalOffsetIterator { 00024 00025 MyDataInPutStream dis; 00026 ArrayList<String> bitlist; 00027 int aantalnormaloffsets; 00028 public NormalOffsetIterator(MyDataInPutStream dis){ 00029 this.dis=dis; 00030 aantalnormaloffsets=dis.readMyShort(); 00031 bitlist=new ArrayList<String>(); 00032 } 00033 00034 00035 00036 public int getNextNormalOffset(GenericEdge genericEdge){ 00037 int lengte=ByteConvertor.nbrBitsForNbrCodeWords(genericEdge.getLengte()); 00038 int normalOffset=getNextNormalOffset(lengte); 00039 if(Debug.DEBUG_DECODER_FILE){ 00040 DecodedFileWithRealValues.getStructuredFile().schrijf(""+normalOffset); 00041 DecodedFileWithRealValues.getStructuredFile().nieuweLijn(); 00042 }return normalOffset; 00043 } 00044 00051 private int getNextNormalOffset(int length){ 00052 00053 while(bitlist.size()<length){ 00054 int getal=0; 00055 try{getal= dis.readMyByte();}catch(IOException exception){exception.printStackTrace(System.out);} 00056 bitlist.addAll(ByteConvertor.getStringArrayListofBitsFor(getal,ByteConvertor.BITS_PER_BYTE)); 00057 } 00058 00059 Assert.assertTrue(bitlist.size()>=length); 00060 Assert.assertTrue(bitlist.size()<=length+ByteConvertor.BITS_PER_BYTE); 00061 00062 String str=""; 00063 for(int k=0;k!=length;k++){ 00064 str=str.concat(bitlist.remove(0)); // removes "length" bits from list 00065 } 00066 int offset=ByteConvertor.getIntegerfor(str.toCharArray()); 00067 00068 return offset; 00069 } 00070 00071 00072 00073 public int getAantalnormaloffsets() { 00074 return aantalnormaloffsets; 00075 } 00076 00077 00078 }
1.5.5