Example usage for org.apache.commons.codec.binary Base64 encodeBase64String

List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 encodeBase64String.

Prototype

public static String encodeBase64String(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm but does not chunk the output.

Usage

From source file:mpimp.assemblxweb.util.J5FileUtils.java

public static String encodeFileBase64(String filePath) throws Exception {
    Path path = Paths.get(filePath);
    String result = "";
    try {//from  w w w  . ja  va2  s .com
        byte[] content = Files.readAllBytes(path);
        result = Base64.encodeBase64String(content);
    } catch (IOException e) {
        String message = "Error while encoding file " + filePath + ". " + e.getMessage();
        throw new AssemblXException(message, J5FileUtils.class);
    }
    return result;
}

From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java

private static void generateSketches() throws Exception {
    Path path = FileSystems.getDefault().getPath("array_of_doubles_sketch_data.tsv");
    try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
        Random rand = new Random();
        int key = 0;
        for (int i = 0; i < 20; i++) {
            ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder()
                    .setNominalEntries(1024).build();
            sketch.update(key++, new double[] { 1 });
            sketch.update(key++, new double[] { 1 });
            out.write("2015010101");
            out.write('\t');
            out.write("product_" + (rand.nextInt(10) + 1));
            out.write('\t');
            out.write(Base64.encodeBase64String(sketch.compact().toByteArray()));
            out.newLine();//  w  w w . ja v  a 2  s  . c  om
        }
    }
}

From source file:com.microsoft.rest.credentials.BasicAuthenticationCredentialsFilter.java

@Override
public void filter(HttpRequest request) {
    try {/*from   w w  w . j  a va2s. c  o  m*/
        String auth = credentials.getUserName() + ":" + credentials.getPassword();
        auth = Base64.encodeBase64String(auth.getBytes("UTF8"));
        request.setHeader("Authorization", "Basic " + auth);
    } catch (UnsupportedEncodingException e) {
        // silently fail
    }
}

From source file:cd.go.authentication.passwordfile.executor.GetPluginIconExecutor.java

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", getContentType());
    jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes(getIcon())));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));//from   w  w  w.  j a  v a2 s . com
    return defaultGoPluginApiResponse;

}

From source file:com.aqnote.shared.cryptology.cert.io.PKCSTransformer.java

public static String getCrtFileB64(X509Certificate x509Cert) throws Exception {
    return Base64.encodeBase64String(x509Cert.getEncoded());
}

From source file:com.ibm.ra.remy.web.utils.RestUtils.java

/**
 * Method to Base64 encode a string.//  w w  w.  j  a  v a 2 s . c o  m
 * 
 * @param data The string to encode
 * @return The Base 64 encoded String
 */
public String base64Encode(String data) {
    return Base64.encodeBase64String(data.getBytes());
}

From source file:com.github.nukesparrow.htmlunit.Util.java

public static String toDataUrl(WebResponse response) throws IOException {
    StringBuilder b = new StringBuilder("data:").append(response.getContentType());
    if (response.getContentCharsetOrNull() != null && !response.getContentType().contains("charset=")) {
        b.append(";charset=").append(response.getContentCharset());
    }//w ww  . j  av  a 2s  . c o  m
    b.append(";base64,");
    try (InputStream in = response.getContentAsStream()) {
        b.append(Base64.encodeBase64String(IOUtils.toByteArray(in)));
    }
    return b.toString();
}

From source file:com.proofpoint.event.blackhole.BlackholeEvent.java

public BlackholeEvent(String method, URI uri, byte[] entity) {
    Preconditions.checkNotNull(method, "method is null");
    Preconditions.checkNotNull(uri, "uri is null");
    Preconditions.checkNotNull(entity, "entity is null");

    this.method = method;
    this.uri = uri.toString();
    this.entity = Base64.encodeBase64String(entity);
}

From source file:com.netflix.zeno.diff.DiffByteArray.java

@Override
public String toString() {
    return Base64.encodeBase64String(bytes);
}

From source file:com.sg.domail.entity.SiteAccount.java

private String getPasswordHash(String password) {
    try {/* ww  w  .j ava  2  s.c  o  m*/
        byte[] passwordBytes = password.getBytes("UTF-8");
        byte[] digestBytes = md.digest(passwordBytes);
        return Base64.encodeBase64String(digestBytes);
    } catch (UnsupportedEncodingException ex) {
        throw new PlatformDoNotSupportUtf8AlgorithmException(ex);
    }
}