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:fr.inria.oak.paxquery.translation.Logical2Pact.java

private static final Operator<Record>[] translate(LeftOuterNestedJoin lonj) {
    final boolean withAggregation = lonj instanceof LeftOuterNestedJoinWithAggregation;

    Operator<Record>[] childPlan1 = translate(lonj.getLeft());
    Operator<Record>[] childPlan2 = translate(lonj.getRight());

    Operator<Record>[] conjLeftOuterNestedJoin;

    if (!lonj.getPred().isOnlyEqui()) { // THETA
        // 1) create CrossOperator for join processing
        CrossOperator thetaJoin;/*from w w  w  .  j  av a  2  s  .c om*/
        if (withAggregation)
            thetaJoin = CrossOperator.builder(ThetaLNOJoinWithAggregationOperator.class).input1(childPlan1)
                    .input2(childPlan2).name("LNOJoinEvalAgg").build();
        else
            thetaJoin = CrossOperator.builder(ThetaLNOJoinOperator.class).input1(childPlan1).input2(childPlan2)
                    .name("LNOJoinEval").build();

        // theta join configuration
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.getLeft().getNRSMD()));
        thetaJoin.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMD1);
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.getRight().getNRSMD()));
        thetaJoin.setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(), encodedNRSMD2);
        final String encodedPredicate = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.getPred()));
        thetaJoin.setParameter(PACTOperatorsConfiguration.PRED_BINARY.toString(), encodedPredicate);
        if (withAggregation) {
            LeftOuterNestedJoinWithAggregation lonja = (LeftOuterNestedJoinWithAggregation) lonj;

            thetaJoin.setParameter(PACTOperatorsConfiguration.AGGREGATION_COLUMN_INT.toString(),
                    lonja.getAggregationColumn() - lonja.getLeft().getNRSMD().getColNo());

            final String encodedAggregationType = DatatypeConverter
                    .printBase64Binary(SerializationUtils.serialize(lonja.getAggregationType()));
            thetaJoin.setParameter(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(),
                    encodedAggregationType);

            thetaJoin.setParameter(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(),
                    lonja.isExcludeNestedField());
        }

        // 2) create ReduceOperator for post join processing
        ReduceOperator.Builder postJoinBuilder;
        if (withAggregation)
            postJoinBuilder = ReduceOperator.builder(PostLNOJoinWithAggregationOperator.class).input(thetaJoin)
                    .name("PostLNOJoinAgg");
        else
            postJoinBuilder = ReduceOperator.builder(PostLNOJoinOperator.class).input(thetaJoin)
                    .name("PostLNOJoin");
        //Document ID column
        KeyFactoryOperations.addKey(postJoinBuilder,
                MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(lonj.getDocumentIDColumn())),
                lonj.getDocumentIDColumn());
        //Node ID columns
        for (int index : lonj.getNodeIDColumns()) {
            KeyFactoryOperations.addKey(postJoinBuilder,
                    MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(index)), index);
        }
        ReduceOperator postJoin = postJoinBuilder.build();

        // postJoin configuration
        // we create the definitive NRSMD
        final NestedMetadata nrsmdPostJoin = lonj.getNRSMD();
        final String encodedNRSMDPostJoin = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(nrsmdPostJoin));
        postJoin.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMDPostJoin);
        if (withAggregation) {
            LeftOuterNestedJoinWithAggregation lonja = (LeftOuterNestedJoinWithAggregation) lonj;

            if (lonja.isExcludeNestedField())
                postJoin.setParameter(PACTOperatorsConfiguration.COMBINATION_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo());
            else {
                postJoin.setParameter(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo());
                postJoin.setParameter(PACTOperatorsConfiguration.EVALUATION_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo() + 1);
                postJoin.setParameter(PACTOperatorsConfiguration.COMBINATION_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo() + 2);
            }

            final String encodedAggregationType = DatatypeConverter
                    .printBase64Binary(SerializationUtils.serialize(lonja.getAggregationType()));
            postJoin.setParameter(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(),
                    encodedAggregationType);

            postJoin.setParameter(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(),
                    lonja.isExcludeNestedField());
        } else {
            postJoin.setParameter(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
                    lonj.getLeft().getNRSMD().getColNo());
            postJoin.setParameter(PACTOperatorsConfiguration.EVALUATION_COLUMN_INT.toString(),
                    lonj.getLeft().getNRSMD().getColNo() + 1);
        }

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

        //Parameters that will be used later for configuring each contract
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.getLeft().getNRSMD()));
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.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;
            if (withAggregation) {
                conjEquiJoinBuilder = CoGroupOperator.builder(DisjLNOEquiJoinWithAggregationOperator.class,
                        MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(leftColumns[i][0])),
                        leftColumns[i][0], rightColumns[i][0] - lonj.getLeft().getNRSMD().getColNo());
                conjEquiJoinBuilder.input1(childPlan1).input2(childPlan2).name("LNOJoinEvalAgg(" + i + ")");
            } else {
                conjEquiJoinBuilder = CoGroupOperator.builder(DisjLNOEquiJoinOperator.class,
                        MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(leftColumns[i][0])),
                        leftColumns[i][0], rightColumns[i][0] - lonj.getLeft().getNRSMD().getColNo());
                conjEquiJoinBuilder.input1(childPlan1).input2(childPlan2).name("LNOJoinEval(" + i + ")");
            }

            for (int k = 1; k < leftColumns[i].length; k++)
                KeyFactoryOperations.addKey(conjEquiJoinBuilder,
                        MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(leftColumns[i][k])),
                        leftColumns[i][k], rightColumns[i][k] - lonj.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);
            if (withAggregation) {
                LeftOuterNestedJoinWithAggregation lonja = (LeftOuterNestedJoinWithAggregation) lonj;

                disjJoin[i].setParameter(PACTOperatorsConfiguration.AGGREGATION_COLUMN_INT.toString(),
                        lonja.getAggregationColumn() - lonja.getLeft().getNRSMD().getColNo());

                final String encodedAggregationType = DatatypeConverter
                        .printBase64Binary(SerializationUtils.serialize(lonja.getAggregationType()));
                disjJoin[i].setParameter(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(),
                        encodedAggregationType);

                disjJoin[i].setParameter(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(),
                        lonja.isExcludeNestedField());
            }
        }

        // 2) create ReduceOperator for post join processing
        ReduceOperator.Builder postJoinBuilder;
        if (withAggregation)
            postJoinBuilder = ReduceOperator.builder(PostLNOJoinWithAggregationOperator.class).input(disjJoin)
                    .name("PostLNOJoinAgg");
        else
            postJoinBuilder = ReduceOperator.builder(PostLNOJoinOperator.class).input(disjJoin)
                    .name("PostLNOJoin");

        //Document ID column
        KeyFactoryOperations.addKey(postJoinBuilder,
                MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(lonj.getDocumentIDColumn())),
                lonj.getDocumentIDColumn());
        //Node ID column
        for (int index : lonj.getNodeIDColumns()) {
            KeyFactoryOperations.addKey(postJoinBuilder,
                    MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(index)), index);
        }
        ReduceOperator postJoin = postJoinBuilder.build();

        // postJoin configuration
        // we create the definitive NRSMD
        final NestedMetadata nrsmdPostJoin = lonj.getNRSMD();
        final String encodedNRSMDPostJoin = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(nrsmdPostJoin));
        postJoin.setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(), encodedNRSMDPostJoin);
        if (withAggregation) {
            LeftOuterNestedJoinWithAggregation lonja = (LeftOuterNestedJoinWithAggregation) lonj;

            if (lonja.isExcludeNestedField())
                postJoin.setParameter(PACTOperatorsConfiguration.COMBINATION_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo());
            else {
                postJoin.setParameter(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo());
                postJoin.setParameter(PACTOperatorsConfiguration.EVALUATION_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo() + 1);
                postJoin.setParameter(PACTOperatorsConfiguration.COMBINATION_COLUMN_INT.toString(),
                        lonj.getLeft().getNRSMD().getColNo() + 2);
            }

            final String encodedAggregationType = DatatypeConverter
                    .printBase64Binary(SerializationUtils.serialize(lonja.getAggregationType()));
            postJoin.setParameter(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(),
                    encodedAggregationType);

            postJoin.setParameter(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(),
                    lonja.isExcludeNestedField());
        } else {
            postJoin.setParameter(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
                    lonj.getLeft().getNRSMD().getColNo());
            postJoin.setParameter(PACTOperatorsConfiguration.EVALUATION_COLUMN_INT.toString(),
                    lonj.getLeft().getNRSMD().getColNo() + 1);
        }

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

        CoGroupOperator.Builder conjLeftOuterNestedEquiJoinBuilder;
        if (withAggregation)
            conjLeftOuterNestedEquiJoinBuilder = CoGroupOperator
                    .builder(ConjLNOEquiJoinWithAggregationOperator.class,
                            MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(leftColumns[0])),
                            leftColumns[0], rightColumns[0] - lonj.getLeft().getNRSMD().getColNo())
                    .input1(childPlan1).input2(childPlan2).name("LNOJoinConcatAgg");
        else
            conjLeftOuterNestedEquiJoinBuilder = CoGroupOperator
                    .builder(ConjLNOEquiJoinOperator.class,
                            MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(leftColumns[0])),
                            leftColumns[0], rightColumns[0] - lonj.getLeft().getNRSMD().getColNo())
                    .input1(childPlan1).input2(childPlan2).name("LNOJoinConcat");

        for (int i = 1; i < leftColumns.length; i++)
            KeyFactoryOperations.addKey(conjLeftOuterNestedEquiJoinBuilder,
                    MetadataTypesMapping.getKeyClass(lonj.getLeft().getNRSMD().getType(leftColumns[i])),
                    leftColumns[i], rightColumns[i] - lonj.getLeft().getNRSMD().getColNo());
        conjLeftOuterNestedJoin = new Operator[] { conjLeftOuterNestedEquiJoinBuilder.build() };

        // for equi join configuration
        final String encodedNRSMD1 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.getLeft().getNRSMD()));
        conjLeftOuterNestedJoin[0].setParameter(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(),
                encodedNRSMD1);
        final String encodedNRSMD2 = DatatypeConverter
                .printBase64Binary(SerializationUtils.serialize(lonj.getRight().getNRSMD()));
        conjLeftOuterNestedJoin[0].setParameter(PACTOperatorsConfiguration.NRSMD2_BINARY.toString(),
                encodedNRSMD2);
        if (withAggregation) {
            LeftOuterNestedJoinWithAggregation lonja = (LeftOuterNestedJoinWithAggregation) lonj;

            conjLeftOuterNestedJoin[0].setParameter(
                    PACTOperatorsConfiguration.AGGREGATION_COLUMN_INT.toString(),
                    lonja.getAggregationColumn() - lonja.getLeft().getNRSMD().getColNo());

            final String encodedAggregationType = DatatypeConverter
                    .printBase64Binary(SerializationUtils.serialize(lonja.getAggregationType()));
            conjLeftOuterNestedJoin[0].setParameter(
                    PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(), encodedAggregationType);

            conjLeftOuterNestedJoin[0].setParameter(
                    PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(),
                    lonja.isExcludeNestedField());
        }
    }

    return conjLeftOuterNestedJoin;
}

