exportSprite之七(Chunk,Stack)
Chunk.java文件源码:<wbr style="line-height:25px"><div style="line-height:25px"> <div style="line-height:25px">import java.io.*;</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"><span style="color:#993300; line-height:25px">public class Chunk</span></div> <div style="line-height:25px">{</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"> int len = 0;</div> <div style="line-height:25px"> byte type[] = new byte[4];</div> <div style="line-height:25px"> byte data[];</div> <div style="line-height:25px"> int crc;</div> <div style="line-height:25px"> Chunk()</div> <div style="line-height:25px"> {}</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">Chunk(DataInputStream in)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> read(in);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">void read(DataInputStream in)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> try</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> len=in.readInt();</div> <div style="line-height:25px"> data=new byte[len];</div> <div style="line-height:25px"> in.read(type);</div> <div style="line-height:25px"> in.read(data);</div> <div style="line-height:25px"> crc=in.readInt();</div> <div style="line-height:25px"> } catch (Exception e)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> }</div> <div style="line-height:25px">}</div> </div> <div style="line-height:25px"> <span style="line-height:25px">Stack.java文件源码</span>:</div> <div style="line-height:25px"> <div style="line-height:25px"> <span style="color:#993300; line-height:25px">public class Stack</span>{</div> <div style="line-height:25px"> int stack[];</div> <div style="line-height:25px"> int curse;</div> <div style="line-height:25px"> final static int kDefaultStackSizeMax=10;</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">Stack()</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> stack=new int [kDefaultStackSizeMax];</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">void stack(int stackMax)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> stack=new int [stackMax];</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">void creatStack(int stackMax)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> stack=new int [stackMax];</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">void push(int value)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> stack[curse++]=value;</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">int pop()</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> if(isEmpty())</div> <div style="line-height:25px"> return -1;</div> <div style="line-height:25px"> curse--;</div> <div style="line-height:25px"> return stack[curse];</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">int getTopValue()</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> if(isEmpty())</div> <div style="line-height:25px"> return -1;</div> <div style="line-height:25px"> return stack[curse-1];</div> <div style="line-height:25px"> </div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">void popAll()</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> curse=0;</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">boolean isEmpty()</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> return curse==0;</div> <div style="line-height:25px"> }</div> <div style="line-height:25px">}</div> </div> </wbr>