private long writeEntryHeader(final ArArchiveEntry pEntry) throws IOException {

    long offset = 0;
    boolean mustAppendName = false;

    final String n = pEntry.getName();
    if (LONGFILE_ERROR == longFileMode && n.length() > 16) {
      throw new IOException("filename too long, > 16 chars: " + n);
    }
    if (LONGFILE_BSD == longFileMode && (n.length() > 16 || n.indexOf(" ") > -1)) {
      mustAppendName = true;
      offset += write(ArArchiveInputStream.BSD_LONGNAME_PREFIX + String.valueOf(n.length()));
    } else {
      offset += write(n);
    }

    offset = fill(offset, 16, ' ');
    final String m = "" + (pEntry.getLastModified());
    if (m.length() > 12) {
      throw new IOException("modified too long");
    }
    offset += write(m);

    offset = fill(offset, 28, ' ');
    final String u = "" + pEntry.getUserId();
    if (u.length() > 6) {
      throw new IOException("userid too long");
    }
    offset += write(u);

    offset = fill(offset, 34, ' ');
    final String g = "" + pEntry.getGroupId();
    if (g.length() > 6) {
      throw new IOException("groupid too long");
    }
    offset += write(g);

    offset = fill(offset, 40, ' ');
    final String fm = "" + Integer.toString(pEntry.getMode(), 8);
    if (fm.length() > 8) {
      throw new IOException("filemode too long");
    }
    offset += write(fm);

    offset = fill(offset, 48, ' ');
    final String s = String.valueOf(pEntry.getLength() + (mustAppendName ? n.length() : 0));
    if (s.length() > 10) {
      throw new IOException("size too long");
    }
    offset += write(s);

    offset = fill(offset, 58, ' ');

    offset += write(ArArchiveEntry.TRAILER);

    if (mustAppendName) {
      offset += write(n);
    }

    return offset;
  }