List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomDeleteSwingWorker.java
@Override protected Integer doInBackground() throws Exception { int selectedRow = restClient.getTblMushroom().getSelectedRow(); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { @Override//from w w w. j av a2 s . c om protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }); restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow), HttpMethod.DELETE, request, MushroomDto.class); RestClient.getMushroomIDs().remove(selectedRow); return selectedRow; }
From source file:com.smartmarmot.dbforbix.zabbix.protocol.Sender18.java
private String base64Encode(String data) { return new String(Base64.encodeBase64(encodeString(data))); }
From source file:VideoTestServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w .j a v a 2 s .c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); final Part filePart = request.getPart("file"); String filename = getFileName(filePart); InputStream filecontent = filePart.getInputStream(); byte[] bytes = new byte[filecontent.available()]; filecontent.read(bytes); /*OutputStream PDFprint = response.getOutputStream(); PDFprint.write(bytes); if(PDFprint != null){ PDFprint.close(); }*/ byte[] encoded = Base64.encodeBase64(bytes); String encodedString = new String(encoded); System.out.println(encodedString); String title = "Video Servlet"; String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n"; out.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<video width=\"320\" hieght=\"240\" controls>" + "<source type=\"video/webm\" src=\"data:video/webm;base64," + encodedString + "\">" + "Your browser does not support the video element" + "</video>" + "</body></html>"); }
From source file:com.oneops.client.api.APIClient.java
protected RequestSpecification createRequest() { RequestSpecification rs = RestAssured.given(); if (!instance.isGzipEnabled()) { rs.config(RestAssured.config().decoderConfig(DecoderConfig.decoderConfig().noContentDecoders())); }/*www . ja v a 2 s.c om*/ String basicAuth = "Basic " + new String(Base64.encodeBase64(instance.getAuthtoken().getBytes())); rs.header("Authorization", basicAuth); rs.header("User-Agent", "OneOpsAPIClient"); rs.header("Accept", "application/json"); rs.header("Content-Type", "application/json"); String baseUri = instance.getEndpoint(); if (instance.getOrgname() != null) { baseUri += instance.getOrgname(); } rs.baseUri(baseUri); return rs; }
From source file:com.haulmont.cuba.core.sys.PasswordEncryptionImpl.java
@Override public String generateRandomPassword() { SecureRandom random;//from w ww . j a v a2 s. co m try { random = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Unable to load SHA1PRNG", e); } byte[] passwordBytes = new byte[6]; random.nextBytes(passwordBytes); return new String(Base64.encodeBase64(passwordBytes), StandardCharsets.UTF_8).replace("=", ""); }
From source file:com.creditcloud.common.security.impl.DESTextCipher.java
@Override public String encrypt(String value) throws GeneralSecurityException { return new String(Base64.encodeBase64(encryptCipher.doFinal(value.getBytes()))); }
From source file:com.createsend.models.transactional.request.Attachment.java
/** * Base64 encodes the input stream and stores the result as the Content. * @param inputStream//w ww . j a v a 2 s . c o m * @throws IOException */ public void base64EncodeContentStream(InputStream inputStream) throws IOException { byte[] bytes = IOUtils.toByteArray(inputStream); byte[] bytesBase64 = Base64.encodeBase64(bytes); Content = new String(bytesBase64); }
From source file:com.dv.sharer.mobile.rest.impl.ImageAndroidRestClient.java
public Response uploadFile(Integer intgr, byte[] data) throws Exception { data = Base64.encodeBase64(data); String dataStr = new String(data); String url = getUrlAndPath() + "upload/"; String response;/*from w ww.j a v a 2 s. c o m*/ try { HttpPost post = getUploadPOST(url, dataStr); HttpResponse httpResponse = getHttpclient().execute(post); response = getResponse(httpResponse); } catch (Exception e) { Log.e(TAG, "Error handling update", e); throw e; } return Response.fromJson(response, Response.class); }
From source file:com.greenpepper.server.license.LicenceGenerator.java
private static void buildEvaluation(Date experyDate) throws Exception { File file = File.createTempFile("evaluation", ".lic"); License license = License.evaluation("Some peeps evaluating", _2006, experyDate); LicenseManager lm = new LicenseManager(getLicenseParam()); lm.store(license, file);/* w ww .j av a 2 s .co m*/ if (deleteFiles) file.deleteOnExit(); System.out.println("# Evaluation Expery: " + new FormatedDate(experyDate).getFormatedDate()); System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file)))); System.out.println(""); }
From source file:datafu.pig.hash.MD5.java
public String call(String val) { if (isBase64) { return new String(Base64.encodeBase64(md5er.digest(val.getBytes()))); } else {//from w w w. java 2 s. c om return String.format("%032x", new BigInteger(1, md5er.digest(val.getBytes()))); } }