From source file:de.ailis.xadrian.data.Complex.java

/**
 * Returns the template code.//ww  w  . j  a  v  a 2  s  . co  m
 *
 * @return The template code.
 */
public String getTemplateCode() {
    try {
        final ByteArrayOutputStream arrayStream = new ByteArrayOutputStream();
        final OutputStream stream = new DynaByteOutputStream(arrayStream);

        // Write the template settings bit mask.
        int settings = this.sector == null ? 0 : 1;
        settings |= this.game.getNid() << 1;
        stream.write(settings);

        // Write the sector coordinates
        if (this.sector != null) {
            stream.write(this.sector.getX());
            stream.write(this.sector.getY());
        }

        // Or else write the sun power
        else {
            stream.write(this.suns.getPercent());
        }

        // Write the factories
        for (final ComplexFactory complexFactory : getAllFactories()) {
            if (complexFactory.isDisabled())
                continue;
            final Factory factory = complexFactory.getFactory();
            stream.write(factory.getNid());
            if (factory.isMine()) {
                for (final int yield : complexFactory.getYields())
                    stream.write(yield + 1);
                stream.write(0);
            } else
                stream.write(complexFactory.getQuantity());
        }

        // Write end marker
        stream.write(0);
        stream.close();

        // Get byte array from stream
        final byte[] data = arrayStream.toByteArray();

        // Return base 64 encoded bytes
        return DatatypeConverter.printBase64Binary(data);
    } catch (final IOException e) {
        throw new TemplateCodeException(e.toString(), e);
    }
}

