public void read(MC68000InputStream in) throws IOException { id = in.readLONG(); long length = in.readULONG(); switch (id) { case ID_CAT: case ID_FORM: case ID_LIST: case ID_PROP: type = in.readLONG(); length -= 4; while (length > 1) { MutableIFFChunk child = new MutableIFFChunk(); child.read(in); add(child); int childLength = child.getLength(); length -= childLength + childLength % 2 + 8; } break; default: data = new byte[(int) length]; in.readFully(data, 0, (int) length); break; } if (length % 2 == 1) { in.read(); } }
public int getLength() { if (data != null) { return data.length; } else { int length = 4; for (MutableIFFChunk child : childChunks()) { int childLength = child.getLength(); length += 8 + childLength + childLength % 2; } return length; } }
public void write(MC68000OutputStream out) throws IOException { out.writeULONG(id); long length = getLength(); out.writeULONG(length); if (data == null) { out.writeULONG(type); for (MutableIFFChunk child : childChunks()) { child.write(out); } } else { out.write(data); } if (length % 2 == 1) { out.write((byte) 0); } }
public String dump(int depth) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < depth; i++) { buf.append('.'); } buf.append(idToString(getId())); buf.append(' '); buf.append(getLength()); if (getChildCount() > 0) { buf.append(' '); buf.append(idToString(getType())); for (MutableIFFChunk child : childChunks()) { buf.append('\n'); buf.append(child.dump(depth + 1)); } } return buf.toString(); }