List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:Importers.ImportReportCompiler.java
private Host getHost(Node n) { Host host = new Host(); NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String name = node.getNodeName(); String value = node.getTextContent(); if (name.equalsIgnoreCase("ip-address")) { host.setIp_address(value); } else if (name.equalsIgnoreCase("hostname")) { host.setHostname(value); } else if (name.equalsIgnoreCase("netbios-name")) { host.setNetbios_name(value); } else if (name.equalsIgnoreCase("operating-system")) { host.setOperating_system(value); } else if (name.equalsIgnoreCase("mac-address")) { host.setMac_address(value); } else if (name.equalsIgnoreCase("portnumber")) { host.setPortnumber(value); } else if (name.equalsIgnoreCase("protocol")) { host.setProtocol(value); } else if (name.equalsIgnoreCase("note")) { Note note = new Note(new String(new Base64().decode(value))); host.setNotes(note);//from ww w. ja v a 2s. c om } } } return host; }
From source file:com.twosigma.beaker.core.rest.PluginServiceLocatorRest.java
@Inject private PluginServiceLocatorRest(BeakerConfig bkConfig, WebServerConfig webServerConfig, OutputLogService outputLogService, GeneralUtils utils) throws IOException { this.nginxDir = bkConfig.getNginxDirectory(); this.nginxBinDir = bkConfig.getNginxBinDirectory(); this.nginxStaticDir = bkConfig.getNginxStaticDirectory(); this.nginxServDir = bkConfig.getNginxServDirectory(); this.nginxExtraRules = bkConfig.getNginxExtraRules(); this.userFolder = bkConfig.getUserFolder(); this.nginxPluginRules = bkConfig.getNginxPluginRules(); this.pluginDir = bkConfig.getPluginDirectory(); this.publicServer = bkConfig.getPublicServer(); this.portBase = bkConfig.getPortBase(); this.useHttpsCert = bkConfig.getUseHttpsCert(); this.useHttpsKey = bkConfig.getUseHttpsKey(); this.requirePassword = bkConfig.getRequirePassword(); this.listenInterface = bkConfig.getListenInterface(); this.servPort = this.portBase + 1; this.corePort = this.portBase + 2; this.restartPort = this.portBase + 3; this.reservedPortCount = bkConfig.getReservedPortCount(); this.authCookie = bkConfig.getAuthCookie(); this.pluginLocations = bkConfig.getPluginLocations(); this.pluginEnvps = bkConfig.getPluginEnvps(); this.urlHash = bkConfig.getHash(); this.pluginArgs = new HashMap<>(); this.outputLogService = outputLogService; this.encoder = new Base64(); this.config = bkConfig; this.nginxTemplate = utils.readFile(this.nginxDir + "/nginx.conf.template"); if (nginxTemplate == null) { throw new RuntimeException("Cannot get nginx template"); }//from ww w . j ava 2s . com this.ipythonTemplate = ("c = get_config()\n" + "c.NotebookApp.ip = u'127.0.0.1'\n" + "c.NotebookApp.port = %(port)s\n" + "c.NotebookApp.open_browser = False\n" + "c.NotebookApp.password = u'%(hash)s'\n"); this.nginxCommand = new String[7]; this.nginxCommand[0] = this.nginxBinDir + (this.nginxBinDir.isEmpty() ? "nginx" : "/nginx"); this.nginxCommand[1] = "-p"; this.nginxCommand[2] = this.nginxServDir; this.nginxCommand[3] = "-c"; this.nginxCommand[4] = this.nginxServDir + "/conf/nginx.conf"; this.nginxCommand[5] = "-g"; this.nginxCommand[6] = "error_log stderr;"; this.nginxRestartCommand = new String[9]; this.nginxRestartCommand[0] = this.nginxBinDir + (this.nginxBinDir.isEmpty() ? "nginx" : "/nginx"); this.nginxRestartCommand[1] = "-p"; this.nginxRestartCommand[2] = this.nginxServDir; this.nginxRestartCommand[3] = "-c"; this.nginxRestartCommand[4] = this.nginxServDir + "/conf/nginx.conf"; this.nginxRestartCommand[5] = "-g"; this.nginxRestartCommand[6] = "error_log stderr;"; this.nginxRestartCommand[7] = "-s"; this.nginxRestartCommand[8] = "reload"; this.corePassword = webServerConfig.getPassword(); this.showZombieLogging = bkConfig.getShowZombieLogging(); // record plugin options from cli and to pass through to individual plugins for (Map.Entry<String, List<String>> e : bkConfig.getPluginOptions().entrySet()) { for (String arg : e.getValue()) { addPluginArg(e.getKey(), arg); } } // Add shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { logger.info("shutting down beaker"); shutdown(); logger.info("done, exiting"); } }); portSearchStart = this.portBase + this.reservedPortCount; // on MacOS add library search path if (macosx()) { List<String> envList = new ArrayList<>(); for (Map.Entry<String, String> entry : System.getenv().entrySet()) { envList.add(entry.getKey() + "=" + entry.getValue()); } envList.add("DYLD_LIBRARY_PATH=./nginx/bin"); this.nginxEnv = new String[envList.size()]; envList.toArray(this.nginxEnv); } }
From source file:davmail.AbstractConnection.java
protected String base64Encode(String value) { return new String(new Base64().encode(value.getBytes())); }
From source file:com.tripit.auth.OAuthCredential.java
private String generateSignature(String baseUrl, SortedMap<String, String> args) throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { String encoding = "UTF-8"; baseUrl = URLEncoder.encode(baseUrl, encoding); StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (Map.Entry<String, String> arg : args.entrySet()) { if (isFirst) { isFirst = false;/*from w w w. java 2 s . c om*/ } else { sb.append('&'); } sb.append(URLEncoder.encode(arg.getKey(), encoding)); sb.append('='); sb.append(URLEncoder.encode(arg.getValue(), encoding)); } String parameters = URLEncoder.encode(sb.toString(), encoding); String signatureBaseString = "GET&" + baseUrl + "&" + parameters; String key = (consumerSecret != null ? consumerSecret : "") + "&" + (userSecret != null ? userSecret : ""); String macName = "HmacSHA1"; Mac mac = Mac.getInstance(macName); mac.init(new SecretKeySpec(key.getBytes(encoding), macName)); byte[] signature = mac.doFinal(signatureBaseString.getBytes(encoding)); return new Base64().encodeToString(signature).trim(); }
From source file:davmail.AbstractConnection.java
protected String base64Decode(String value) { return new String(new Base64().decode(value.getBytes())); }
From source file:freeipa.client.negotiation.JBossNegotiateScheme.java
@Override protected void parseChallenge(final CharArrayBuffer buffer, int beginIndex, int endIndex) throws MalformedChallengeException { String challenge = buffer.substringTrimmed(beginIndex, endIndex); System.out.println("Received challenge '" + challenge + "' from the auth server"); if (state == State.UNINITIATED) { token = new Base64().decode(challenge.getBytes()); state = State.CHALLENGE_RECEIVED; } else {// w ww . j av a 2 s . c o m System.out.println("Authentication already attempted"); state = State.FAILED; } }
From source file:co.cask.hydrator.transforms.CSVParser2.java
/** * Decodes the payload. /*from ww w .ja v a2 s . co m*/ * * @param body * @return */ private byte[] decodePayLoad(String body) throws DecoderException { if (config.decoder.equalsIgnoreCase("base64")) { Base64 codec = new Base64(); return codec.decode(body); } else if (config.decoder.equalsIgnoreCase("base32")) { Base32 codec = new Base32(); return codec.decode(body); } else if (config.decoder.equalsIgnoreCase("hex")) { Hex codec = new Hex(); return codec.decode(body.getBytes()); } return new byte[0]; }
From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java
private String handleStream(Document responseDocument, ResponseExtractor stream) { StringBuffer buffer = new StringBuffer(); @SuppressWarnings("unchecked") final List<Element> streams = (List<Element>) stream.getXPath().selectNodes(responseDocument); if (!streams.isEmpty()) { final Base64 base64 = new Base64(); Iterator<Element> itStreams = streams.iterator(); while (itStreams.hasNext()) { Element e = itStreams.next(); //TODO check performance with http://www.iharder.net/current/java/base64/ final byte[] decode = base64.decode(e.getText().getBytes()); buffer.append(new String(decode)); }/* w w w .j a v a2s . c o m*/ } log.debug("handleStream {} buffer {}", stream, buffer); return buffer.toString(); }
From source file:com.awesheet.models.Workbook.java
@Override public void onMessage(final UIMessage message) { switch (message.getType()) { case UIMessageType.CREATE_SHEET: { addSheet(new Sheet(this, "Sheet " + (newSheetID + 1))); break;/*ww w . j a va 2 s . c o m*/ } case UIMessageType.SELECT_SHEET: { SelectSheetMessage uiMessage = (SelectSheetMessage) message; selectSheet(uiMessage.getSheet()); break; } case UIMessageType.DELETE_SHEET: { DeleteSheetMessage uiMessage = (DeleteSheetMessage) message; removeSheet(uiMessage.getSheet()); break; } case UIMessageType.CREATE_BAR_CHART: { CreateBarChartMessage uiMessage = (CreateBarChartMessage) message; // Get selected cells. Cell selectedCells[] = getSelectedSheet().collectSelectedCells(); BarChart chart = new BarChart(selectedCells); chart.setNameX(uiMessage.getXaxis()); chart.setNameY(uiMessage.getYaxis()); chart.setTitle(uiMessage.getTitle()); if (!chart.generateImageData()) { UIMessageManager.getInstance().dispatchAction( new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not create a chart. Please make sure the cells you selected are in the correct format."))); break; } UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP, new ChartPopup(new Base64().encodeAsString(chart.getImageData())))); break; } case UIMessageType.CREATE_LINE_CHART: { CreateLineChartMessage uiMessage = (CreateLineChartMessage) message; // Get selected cells. Cell selectedCells[] = getSelectedSheet().collectSelectedCells(); LineChart chart = new LineChart(selectedCells); chart.setNameX(uiMessage.getXaxis()); chart.setNameY(uiMessage.getYaxis()); chart.setTitle(uiMessage.getTitle()); if (!chart.generateImageData()) { UIMessageManager.getInstance().dispatchAction( new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not create a chart. Please make sure the cells you selected are in the correct format."))); break; } UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP, new ChartPopup(new Base64().encodeAsString(chart.getImageData())))); break; } case UIMessageType.SAVE_CHART_IMAGE: { final SaveChartImageMessage uiMessage = (SaveChartImageMessage) message; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { byte imageData[] = new Base64().decode(uiMessage.getImageData()); FileDialog dialog = new FileDialog(MainFrame.getInstance(), "Save Chart Image", FileDialog.SAVE); dialog.setFile("*.png"); dialog.setVisible(true); dialog.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return (dir.isFile() && name.endsWith(".png")); } }); String filePath = dialog.getFile(); String directory = dialog.getDirectory(); dialog.dispose(); if (directory != null && filePath != null) { String absolutePath = new File(directory + filePath).getAbsolutePath(); if (!FileManager.getInstance().saveFile(absolutePath, imageData)) { UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not save chart image."))); } } } }); break; } } }
From source file:com.xqdev.sql.MLSQL.java
private static void addResultSet(Element root, ResultSet rs) throws SQLException { Namespace sql = root.getNamespace(); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); while (rs.next()) { Element tuple = new Element("tuple", sql); for (int i = 1; i <= columnCount; i++) { String colName = rsmd.getColumnName(i); // names aren't guaranteed OK in xml String colTypeName = rsmd.getColumnTypeName(i); // Decode a BLOB if one is found and place it into the result as a encoded Base 64 string String colValue = ""; if ("BLOB".equalsIgnoreCase(colTypeName)) { Blob b = rs.getBlob(i); if (b != null && b.length() > 0) { Base64 b64 = new Base64(); String b64Blob = b64.encodeBase64String(b.getBytes(1, (int) b.length())); colValue = b64Blob; } else colValue = ""; } else { colValue = rs.getString(i); }//from w ww . j a va 2 s .c o m boolean wasNull = rs.wasNull(); Element elt = new Element(colName); if (wasNull) { elt.setAttribute("null", "true"); } if ("UNKNOWN".equalsIgnoreCase(colTypeName)) { tuple.addContent(elt.setText("UNKNOWN TYPE")); // XXX ugly } else { tuple.addContent(elt.setText(colValue)); } } root.addContent(tuple); } }