From source file:com.ibm.cics.ca1y.Emit.java

/**
 * Return an XML representation of elements that are common to both the common base event and common base event REST
 * format.//from   w  w w  . j av  a  2 s .  c  o  m
 * 
 * @param props
 *            - the properties table to use
 * @return XML fragment
 */
private static StringBuilder getCommonBaseEventSection(EmitProperties props) {
    StringBuilder sb = new StringBuilder();

    sb.append("<cics:event xmlns:cics=\"http://www.ibm.com/xmlns/prod/cics/events/CBE\">");

    sb.append("<cics:context-info>");

    sb.append("<cics:eventname>").append(props.getProperty("EPCX_BUSINESSEVENT")).append("</cics:eventname>");
    sb.append("<cics:usertag>").append(props.getProperty("EPCX_EBUSERTAG")).append("</cics:usertag>");
    sb.append("<cics:networkapplid>").append(props.getProperty("EPCX_NETQUAL")).append(".")
            .append(props.getProperty("EPCX_APPLID")).append("</cics:networkapplid>");
    sb.append("<cics:timestamp>").append(rfc3339.format(new Date())).append("</cics:timestamp>");
    sb.append("<cics:bindingname>").append(props.getProperty("EPCX_EVENT__BINDING"))
            .append("</cics:bindingname>");
    sb.append("<cics:capturespecname>").append(props.getProperty("EPCX_CS__NAME"))
            .append("</cics:capturespecname>");
    sb.append("<cics:UOWid>").append(props.getProperty("EPCX_UOWID")).append("</cics:UOWid>");

    sb.append("</cics:context-info>");

    sb.append("<cics:payload-data>");

    sb.append("<data:payload xmlns:data=\"http://www.ibm.com/prod/cics/")
            .append(props.getProperty("EPCX_EBUSERTAG")).append("/")
            .append(props.getProperty("EPCX_BUSINESSEVENT")).append("\">");

    for (Map.Entry<String, Integer> entry : props.getBusinessInformationItems().entrySet()) {
        String key = entry.getKey();

        sb.append("<data:").append(key).append(">");

        if (props.getPropertyAttachment(key) == null) {
            sb.append(props.getProperty(key));

        } else {
            sb.append(DatatypeConverter.printBase64Binary(props.getPropertyAttachment(key)));
        }

        sb.append("</data:").append(key).append(">");
    }

    sb.append("</data:payload>");

    sb.append("</cics:payload-data>");

    sb.append("</cics:event>");

    return sb;
}

