39 lines
1.0 KiB
Java
39 lines
1.0 KiB
Java
import java.io.DataInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
|
|
class Chunk {
|
|
int length;
|
|
String type;
|
|
byte[] data;
|
|
|
|
Chunk(int length, String type, byte[] data) {
|
|
this.length = length;
|
|
this.type = type;
|
|
this.data = data;
|
|
}
|
|
|
|
static Chunk read(DataInputStream dis) throws IOException {
|
|
int length = dis.readInt();
|
|
String type = new String(dis.readNBytes(4));
|
|
byte[] data = dis.readNBytes(length);
|
|
dis.skipBytes(4);
|
|
return new Chunk(length, type, data);
|
|
}
|
|
}
|
|
|
|
public class DN10 {
|
|
public static void main(String[] args) throws IOException {
|
|
FileInputStream fis = new FileInputStream(args[0]);
|
|
DataInputStream dis = new DataInputStream(fis);
|
|
|
|
dis.skipBytes(8); // header
|
|
|
|
Chunk chunk;
|
|
do {
|
|
chunk = Chunk.read(dis);
|
|
System.out.printf("Chunk: %s, length: %d\n", chunk.type, chunk.length);
|
|
} while (!chunk.type.equals("IEND"));
|
|
}
|
|
}
|