private String sanitizeName(String name) {

    // Check null name
    if (null == name) {
      throw new IllegalArgumentException("Entry name cannot be [null]");
    }

    // Trim name
    String sanitizedName= name.replaceAll("[/ .]+$", "").replaceAll("^[/ .]+", "");

    // Check for invalid characters in entry name
    for (char c : XarEntry.NAME_ILLEGAL_CHARACTERS) {
      if (sanitizedName.contains("" + c)) {
        throw new IllegalArgumentException("Entry name [" + sanitizedName + "] contains illegal character [" + c + "]");
      }
    }

    // Check name length
    try {
      if (sanitizedName.getBytes("ISO-8859-1").length > NAME_MAXLEN) {
        throw new IllegalArgumentException(
          "XAR entry names [" + sanitizedName + "] must be shorter than " + NAME_MAXLEN + " bytes"
        );
      }
    } catch (UnsupportedEncodingException ex) {
      throw new IllegalArgumentException("Unsupported character encoding [ISO-8859-1]", ex);
    }

    return sanitizedName;
  }