public static long getOffset(DataOutput stream) throws IOException {
    if (stream instanceof RandomAccessFile raf) return raf.getFilePointer();
    if (stream instanceof DataOutputStream dos) return dos.size();
    throw new IOException("RandomAccessFile or DataOutputStream expected, got " + stream.getClass().getName());
  }
public static long getOffset(DataOutput stream)