1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.zmpp.iff;
24
25 import org.zmpp.base.MemoryAccess;
26
27 /***
28 * This is the default implementation of the Chunk interface.
29 *
30 * @author Wei-ju Wu
31 * @version 1.0
32 */
33 public class DefaultChunk implements Chunk {
34
35 /***
36 * The memory access object.
37 */
38 protected MemoryAccess memaccess;
39
40 /***
41 * The chunk id.
42 */
43 private byte[] id;
44
45 /***
46 * The chunk size.
47 */
48 private int chunkSize;
49
50 /***
51 * Constructor.
52 *
53 * @param memaccess a memory access object to the chunk data
54 */
55 public DefaultChunk(MemoryAccess memaccess) {
56
57 this.memaccess = memaccess;
58 initBaseInfo();
59 }
60
61 /***
62 * Initialize the base information for this chunk.
63 */
64 private void initBaseInfo() {
65
66
67 id = new byte[CHUNK_ID_LENGTH];
68 for (int i = 0; i < CHUNK_ID_LENGTH; i++) {
69
70 id[i] = memaccess.readByte(i);
71 }
72
73
74 chunkSize = (int) memaccess.readUnsigned32(CHUNK_ID_LENGTH);
75 }
76
77 /***
78 * {@inheritDoc}
79 */
80 public boolean isValid() {
81
82 return true;
83 }
84
85 /***
86 * {@inheritDoc}
87 */
88 public byte[] getId() {
89
90 return id;
91 }
92
93 /***
94 * {@inheritDoc}
95 */
96 public int getSize() {
97
98 return chunkSize;
99 }
100
101 /***
102 * {@inheritDoc}
103 */
104 public MemoryAccess getMemoryAccess() {
105
106 return memaccess;
107 }
108 }