From source file:nl.fontys.fhict.jea.gwt.jee7.server.bus.FileUploadServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    System.out.println("working?");
    // process only multipart requests
    if (ServletFileUpload.isMultipartContent(req)) {

        // Create a factory for disk-based file items
        FileItemFactory factory = new DiskFileItemFactory();

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        // Parse the request
        try {/*from   ww w .j  av a 2  s.c om*/
            List<FileItem> items = upload.parseRequest(req);
            for (FileItem item : items) {
                // process only file upload - discard other form item types
                if (item.isFormField()) {
                    continue;
                }

                String fileName = item.getName();
                // get only the file name not whole path
                if (fileName != null) {
                    fileName = FilenameUtils.getName(fileName);
                }

                File uploadedFile = new File(UPLOAD_DIRECTORY, fileName);
                uploadedFile.delete();
                if (uploadedFile.createNewFile()) {
                    item.write(uploadedFile);
                } else {
                    throw new IOException("The file already exists in repository.");
                }

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                BufferedImage in = ImageIO.read(uploadedFile);
                try {
                    ImageIO.write(in, "png", baos);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String imageString = "data:image/png;base64,"
                        + DatatypeConverter.printBase64Binary(baos.toByteArray());
                serviceBean.setPicture(req.getRemoteUser(), imageString);

                resp.setStatus(HttpServletResponse.SC_CREATED);
                resp.setContentType("image/png");
                resp.getWriter().print(imageString);
                resp.flushBuffer();

            }
        } catch (Exception e) {
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "An error occurred while creating the file : " + e.getMessage());
        }

    } else {
        resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                "Request contents type is not supported by the servlet.");
    }
}

From source file:org.acmsl.queryj.customsql.AbstractCustomSqlProvider.java

/**
 * Computes the hash of given String.//from  w w w .  j a v  a 2 s .co  m
 * @param value the value.
 * @param charset the charset.
 * @return the hash.
 */
