Java Code Examples for com.squareup.okhttp.internal.Base64#encode()

The following examples show how to use com.squareup.okhttp.internal.Base64#encode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpResponseCache.java    From L.TileLayer.Cordova with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 2
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e);
  }
}
 
Example 3
Source File: HttpResponseCache.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 4
Source File: HttpResponseCache.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 5
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 6
Source File: HttpResponseCache.java    From reader with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 7
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 8
Source File: HttpResponseCache.java    From reader with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 9
Source File: HttpResponseCache.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 10
Source File: HttpResponseCache.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
    if (certificates == null) {
        writer.write("-1\n");
        return;
    }
    try {
        writer.write(Integer.toString(certificates.length) + '\n');
        for (Certificate certificate : certificates) {
            byte[] bytes = certificate.getEncoded();
            String line = Base64.encode(bytes);
            writer.write(line + '\n');
        }
    } catch (CertificateEncodingException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 11
Source File: HttpResponseCache.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 12
Source File: OkAuthenticator.java    From reader with MIT License 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}
 
Example 13
Source File: OkAuthenticator.java    From bluemix-parking-meter with MIT License 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}
 
Example 14
Source File: OkAuthenticator.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}
 
Example 15
Source File: OkAuthenticator.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an auth credential for the Basic scheme.
 */
public static Credential basic(String userName, String password) {
    try {
        String usernameAndPassword = userName + ":" + password;
        byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
        String encoded = Base64.encode(bytes);
        return new Credential("Basic " + encoded);
    } catch (UnsupportedEncodingException e) {
        throw new AssertionError();
    }
}
 
Example 16
Source File: OkAuthenticator.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}
 
Example 17
Source File: OkAuthenticator.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}
 
Example 18
Source File: OkAuthenticator.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}
 
Example 19
Source File: HttpAuthenticator.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the authorization credentials that may satisfy the challenge.
 * Returns null if a challenge header was not provided or if credentials
 * were not available.
 */
private static String getCredentials(RawHeaders responseHeaders, String challengeHeader,
    Proxy proxy, URL url) throws IOException {
  List<Challenge> challenges = parseChallenges(responseHeaders, challengeHeader);
  if (challenges.isEmpty()) {
    return null;
  }

  for (Challenge challenge : challenges) {
    // Use the global authenticator to get the password.
    PasswordAuthentication auth;
    if (responseHeaders.getResponseCode() == HTTP_PROXY_AUTH) {
      InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
      auth = Authenticator.requestPasswordAuthentication(proxyAddress.getHostName(),
          getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.getProtocol(),
          challenge.realm, challenge.scheme, url, Authenticator.RequestorType.PROXY);
    } else {
      auth = Authenticator.requestPasswordAuthentication(url.getHost(),
          getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(), challenge.realm,
          challenge.scheme, url, Authenticator.RequestorType.SERVER);
    }
    if (auth == null) {
      continue;
    }

    // Use base64 to encode the username and password.
    String usernameAndPassword = auth.getUserName() + ":" + new String(auth.getPassword());
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return challenge.scheme + " " + encoded;
  }

  return null;
}
 
Example 20
Source File: OkAuthenticator.java    From wildfly-samples with MIT License 5 votes vote down vote up
/** Returns an auth credential for the Basic scheme. */
public static Credential basic(String userName, String password) {
  try {
    String usernameAndPassword = userName + ":" + password;
    byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1");
    String encoded = Base64.encode(bytes);
    return new Credential("Basic " + encoded);
  } catch (UnsupportedEncodingException e) {
    throw new AssertionError();
  }
}