List of usage examples for javax.xml.bind DatatypeConverter printBase64Binary
public static String printBase64Binary(byte[] val)
Converts an array of bytes into a string.
From source file:org.vpac.web.controller.DataController.java
@RequestMapping(value = "/MultiPreviewQuery", method = RequestMethod.POST) public void multiPreviewQuery(@RequestParam(required = false) String query, @RequestParam(required = false) String threads, @RequestParam(required = false) Double minX, @RequestParam(required = false) Double minY, @RequestParam(required = false) Double maxX, @RequestParam(required = false) Double maxY, @RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate, @RequestParam(required = false) String netcdfVersion, ModelMap model, HttpServletResponse response) throws Exception { // FIXME: this should only be done once! ProviderRegistry.getInstance().clearProivders(); ProviderRegistry.getInstance().addProivder(rsaDatasetProvider); ProviderRegistry.getInstance().addProivder(previewDatasetProvider); final QueryDefinition qd = QueryDefinition.fromString(query); if (minX != null) qd.output.grid.bounds = String.format("%f %f %f %f", minX, minY, maxX, maxY); if (startDate != null) { qd.output.grid.timeMin = startDate; qd.output.grid.timeMax = endDate; }//from w w w. j a v a 2s . c o m Version version; if (netcdfVersion != null) { if (netcdfVersion.equals("nc3")) { version = Version.netcdf3; } else if (netcdfVersion.equals("nc4")) { version = Version.netcdf4; } else { throw new IllegalArgumentException(String.format("Unrecognised NetCDF version %s", netcdfVersion)); } } else { version = Version.netcdf4; } final Version ver = version; final QueryProgress qp = new QueryProgress(jobProgressDao); String taskId = qp.getTaskId(); final Integer t = threads == null ? null : Integer.parseInt(threads); Path outputDir = FileUtils.getTargetLocation(taskId); final Path queryPath = outputDir.resolve("query_output.nc"); if (!Files.exists(outputDir)) Files.createDirectories(outputDir); try { executeQuery(qd, qp, t, queryPath, ver); if (!Files.exists(queryPath)) { throw new ResourceNotFoundException("Query output file not found: " + queryPath); } Path ncPreviewPath = queryPath.getParent().resolve("multipreview.nc"); // generate multiple 2D preview out of query output boolean hasNoData = FilterUtils.multiPreview(queryPath, ncPreviewPath); Path pngPreviewPath = queryPath.getParent().resolve("multipreview.png"); Path tifPreviewPath = queryPath.getParent().resolve("multipreview.tif"); CommandUtil commandUtil = new CommandUtil(); // Warp to tiff first - this sets an alpha flag. List<String> command = new ArrayList<String>(); command.add("gdalwarp"); command.add("-of"); command.add("GTiff"); if (hasNoData) { command.add("-srcnodata"); command.add("-999"); command.add("-dstnodata"); command.add("-999"); command.add("-dstalpha"); } command.add(ncPreviewPath.toString()); command.add(tifPreviewPath.toString()); commandUtil.start(command); // Now translate to png. command = new ArrayList<String>(); command.add("gdal_translate"); command.add("-of"); command.add("PNG"); command.add("-scale"); command.add("-ot"); command.add("Byte"); command.add(tifPreviewPath.toString()); command.add(pngPreviewPath.toString()); commandUtil.start(command); try { // get your file as InputStream InputStream is = new FileInputStream(pngPreviewPath.toString()); String result = DatatypeConverter.printBase64Binary(IOUtils.toByteArray(is)); response.setContentType("application/json"); response.setContentLength(result.getBytes().length); response.getOutputStream().write(result.getBytes()); response.flushBuffer(); } catch (IOException ex) { throw new RuntimeException("IOError writing file to output stream"); } } catch (Exception e) { qp.setErrorMessage(e.getMessage()); log.error("Task exited abnormally: ", e); throw e; } }
From source file:org.wso2.bps.integration.common.clients.bpmn.WorkflowServiceClient.java
public String getProcessDiagram(String processId) throws Exception { String dataUri = null;//from w w w .j a v a2 s . c o m ByteArrayOutputStream baos = null; try { String imageString = deploymentServiceStub.getProcessDiagram(processId); BufferedImage bufferedImage = decodeToImage(imageString); baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", baos); } catch (Exception e) { throw new IOException("Failed to get the process diagram", e); } finally { try { if (baos != null) { baos.flush(); dataUri = "data:image/png;base64," + DatatypeConverter.printBase64Binary(baos.toByteArray()); baos.close(); } } catch (IOException e) { log.error("Exception occurred when closing the stream", e); } } return dataUri; }
From source file:org.wso2.carbon.bpmn.ui.WorkflowServiceClient.java
public String getProcessDiagram(String processId) { ByteArrayOutputStream baos = null; String dataUri = null;/*from w ww . j a v a 2 s . co m*/ try { String imageString = deploymentServiceStub.getProcessDiagram(processId); BufferedImage bufferedImage = decodeToImage(imageString); baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", baos); baos.flush(); dataUri = "data:image/png;base64," + DatatypeConverter.printBase64Binary(baos.toByteArray()); } catch (IOException e) { log.error("IO error while writing image " + e); } catch (Exception e) { //TODO Fix skeleton and rename above exception to correct type log.error(" Error while obtaining the process diagram " + e); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { log.error("Error occurred while closing io stream " + e); } } } return dataUri; }
From source file:org.wso2.carbon.bpmn.ui.WorkflowServiceClient.java
public String getProcessInstanceDiagram(String instanceId) throws Exception { ByteArrayOutputStream baos = null; String dataUri;//from ww w.j a v a2 s.co m try { String imageString = instanceServiceStub.getProcessInstanceDiagram(instanceId); BufferedImage bufferedImage = decodeToImage(imageString); baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", baos); baos.flush(); dataUri = "data:image/png;base64," + DatatypeConverter.printBase64Binary(baos.toByteArray()); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { log.error("IO error occurred while closing the stream " + e); } } } return dataUri; }
From source file:org.wso2.carbon.bps.analytics.core.utils.Helper.java
/** * Get authorization header/*from w ww .jav a 2s . c o m*/ * * @return encoded auth header * @throws IOException * @throws XMLStreamException */ public static String getAuthorizationHeader() throws IOException, XMLStreamException { String requestHeader = "Basic "; String userName = null; String password = null; Iterator properties = getPropertyIterator(); while (properties.hasNext()) { if (userName != null && password != null) { break; } OMElement property = (OMElement) properties.next(); if (AnalyticConstants.CONFIG_USER_NAME .equals(property.getAttributeValue(new QName(null, AnalyticConstants.NAME)))) { String name = property.getAttributeValue(new QName(null, AnalyticConstants.VALUE)); if (name != null && !name.isEmpty()) { userName = name; } } if (AnalyticConstants.CONFIG_PASSWORD .equals(property.getAttributeValue(new QName(null, AnalyticConstants.NAME)))) { String pwd = property.getAttributeValue(new QName(null, AnalyticConstants.VALUE)); if (pwd != null && !pwd.isEmpty()) { password = pwd; } } } if (userName != null && password != null) { String headerPortion = userName + ":" + password; byte[] encodedBytes = headerPortion.getBytes("UTF-8"); String encodedString = DatatypeConverter.printBase64Binary(encodedBytes); requestHeader += encodedString; return requestHeader; } return null; }
From source file:org.wso2.carbon.das.messageflow.data.publisher.publish.StatisticsPublisher.java
/** * Compress the payload/*from ww w . j ava 2 s . c o m*/ * * @param str * @return */ private static String compress(byte[] str) { if (str == null || str.length == 0) { return null; } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(str); gzip.close(); return DatatypeConverter.printBase64Binary(out.toByteArray()); } catch (IOException e) { log.error("Unable to compress data", e); } return null; }
From source file:org.wso2.carbon.la.alert.impl.ScheduleAlertTask.java
/** * This method build a URL string according to the current search. * * @return String URL//from w ww. j a v a 2s. c om */ private String getBuildURL() { String base64EncodeQuery = DatatypeConverter .printBase64Binary(taskProperties.get(LAAlertConstants.QUERY).getBytes()); String base64EncodeTimeFrom = DatatypeConverter .printBase64Binary(taskProperties.get(LAAlertConstants.TIME_FROM).getBytes()); String base64EncodeTimeTo = DatatypeConverter .printBase64Binary(taskProperties.get(LAAlertConstants.TIME_TO).getBytes()); return "https://10.100.4.179:9443/loganalyzer/site/search/search.jag?" + "query=" + base64EncodeQuery + "&" + "timeFrom=" + base64EncodeTimeFrom + "&" + "timeTo=" + base64EncodeTimeTo; }
From source file:org.wso2.carbon.pc.analytics.core.generic.utils.AnalyticsUtils.java
/** * Get authorization header//from w ww . j a va2s .c o m * * @return encoded auth header */ public static String getAuthorizationHeader() { String userName = getInstance().getProcessCenter().getProcessCenterConfiguration() .getAnalyticsServerUsername(); String password = getInstance().getProcessCenter().getProcessCenterConfiguration() .getAnalyticsServerPassword(); if (userName != null && password != null) { return AnalyticsConstants.AUTH_BASIC_HEADER + " " + DatatypeConverter .printBase64Binary((userName + ":" + password).getBytes(StandardCharsets.UTF_8)); } return null; }
From source file:org.wso2.carbon.pc.analytics.core.kpi.utils.DASConfigurationUtils.java
/** * Get authorization header for access bps admin service * * @return AuthorizationHeader/*from w w w . j ava 2 s. c om*/ */ public static String getAuthorizationHeader() { String userName = getInstance().getProcessCenter().getProcessCenterConfiguration() .getRuntimeEnvironmentUsername(); String password = getInstance().getProcessCenter().getProcessCenterConfiguration() .getRuntimeEnvironmentPassword(); if (userName != null && password != null) { return AnalyticsConfigConstants.REQUEST_HEADER_BASIC + " " + DatatypeConverter .printBase64Binary((userName + ":" + password).getBytes(StandardCharsets.UTF_8)); } return null; }
From source file:org.wso2.carbon.pc.analytics.core.utils.AnalyticsUtils.java
/** * Get authorization header//from w w w. j a v a2s . c o m * * @return encoded auth header * @throws IOException * @throws XMLStreamException */ public static String getAuthorizationHeader() throws IOException, XMLStreamException { String requestHeader = "Basic "; OMElement configElement = getConfigElement(); SecretResolver secretResolver = SecretResolverFactory.create(configElement, false); OMElement analyticsElement = configElement.getFirstChildWithName(new QName(AnalyticsConstants.ANALYTICS)); String userName = null; String password = null; if (analyticsElement != null) { userName = analyticsElement.getFirstChildWithName(new QName(AnalyticsConstants.CONFIG_USER_NAME)) .getText(); if (secretResolver != null && secretResolver.isInitialized()) { if (secretResolver.isTokenProtected(AnalyticsConstants.SECRET_ALIAS)) { password = secretResolver.resolve(AnalyticsConstants.SECRET_ALIAS); } else { password = analyticsElement.getFirstChildWithName(new QName(AnalyticsConstants.CONFIG_PASSWORD)) .getText(); } } else { password = analyticsElement.getFirstChildWithName(new QName(AnalyticsConstants.CONFIG_PASSWORD)) .getText(); } } if (userName != null && password != null) { String headerPortion = userName + ":" + password; byte[] encodedBytes = headerPortion.getBytes("UTF-8"); String encodedString = DatatypeConverter.printBase64Binary(encodedBytes); requestHeader += encodedString; return requestHeader; } return null; }