Exemplo n.º 1
0
  /**
   * Get the FreenetURI as a string.
   *
   * @param prefix Whether to include the freenet: prefix.
   * @param pureAscii If true, encode any non-english characters. If false, only encode dangerous
   *     characters (slashes e.g.).
   */
  public String toString(boolean prefix, boolean pureAscii) {
    if (keyType == null) {
      // Not activated or something...
      Logger.minor(this, "Not activated?? in toString(" + prefix + "," + pureAscii + ")");
      return null;
    }
    StringBuilder b;
    if (prefix) b = new StringBuilder("freenet:");
    else b = new StringBuilder();

    b.append(keyType).append('@');

    if (!"KSK".equals(keyType)) {
      if (routingKey != null) b.append(Base64.encode(routingKey));
      if (cryptoKey != null) b.append(',').append(Base64.encode(cryptoKey));
      if (extra != null) b.append(',').append(Base64.encode(extra));
      if (docName != null) b.append('/');
    }

    if (docName != null) b.append(URLEncoder.encode(docName, "/", pureAscii));
    if (keyType.equals("USK")) {
      b.append('/');
      b.append(suggestedEdition);
    }
    if (metaStr != null)
      for (int i = 0; i < metaStr.length; i++) {
        b.append('/').append(URLEncoder.encode(metaStr[i], "/", pureAscii));
      }
    return b.toString();
  }
Exemplo n.º 2
0
  /**
   * Encode to a user-friendly, incomplete string with ... replacing some of the base64. Allow
   * spaces, foreign chars etc.
   */
  public String toShortString() {
    StringBuilder b = new StringBuilder();

    b.append(keyType).append('@');

    if (!"KSK".equals(keyType)) {
      b.append("...");
      if (docName != null) b.append('/');
    }

    if (docName != null) b.append(URLEncoder.encode(docName, "/", false, " "));
    if (keyType.equals("USK")) {
      b.append('/');
      b.append(suggestedEdition);
    }
    if (metaStr != null)
      for (int i = 0; i < metaStr.length; i++) {
        b.append('/').append(URLEncoder.encode(metaStr[i], "/", false, " "));
      }
    return b.toString();
  }