This commit is contained in:
Gašper Dobrovoljc 2024-05-22 15:06:06 +02:00
parent 84a6f51bd1
commit 75eb6fa962
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5
2 changed files with 38 additions and 0 deletions

38
src/DN10.java Normal file
View File

@ -0,0 +1,38 @@
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"));
}
}

BIN
viri/lion.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB