Example usage for javax.xml.bind DatatypeConverter printBase64Binary

List of usage examples for javax.xml.bind DatatypeConverter printBase64Binary

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter printBase64Binary.

Prototype

public static String printBase64Binary(byte[] val) 

Source Link

Document

Converts an array of bytes into a string.

Usage

From source file:com.sitewhere.hbase.device.HBaseDeviceEvent.java

/**
 * Creates a base 64 encoded String for unique event key.
 * /*from ww  w  .j a v a 2 s  .  c  om*/
 * @param rowkey
 * @param qualifier
 * @return
 */
public static String getEncodedEventId(byte[] rowkey, byte[] qualifier) {
    ByteBuffer buffer = ByteBuffer.allocate(rowkey.length + qualifier.length);
    buffer.put(rowkey);
    buffer.put(qualifier);
    return DatatypeConverter.printBase64Binary(buffer.array());
}

From source file:fr.inria.oak.paxquery.translation.Logical2Pact.java

private static final Operator<Record>[] translate(CartesianProduct cp) {
    Operator<Record>[] childPlan1 = translate(cp.getLeft());
    Operator<Record>[] childPlan2 = translate(cp.getRight());

    // create CrossOperator for cartesian product
    CrossOperator cartesianProduct = CrossOperator.builder(CartesianProductOperator.class).input1(childPlan1)
            .input2(childPlan2).name("Product").build();

    // cartesian product configuration
    final String encodedNRSMD1 = DatatypeConverter
            .printBase64Binary(SerializationUtils.serialize(cp.getLeft().getNRSMD()));
    cartesianProduct.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
    final String encodedNRSMD2 = DatatypeConverter
            .printBase64Binary(SerializationUtils.serialize(cp.getRight().getNRSMD()));
    cartesianProduct.setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);

    return new Operator[] { cartesianProduct };
}

From source file:org.ocelotds.integration.AbstractOcelotTest.java

private ClientEndpointConfig createClientEndpointConfigWithJsession(final String jsession,
        final String userpwd) {
    ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() {
        @Override/*  w ww.  java 2 s . co  m*/
        public void beforeRequest(Map<String, List<String>> headers) {
            if (null != jsession) {
                headers.put("Cookie", Arrays.asList("JSESSIONID=" + jsession));
            }
            headers.put("Authorization",
                    Arrays.asList("Basic " + DatatypeConverter.printBase64Binary(userpwd.getBytes())));
        }
    };
    return ClientEndpointConfig.Builder.create().configurator(configurator).build();
}

From source file:fr.inria.oak.paxquery.translation.Logical2Pact.java

private static final Operator<Record>[] translate(Join j) {
    Operator<Record>[] childPlan1 = translate(j.getLeft());
    Operator<Record>[] childPlan2 = translate(j.getRight());

    Operator<Record>[] join;/*from ww  w .j a va 2s  . c o m*/

    if (!j.getPred().isOnlyEqui()) { //THETA INNER JOIN
        // create CrossOperator for theta join
        join = new Operator[] { CrossOperator.builder(ThetaJoinOperator.class).input1(childPlan1)
                .input2(childPlan2).name("JoinEval").build() };

        //  for theta join configuration
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getLeft().getNRSMD()));
        join[0].setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getRight().getNRSMD()));
        join[0].setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);
        final String encodedPredicate = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getPred()));
        join[0].setParameter(PACTOperatorsConfiguration.PRED_BINARY.toString(), encodedPredicate);
    } else if (j.getPred() instanceof DisjunctivePredicate
            && ((DisjunctivePredicate) j.getPred()).getConjunctivePreds().size() != 1) { //DISJ INNER JOIN
        // create CoGroup contracts for disjunctive equi join
        DisjunctivePredicate disjPred = (DisjunctivePredicate) j.getPred();
        final int[][] leftColumns = j.getPred().getLeftColumns();
        final int[][] rightColumns = j.getPred().getRightColumns();

        //Parameters that will be used later for configuring each contract
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getLeft().getNRSMD()));
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getRight().getNRSMD()));
        final String encodedPredicate = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(disjPred));

        final NestedMetadata leftNRSMD = j.getLeft().getNRSMD();

        //We create the join with the number of contracts needed for evaluation
        join = new Operator[disjPred.getConjunctivePreds().size()];
        for (int i = 0; i < join.length; i++) {
            JoinOperator.Builder conjEquiJoinBuilder = JoinOperator.builder(DisjEquiJoinOperator.class,
                    MetadataTypesMapping.getKeyClass(leftNRSMD.getType(leftColumns[i][0])), leftColumns[i][0],
                    rightColumns[i][0] - leftNRSMD.getColNo());
            conjEquiJoinBuilder.input1(childPlan1).input2(childPlan2).name("JoinEval(" + i + ")");

            for (int k = 1; k < leftColumns[i].length; k++)
                KeyFactoryOperations.addKey(conjEquiJoinBuilder,
                        MetadataTypesMapping.getKeyClass(leftNRSMD.getType(leftColumns[i][k])),
                        leftColumns[i][k], rightColumns[i][k] - leftNRSMD.getColNo());

            join[i] = conjEquiJoinBuilder.build();
            // join configuration
            join[i].setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
            join[i].setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);
            join[i].setParameter(PACTOperatorsConfiguration.PRED_BINARY.toString(), encodedPredicate);
            join[i].setParameter(PACTOperatorsConfiguration.PRED_INT.toString(), i);
        }
    } else { //CONJ INNER JOIN
        // create JoinOperator for conjunctive equi join
        final int[] leftColumns = j.getPred().getLeftColumns()[0];
        final int[] rightColumns = j.getPred().getRightColumns()[0];

        final NestedMetadata leftNRSMD = j.getLeft().getNRSMD();

        JoinOperator.Builder conjEquiJoinBuilder = JoinOperator.builder(ConjEquiJoinOperator.class,
                MetadataTypesMapping.getKeyClass(leftNRSMD.getType(leftColumns[0])), leftColumns[0],
                rightColumns[0] - leftNRSMD.getColNo());
        conjEquiJoinBuilder.input1(childPlan1).input2(childPlan2).name("JoinConcat");

        for (int i = 1; i < leftColumns.length; i++)
            KeyFactoryOperations.addKey(conjEquiJoinBuilder,
                    MetadataTypesMapping.getKeyClass(leftNRSMD.getType(leftColumns[i])), leftColumns[i],
                    rightColumns[i] - leftNRSMD.getColNo());

        join = new Operator[] { conjEquiJoinBuilder.build() };
        // for equi join configuration
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getLeft().getNRSMD()));
        join[0].setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(j.getRight().getNRSMD()));
        join[0].setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);
    }

    return join;
}

From source file:io.fabric8.elasticsearch.ElasticsearchIntegrationTest.java

public static String encodeBasicHeader(final String username, final String password) {
    return new String(DatatypeConverter.printBase64Binary(
            (username + ":" + Objects.requireNonNull(password)).getBytes(StandardCharsets.UTF_8)));
}

From source file:com.microsoft.azure.vmagent.AzureVMAgentTemplate.java