@NotNull
protected String getHash(@NotNull final String value, @NotNull final String charset) {
    @Nullable
    String result = null;

    try {
        @NotNull
        final MessageDigest t_MessageDigest = MessageDigest.getInstance("SHA1");

        result = URLEncoder.encode(
                DatatypeConverter.printBase64Binary(t_MessageDigest.digest(value.getBytes(charset))), charset);
    } catch (@NotNull final NoSuchAlgorithmException noSuchAlgorithm) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(SqlXmlParser.class);

        if (t_Log != null) {
            t_Log.fatal("Cannot use SHA1 for computing hashes", noSuchAlgorithm);
        }
    } catch (@NotNull final UnsupportedEncodingException unsupportedEncoding) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(SqlXmlParser.class);

        if (t_Log != null) {
            t_Log.fatal("Cannot use UTF-8 for encoding hashes", unsupportedEncoding);
        }
    }

    if (result == null) {
        result = "";
    }

    return result;
}

From source file:org.adeptnet.auth.saml.SAMLClient.java

/**
 * Create a new AuthnRequest suitable for sending to an HTTPRedirect binding
 * endpoint on the IdP. The SPConfig will be used to fill in the ACS and
 * issuer, and the IdP will be used to set the destination.
 *
 * @param requestId random generated RequestId
 * @return a deflated, base64-encoded AuthnRequest
 * @throws org.adeptnet.auth.saml.SAMLException
 *///from   w ww  . ja  v a  2s.  c  o  m
public String generateAuthnRequest(final String requestId) throws SAMLException {
    final String request = _createAuthnRequest(requestId);

    try {
        final byte[] compressed = deflate(request.getBytes("UTF-8"));
        return DatatypeConverter.printBase64Binary(compressed);
    } catch (UnsupportedEncodingException e) {
        throw new SAMLException("Apparently your platform lacks UTF-8.  That's too bad.", e);
    } catch (IOException e) {
        throw new SAMLException("Unable to compress the AuthnRequest", e);
    }
}

From source file:org.apache.kylin.jdbc.KylinClient.java

private void addHttpHeaders(HttpMethodBase method) {
    method.addRequestHeader("Accept", "application/json, text/plain, */*");
    method.addRequestHeader("Content-Type", "application/json");

    String username = connProps.getProperty("user");
    String password = connProps.getProperty("password");
    String basicAuth = DatatypeConverter.printBase64Binary((username + ":" + password).getBytes());
    method.addRequestHeader("Authorization", "Basic " + basicAuth);
}

From source file:org.apache.marmotta.client.util.HTTPUtil.java

public static HttpPost createPost(String path, ClientConfiguration config) throws URISyntaxException {
    final URIBuilder uriBuilder = new URIBuilder(config.getMarmottaUri());
    uriBuilder.setPath(uriBuilder.getPath() + path);

    if (StringUtils.isNotBlank(config.getMarmottaContext())) {
        uriBuilder.addParameter(CONTEXT, config.getMarmottaContext());
    }/* w  ww .  java2  s. c om*/

    final HttpPost post = new HttpPost(uriBuilder.build());

    if (StringUtils.isNotBlank(config.getMarmottaUser()) && StringUtils.isNotBlank(config.getMarmottaUser())) {
        final String credentials = String.format("%s:%s", config.getMarmottaUser(),
                config.getMarmottaPassword());
        try {
            final String encoded = DatatypeConverter.printBase64Binary(credentials.getBytes("UTF-8"));
            post.setHeader("Authorization", String.format("Basic %s", encoded));
        } catch (UnsupportedEncodingException e) {
            System.err.println("Error encoding credentials: " + e.getMessage());
        }
    }

    return post;
}

From source file:org.apache.nifi.processors.standard.TestPutSQL.java

private String fixedSizeByteArrayAsBase64String(int length) {
    byte[] bBinary = RandomUtils.nextBytes(length);
    return DatatypeConverter.printBase64Binary(bBinary);
}

From source file:org.apache.storm.common.AbstractAutoCreds.java

@Override
public void populateCredentials(Map<String, String> credentials, Map conf) {
    try {/* w ww.j  a va2 s.  c o m*/
        if (!configKeys.isEmpty()) {
            Map<String, Object> updatedConf = updateConfigs(conf);
            for (String configKey : configKeys) {
                credentials.put(getCredentialKey(configKey),
                        DatatypeConverter.printBase64Binary(getHadoopCredentials(updatedConf, configKey)));
            }
        } else {
            credentials.put(getCredentialKey(StringUtils.EMPTY),
                    DatatypeConverter.printBase64Binary(getHadoopCredentials(conf)));
        }
        LOG.info("Tokens added to credentials map.");
    } catch (Exception e) {
        LOG.error("Could not populate credentials.", e);
    }
}