當前位置: 首頁>>代碼示例>>Java>>正文


Java Base64類代碼示例

本文整理匯總了Java中org.apache.commons.net.util.Base64的典型用法代碼示例。如果您正苦於以下問題:Java Base64類的具體用法?Java Base64怎麽用?Java Base64使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Base64類屬於org.apache.commons.net.util包,在下文中一共展示了Base64類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleCertForHttpsThroughHttpProxyWithAuth

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
private static void handleCertForHttpsThroughHttpProxyWithAuth(URL url, Proxy proxy,
        String proxyUsername, String proxyPassword, long timeout,
        SSLSocketFactory socketFactory) throws IOException {
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(proxy);

    connection.setSSLSocketFactory(socketFactory);
    connection.setConnectTimeout((int) (timeout < 0 ? 0 : timeout));
    if (proxyUsername != null && proxyPassword != null) {
        byte[] token = (proxyUsername + ":" + proxyPassword)
                .getBytes(StandardCharsets.UTF_8);

        connection.setRequestProperty(REQUEST_HEADER_PROXY_AUTHORIZATION,
                "Basic " + Base64.encodeBase64StringUnChunked(token));
    }

    connection.connect();
    connection.disconnect();
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:19,代碼來源:CertificateUtil.java

示例2: getDevices

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
public Collection<? extends Device> getDevices(List<DeviceConfiguration> configurations) {

		List<Device> devices = new ArrayList<Device>();

		byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes());

		MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage);

		while (tokenizer.hasMoreElements()) {
			byte[] token = tokenizer.nextElement();
			Device tempDevice = Device.create(token, configurations);
			if (tempDevice != null) {
				devices.add(tempDevice);
			}
		}

		return devices;
	}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:19,代碼來源:L_Message.java

示例3: BaseCommandTest

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
@Test
public void BaseCommandTest() {
	S_Command scmd = new S_Command("0b0da3", 1, ThermostatModeType.MANUAL, 20.0);
	
	String commandStr = scmd.getCommandString();
	
	String base64Data = commandStr.substring(3);
	byte[] bytes = Base64.decodeBase64(base64Data.getBytes());
	
	int[] data = new int[bytes.length];

	for (int i = 0; i < bytes.length; i++) {
		data[i] = bytes[i] & 0xFF;
	}
	
	String decodedString = Utils.toHex(data);
	assertEquals("s:AARAAAAACw2jAWg=\r\n", commandStr);
	assertEquals("011000000002C368C05A", decodedString);
	
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:21,代碼來源:S_CommandTest.java

示例4: getAsMap

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
private Map<String, String> getAsMap() throws IOException, XPathExpressionException {
  InputStream zipInputStream =
      new ZipInputStream(new ByteArrayInputStream(Base64.decodeBase64(encodedZip)));
  ZipEntry zipFileEntry;
  Map<String, String> map = new HashMap<>();
  while ((zipFileEntry = ((ZipInputStream) zipInputStream).getNextEntry()) != null) {
    if (!zipFileEntry.getName().endsWith("-site.xml")) {
      continue;
    }
    byte[] bytes = IOUtils.toByteArray(zipInputStream);
    InputSource is = new InputSource(new ByteArrayInputStream(bytes));
    XPath xPath = XPathFactory.newInstance().newXPath();
    NodeList nodeList =
        (NodeList) xPath
            .evaluate(ConfigConstants.CONF_PROPERTY_XPATH, is, XPathConstants.NODESET);
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node propNode = nodeList.item(i);
      String key = (String) xPath.evaluate("name/text()", propNode, XPathConstants.STRING);
      String value = (String) xPath.evaluate("value/text()", propNode, XPathConstants.STRING);
      map.put(key, value);
    }
  }
  return map;
}
 
開發者ID:trustedanalytics,項目名稱:broker-store,代碼行數:25,代碼來源:HadoopZipConfiguration.java