public static String generateUniqueStorageAccountName(final String resourceGroupName,
        final ServicePrincipal servicePrincipal) {
    try {/*from   w w  w. j  a  va2 s  .  c o m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        if (null != servicePrincipal && !StringUtils.isEmpty(servicePrincipal.getSubscriptionId()))
            md.update(servicePrincipal.getSubscriptionId().getBytes("UTF-8"));
        if (null != resourceGroupName)
            md.update(resourceGroupName.getBytes("UTF-8"));

        String uid = DatatypeConverter.printBase64Binary(md.digest());
        uid = uid.substring(0, 22);
        uid = uid.toLowerCase();
        uid = uid.replaceAll("[^a-z0-9]", "a");
        return "jn" + uid;
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
        LOGGER.log(Level.WARNING,
                "Could not genetare UID from the resource group name. Will fallback on using the resource group name.",
                e);
        return "";
    }
}

From source file:fr.inria.oak.paxquery.translation.Logical2Pact.java

private static final Operator<Record>[] translate(LeftOuterJoin loj) {
    Operator<Record>[] childPlan1 = translate(loj.getLeft());
    Operator<Record>[] childPlan2 = translate(loj.getRight());

    Operator<Record>[] conjLeftOuterJoin;

    if (!loj.getPred().isOnlyEqui()) { // THETA
        // 1) create CrossOperator for join processing
        CrossOperator thetaJoin = CrossOperator.builder(ThetaLOJoinOperator.class).input1(childPlan1)
                .input2(childPlan2).name("LOJoinEval").build();

        // theta join configuration
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getLeft().getNRSMD()));
        thetaJoin.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getRight().getNRSMD()));
        thetaJoin.setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);

        final String encodedPredicate = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getPred()));
        thetaJoin.setParameter(PACTOperatorsConfiguration.PRED_BINARY.toString(), encodedPredicate);

        // 2) create ReduceOperator for post join processing
        ReduceOperator.Builder postJoinBuilder = ReduceOperator.builder(PostLOJoinOperator.class)
                .input(thetaJoin).name("PostLOJoin");
        //Document ID column
        KeyFactoryOperations.addKey(postJoinBuilder,
                MetadataTypesMapping.getKeyClass(loj.getLeft().getNRSMD().getType(loj.getDocumentIDColumn())),
                loj.getDocumentIDColumn());
        //Node ID columns
        for (int index : loj.getNodeIDColumns()) {
            KeyFactoryOperations.addKey(postJoinBuilder,
                    MetadataTypesMapping.getKeyClass(loj.getLeft().getNRSMD().getType(index)), index);
        }//  ww  w . ja  v  a2 s  . c  o m
        ReduceOperator postJoin = postJoinBuilder.build();

        // postJoin configuration
        // we create the definitive NRSMD
        final NestedMetadata nrsmdPostJoin = loj.getNRSMD();
        final String encodedNRSMDPostJoin = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(nrsmdPostJoin));
        postJoin.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMDPostJoin);
        postJoin.setParameter(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
                loj.getLeft().getNRSMD().getColNo());
        postJoin.setParameter(PACTOperatorsConfiguration.EVALUATION_COLUMN_INT.toString(),
                loj.getNRSMD().getColNo());

        conjLeftOuterJoin = new Operator[] { postJoin };
    } else if (loj.getPred() instanceof DisjunctivePredicate
            && ((DisjunctivePredicate) loj.getPred()).getConjunctivePreds().size() != 1) { // DISJ EQUI                  
        // 1) create CoGroup contracts for join processing
        // create CoGroup contracts for disjunctive equi join
        DisjunctivePredicate disjPred = (DisjunctivePredicate) loj.getPred();
        final int[][] leftColumns = loj.getPred().getLeftColumns();
        final int[][] rightColumns = loj.getPred().getRightColumns();

        //Parameters that will be used later for configuring each contract         
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getLeft().getNRSMD()));
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getRight().getNRSMD()));
        final String encodedPredicate = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(disjPred));

        //We create the join with the number of contracts needed for evaluation
        Operator[] disjJoin = new Operator[disjPred.getConjunctivePreds().size()];
        for (int i = 0; i < disjJoin.length; i++) {
            CoGroupOperator.Builder conjEquiJoinBuilder = CoGroupOperator.builder(DisjLOEquiJoinOperator.class,
                    MetadataTypesMapping.getKeyClass(loj.getLeft().getNRSMD().getType(leftColumns[i][0])),
                    leftColumns[i][0], rightColumns[i][0] - loj.getLeft().getNRSMD().getColNo());
            conjEquiJoinBuilder.input1(childPlan1).input2(childPlan2).name("LOJoinEval(" + i + ")");

            for (int k = 1; k < leftColumns[i].length; k++)
                KeyFactoryOperations.addKey(conjEquiJoinBuilder,
                        MetadataTypesMapping.getKeyClass(loj.getLeft().getNRSMD().getType(leftColumns[i][k])),
                        leftColumns[i][k], rightColumns[i][k] - loj.getLeft().getNRSMD().getColNo());

            disjJoin[i] = conjEquiJoinBuilder.build();
            // join configuration
            disjJoin[i].setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
            disjJoin[i].setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);
            disjJoin[i].setParameter(PACTOperatorsConfiguration.PRED_BINARY.toString(), encodedPredicate);
            disjJoin[i].setParameter(PACTOperatorsConfiguration.PRED_INT.toString(), i);
        }

        // 2) create ReduceOperator for post join processing
        ReduceOperator.Builder postJoinBuilder = ReduceOperator.builder(PostLOJoinOperator.class)
                .input(disjJoin).name("PostLOJoin");
        //Document ID column
        KeyFactoryOperations.addKey(postJoinBuilder,
                MetadataTypesMapping.getKeyClass(loj.getLeft().getNRSMD().getType(loj.getDocumentIDColumn())),
                loj.getDocumentIDColumn());
        //Node ID columns
        for (int index : loj.getNodeIDColumns()) {
            KeyFactoryOperations.addKey(postJoinBuilder,
                    MetadataTypesMapping.getKeyClass(loj.getLeft().getNRSMD().getType(index)), index);
        }
        ReduceOperator postJoin = postJoinBuilder.build();

        // postJoin configuration
        // we create the definitive NRSMD
        final NestedMetadata nrsmdPostJoin = loj.getNRSMD();
        final String encodedNRSMDPostJoin = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(nrsmdPostJoin));
        postJoin.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMDPostJoin);
        postJoin.setParameter(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
                loj.getLeft().getNRSMD().getColNo());
        postJoin.setParameter(PACTOperatorsConfiguration.EVALUATION_COLUMN_INT.toString(),
                loj.getNRSMD().getColNo());

        conjLeftOuterJoin = new Operator[] { postJoin };
    } else { // CONJ EQUI
        // create JoinOperator for conjunctive equi join
        final int[] leftColumns = loj.getPred().getLeftColumns()[0];
        final int[] rightColumns = loj.getPred().getRightColumns()[0];

        final NestedMetadata leftNRSMD = loj.getLeft().getNRSMD();

        CoGroupOperator.Builder conjLeftOuterEquiJoinBuilder = CoGroupOperator.builder(
                ConjLOEquiJoinOperator.class,
                MetadataTypesMapping.getKeyClass(leftNRSMD.getType(leftColumns[0])), leftColumns[0],
                rightColumns[0] - leftNRSMD.getColNo());
        conjLeftOuterEquiJoinBuilder.input1(childPlan1).input2(childPlan2).name("LOJoinConcat");

        for (int i = 1; i < leftColumns.length; i++)
            KeyFactoryOperations.addKey(conjLeftOuterEquiJoinBuilder,
                    MetadataTypesMapping.getKeyClass(leftNRSMD.getType(leftColumns[i])), leftColumns[i],
                    rightColumns[i] - leftNRSMD.getColNo());

        conjLeftOuterJoin = new Operator[] { conjLeftOuterEquiJoinBuilder.build() };
        // for equi join configuration
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getLeft().getNRSMD()));
        conjLeftOuterJoin[0].setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(loj.getRight().getNRSMD()));
        conjLeftOuterJoin[0].setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);
    }

    return conjLeftOuterJoin;
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Performs a simple get on the given URL
 *//*from   w ww. j a v a 2s .c o  m*/
public static void doGet(URL url) {
    try {
        if (mockMode)
            return;
        HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
        if (url.getUserInfo() != null) {
            String encoding = DatatypeConverter
                    .printBase64Binary(url.getUserInfo().getBytes(StandardCharsets.US_ASCII));
            urlc.setRequestProperty("Authorization", "Basic " + encoding);
        }
        urlc.connect();
        checkResponseCode(urlc);
    } catch (IOException e) {
        warn("An error occurred posting data to " + url + ". Please check that Solr is running.");
    }
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Reads data from the data stream and posts it to solr,
 * writes to the response to output// w  ww .  ja  va 2 s.c o m
 * @return true if success
 */
public boolean postData(InputStream data, Integer length, OutputStream output, String type, URL url) {
    if (mockMode)
        return true;
    boolean success = true;
    if (type == null)
        type = DEFAULT_CONTENT_TYPE;
    HttpURLConnection urlc = null;
    try {
        try {
            urlc = (HttpURLConnection) url.openConnection();
            try {
                urlc.setRequestMethod("POST");
            } catch (ProtocolException e) {
                fatal("Shouldn't happen: HttpURLConnection doesn't support POST??" + e);
            }
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            urlc.setRequestProperty("Content-type", type);
            if (url.getUserInfo() != null) {
                String encoding = DatatypeConverter
                        .printBase64Binary(url.getUserInfo().getBytes(StandardCharsets.US_ASCII));
                urlc.setRequestProperty("Authorization", "Basic " + encoding);
            }
            if (null != length)
                urlc.setFixedLengthStreamingMode(length);
            urlc.connect();
        } catch (IOException e) {
            fatal("Connection error (is Solr running at " + solrUrl + " ?): " + e);
            success = false;
        }

        try (final OutputStream out = urlc.getOutputStream()) {
            pipe(data, out);
        } catch (IOException e) {
            fatal("IOException while posting data: " + e);
            success = false;
        }

        try {
            success &= checkResponseCode(urlc);
            try (final InputStream in = urlc.getInputStream()) {
                pipe(in, output);
            }
        } catch (IOException e) {
            warn("IOException while reading response: " + e);
            success = false;
        }
    } finally {
        if (urlc != null)
            urlc.disconnect();
    }
    return success;
}

From source file:com.aurel.track.prop.LoginBL.java

private static StringBuilder assembleJSONPart2(StringBuilder sb, Locale locale, boolean firstTimeEver,
        TPersonBean personBean, HttpSession httpSession, String redirectURL, Integer mobileApplicationVersionNo,
        TMotdBean motd) {//www. j  av a  2s.  c  o m
    String licURL = "";
    if (ApplicationBean.getInstance().getLicenseManager() != null) {
        licURL = ApplicationBean.getInstance().getLicenseManager().getLicenseUrl(locale);
    }

    JSONUtility.appendStringValue(sb, "licURL", licURL, false);
    JSONUtility.appendBooleanValue(sb, "ftever", firstTimeEver, false);

    boolean isld = true;

    JSONUtility.appendBooleanValue(sb, "isLicenseDerfined", isld, false);

    JSONUtility.appendStringValue(sb, "jsonURL", redirectURL, false);
    if (httpSession.getAttribute(ISMOBILEAPP) != null) {
        if ((Boolean) httpSession.getAttribute(ISMOBILEAPP)) {
            // This property is added for mobile client,
            if (personBean != null && personBean.getLocale() != null) {
                JSONUtility.appendStringValue(sb, "locale", personBean.getLocale().toString());
                JSONUtility.appendStringValue(sb, "datePattern", getLocaleDatePattern(personBean.getLocale()));
                JSONUtility.appendIntegerValue(sb, "userLevel", personBean.getUserLevel());
                JSONUtility.appendIntegerValue(sb, "sessionTimeoutMinutes",
                        httpSession.getMaxInactiveInterval() / 60);
                JSONUtility.appendJSONValue(sb, "userSettingsProperties", getUserProperties(personBean));
                JSONUtility.appendIntegerValue(sb, "userObjectID", personBean.getObjectID());
                JSONUtility.appendStringValue(sb, "serverVersion", ApplicationBean.getInstance().getVersion());
                JSONUtility.appendIntegerValue(sb, "serverVersionNo",
                        ApplicationBean.getInstance().getVersionNo());
                JSONUtility.appendIntegerValue(sb, "clientCompatibility",
                        MobileBL.checkClientCompatibility(mobileApplicationVersionNo, true));
                JSONUtility.appendStringValue(sb, "sessionId", httpSession.getId());

                Integer iconKey = Integer.valueOf(-1);
                try {
                    byte[] oneAvatar = AvatarBL.getAvatarInByteArray(personBean.getObjectID(), iconKey);
                    MessageDigest md = MessageDigest.getInstance("MD5");
                    byte[] thedigest = md.digest(oneAvatar);
                    String checksum = DatatypeConverter.printBase64Binary(thedigest);
                    JSONUtility.appendStringValue(sb, "checkSum", checksum);
                } catch (Exception ex) {
                }
            }
        }
    }
    String motdMsg = motd.getTheMessage();
    if (motdMsg == null) {
        motdMsg = "&nbsp;";
    }
    try {
        JSONUtility.appendStringValue(sb, "teaserText",
                Html2Text.getNewInstance().convert(motd.getTeaserText()));
    } catch (Exception ex) {
    }
    JSONUtility.appendStringValue(sb, "motd", motdMsg, true);

    sb.append("}");
    sb.append("}");
    return sb;
}