exif: Java parsing library

This page hosts a formal specification of exif using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.


Parse a local file and get structure in memory:

Exif data = Exif.fromFile("path/to/local/file.exif");

Or parse structure from a byte array:

byte[] someArray = new byte[] { ... };
Exif data = new Exif(new KaitaiStream(someArray));

After that, one can get various attributes from the structure by invoking getter methods like:

data.endianness() // => get endianness

Java source code to parse exif


// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;

public class Exif extends KaitaiStruct {
    public static Exif fromFile(String fileName) throws IOException {
        return new Exif(new ByteBufferKaitaiStream(fileName));

    public Exif(KaitaiStream _io) {
        this(_io, null, null);

    public Exif(KaitaiStream _io, KaitaiStruct _parent) {
        this(_io, _parent, null);

    public Exif(KaitaiStream _io, KaitaiStruct _parent, Exif _root) {
        this._parent = _parent;
        this._root = _root == null ? this : _root;
    private void _read() {
        this.endianness = this._io.readU2le();
        switch (endianness()) {
        case 18761: {
            this.body = new ExifLe(this._io);
        case 19789: {
            this.body = new ExifBe(this._io);
    private int endianness;
    private KaitaiStruct body;
    private Exif _root;
    private KaitaiStruct _parent;
    public int endianness() { return endianness; }
    public KaitaiStruct body() { return body; }
    public Exif _root() { return _root; }
    public KaitaiStruct _parent() { return _parent; }