示例5: getOAuthTokenPair

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
public static JSONObject getOAuthTokenPair(String backendHTTPURL, String backendHTTPSURL) throws Exception {
    String AuthString = "Basic YWRtaW46YWRtaW4=";
    RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, AuthString);
    HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT,
                                         Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
    JSONObject jsonObj = new JSONObject(oAuthData.getData());
    String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
    String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
    byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes());
    String basicAuthString = "Basic " + new String(bytesEncoded);
    //Initiate a RestClient to get OAuth token
    client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
    oAuthData = client.post(Constants.APIApplicationRegistration.TOKEN_ENDPOINT,
                            Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD);
    jsonObj = new JSONObject(oAuthData.getData());
    return jsonObj;
}
 
開發者ID:wso2,項目名稱:product-iots,代碼行數:18,代碼來源:OAuthUtil.java

示例6: initTest

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP})
public void initTest() throws Exception {
    super.init(userMode);
    User currentUser = getAutomationContext().getContextTenant().getContextUser();
    byte[] bytesEncoded = Base64
            .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
    String encoded = new String(bytesEncoded);
    String auth_string = "Basic " + encoded;
    String anaytics_https_url = automationContext.getContextUrls().getWebAppURLHttps()
            .replace("9443", String.valueOf(Constants.HTTPS_ANALYTICS_PORT))
            .replace("/t/" + automationContext.getContextTenant().getDomain(), "") + "/";
    this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
    this.analyticsClient = new RestClient(anaytics_https_url, Constants.APPLICATION_JSON, auth_string);
    if (this.userMode == TestUserMode.TENANT_ADMIN) {
        HttpResponse response = client
                .post(Constants.AndroidSenseEnrollment.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
        Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
    }
}
 
開發者ID:wso2,項目名稱:product-iots,代碼行數:20,代碼來源:AndroidSenseEnrollment.java

示例7: createHttpStream

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
private HttpURLConnection createHttpStream()
    throws IOException {
  String apiUrl = joinUrlPath(
      joinUrlPath(config.getNavigatorUrl(),
          "api/v" + String.valueOf(config.getApiVersion())),
          "metadata/plugin");
  HttpURLConnection conn = openConnection(new URL(apiUrl));
  conn.setRequestMethod("POST");
  String userpass = config.getUsername() + ":" + config.getPassword();
  String basicAuth = "Basic " + new String(Base64.encodeBase64(
      userpass.getBytes()));
  conn.addRequestProperty("Authorization", basicAuth);
  conn.addRequestProperty("Content-Type", "application/json");
  conn.setDoOutput(true);
  return conn;
}
 
開發者ID:cloudera,項目名稱:navigator-sdk,代碼行數:17,代碼來源:MetadataWriterFactory.java

示例8: getOAuthToken

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) throws Exception {
    RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON);
    HttpResponse oAuthData = client.post(Constants.DynamicClientAuthentication.REGISTRATION_ENDPOINT,
                                         Constants.DynamicClientAuthentication.DYNAMIC_CLIENT_REGISTRATION_PAYLOAD);
    JSONObject jsonObj = new JSONObject(oAuthData.getData());
    String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
    String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
    byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes());
    String basicAuthString = "Basic " + new String(bytesEncoded);
    //Initiate a RestClient to get OAuth token
    client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
    oAuthData = client.post(Constants.DynamicClientAuthentication.TOKEN_ENDPOINT,
                            Constants.DynamicClientAuthentication.OAUTH_TOKEN_PAYLOAD);
    jsonObj = new JSONObject(oAuthData.getData());
    return jsonObj.get(Constants.OAUTH_ACCESS_TOKEN).toString();
}
 
開發者ID:wso2-attic,項目名稱:product-emm,代碼行數:17,代碼來源:OAuthUtil.java

示例9: N_Message

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
/**
 * The {@link: N_Message} contains information about a newly discovered Device
 *
 * @param raw String with raw message
 */
