Exemplo n.º 1
0
  /**
   * Returns the encoded form of the given unencoded string.
   *
   * @param unencoded the string to encode
   * @return the encoded form of the unencoded string
   */
  public static String encode(String unencoded) {
    ByteArrayOutputStream out = new ByteArrayOutputStream((int) (unencoded.length() * 1.37));
    Base64Encoder encodedOut = new Base64Encoder(out);

    byte[] bytes = null;
    try {
      bytes = unencoded.getBytes("8859_1");
    } catch (UnsupportedEncodingException ignored) {
    }

    try {
      encodedOut.write(bytes);
      encodedOut.close();

      return out.toString("8859_1");
    } catch (IOException ignored) {
      return null;
    }
  }