out.setByteOrder(ByteOrder.LITTLE_ENDIAN);
out.writeInt(MAGIC);
out.writeInt(VERSION);
for (Map.Entry<String, Attribute> entry : attributes.entrySet()) {
Attribute attr = entry.getValue();
String name = entry.getKey();
String type = attr.getClass().getAnnotation(OpenEXRAttributeType.class).value();
out.writeBytes(name);
out.writeByte(0);
out.writeBytes(type);
out.writeByte(0);
out.flush();
long attrStart = out.getStreamPosition() + 4;
out.seek(attrStart);
attr.write(out);
long attrEnd = out.getStreamPosition();
out.seek(out.getFlushedPosition());
out.writeInt((int) (attrEnd - attrStart));
out.seek(attrEnd);
out.flush();