public N_Message(String raw) {
    super(raw);
    String msgPayload = this.getPayload();

    if (msgPayload.length() > 0) {
        try {
            decodedPayload = new String(Base64.decodeBase64(msgPayload), "UTF-8");
            byte[] bytes = Base64.decodeBase64(msgPayload);

            deviceType = DeviceType.create(bytes[0] & 0xFF);
            rfAddress = Utils.toHex(bytes[1] & 0xFF, bytes[2] & 0xFF, bytes[3] & 0xFF);

            byte[] data = new byte[10];
            System.arraycopy(bytes, 4, data, 0, 10);
            serialnr = new String(data, "UTF-8");
        } catch (Exception e) {
            logger.debug("Exception occurred during parsing of N message: {}", e.getMessage(), e);
        }
    } else {
        logger.debug("No device found during inclusion");
    }
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:28,代碼來源:N_Message.java

示例10: getDevices

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
public Collection<? extends Device> getDevices(List<DeviceConfiguration> configurations) {

        List<Device> devices = new ArrayList<Device>();

        byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes());

        MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage);

        while (tokenizer.hasMoreElements()) {
            byte[] token = tokenizer.nextElement();
            Device tempDevice = Device.create(token, configurations);
            if (tempDevice != null) {
                devices.add(tempDevice);
            }
        }

        return devices;
    }
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:19,代碼來源:L_Message.java

示例11: getCommandString

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
/**
 * Returns the Base64 encoded command string to be sent via the MAX! Cube.
 *
 * @return the string representing the command
 */
@Override
public String getCommandString() {

    StringBuilder commandConfigString = new StringBuilder();
    for (byte b : commandBytes) {
        commandConfigString.append(String.format("%02X", b));
    }

    String commandString = baseString + rfAddress;
    if (configCommandType == ConfigCommandType.SetRoom || configCommandType == ConfigCommandType.RemoveRoom) {
        commandString = commandString + commandConfigString + Utils.toHex(roomId);
    } else {
        commandString = commandString + Utils.toHex(roomId) + commandConfigString;
    }

    String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString));
    return "s:" + encodedString;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:24,代碼來源:S_ConfigCommand.java

示例12: getCommandString

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
/**
 * Returns the Base64 encoded command string to be sent via the MAX!
 * protocol.
 *
 * @return the string representing the command
 */
@Override
public String getCommandString() {

    String baseString = "";
    if (roomId == 0) {
        baseString = baseStringS;
    } else {
        baseString = baseStringG;
    }

    String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits);

    String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString));

    return "s:" + encodedString;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:23,代碼來源:S_Command.java

示例13: getCommandString

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
@Override
public String getCommandString() {
    int updateForced = 0;
    if (forceUpdate) {
        updateForced = FORCE_UPDATE;
    } else {
        updateForced = NO_FORCE_UPDATE;
    }
    byte[] commandArray = null;
    for (String rfAddress : rfAddresses) {
        commandArray = ArrayUtils.addAll(Utils.hexStringToByteArray(rfAddress), commandArray);
    }
    String encodedString = Base64.encodeBase64StringUnChunked(commandArray);

    String cmd = "t:" + String.format("%02d", rfAddresses.size()) + "," + updateForced + "," + encodedString + '\r'
            + '\n';
    return cmd;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:19,代碼來源:T_Command.java

示例14: BaseCommandTest

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
@Test
public void BaseCommandTest() {
    T_Command scmd = new T_Command("0f1d54", false);

    String commandStr = scmd.getCommandString();

    String base64Data = commandStr.split(",")[2];
    byte[] bytes = Base64.decodeBase64(base64Data.getBytes());
    int[] data = new int[bytes.length];
    for (int i = 0; i < bytes.length; i++) {
        data[i] = bytes[i] & 0xFF;
    }
    String decodedString = Utils.toHex(data);

    assertEquals("t:01,0,Dx1U\r\n", commandStr);
    assertEquals("0F1D54", decodedString);

}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:19,代碼來源:T_CommandTest.java

示例15: AddRoomTest

import org.apache.commons.net.util.Base64; //導入依賴的package包/類
@Test
public void AddRoomTest() {
    T_Command scmd = new T_Command("0f1d54", false);
    scmd.addRoom("0b0da3");

    String commandStr = scmd.getCommandString();

    String base64Data = commandStr.split(",")[2];
    byte[] bytes = Base64.decodeBase64(base64Data.getBytes());
    int[] data = new int[bytes.length];
    for (int i = 0; i < bytes.length; i++) {
        data[i] = bytes[i] & 0xFF;
    }
    String decodedString = Utils.toHex(data);

    assertEquals("t:02,0,Cw2jDx1U\r\n", commandStr);
    assertEquals("0B0DA30F1D54", decodedString);
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:19,代碼來源:T_CommandTest.java


注:本文中的org.apache.commons.net.util.Base64類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。