List of usage examples for org.apache.commons.codec.binary Base64 isBase64
public static boolean isBase64(final byte[] arrayOctet)
From source file:com.google.appengine.tck.datastore.KeyTest.java
@Test public void testKeyString() throws InterruptedException { String kind = "familyKeyString"; clearData(kind);//from www . jav a 2s. c om Entity parent = new Entity(kind); parent.setProperty("role", "father"); Key pKey = service.put(parent); String keyString = KeyFactory.createKeyString(pKey, kind, 1); assertTrue(Base64.isBase64(keyString.getBytes())); Entity entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+id"); service.put(entity); assertEquals(1, entity.getKey().getId()); assertEquals(kind, entity.getKey().getKind()); keyString = KeyFactory.createKeyString(pKey, kind, "2"); assertTrue(Base64.isBase64(keyString.getBytes())); entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+name"); service.put(entity); assertEquals("2", entity.getKey().getName()); assertEquals(pKey, entity.getParent()); keyString = KeyFactory.createKeyString(kind, 3); assertTrue(Base64.isBase64(keyString.getBytes())); entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+id"); service.put(entity); assertEquals(3, entity.getKey().getId()); keyString = KeyFactory.createKeyString(kind, "4"); assertTrue(Base64.isBase64(keyString.getBytes())); entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+name"); service.put(entity); assertEquals("4", entity.getKey().getName()); }
From source file:com.google.cloud.backend.config.BackendConfigManager.java
/** * Extracts data without prefix since data from the front end is based64-encoded and prefixed with * "data:application/x-pkcs12;base64,"./*from w w w .j ava 2 s .c o m*/ * * @param base64String from client * @return extracted data without prefix */ private Text removeClientHeaderFromData(String base64String) { if (StringUtility.isNullOrEmpty(base64String)) { return null; } int index = base64String.indexOf(PKCS12_BASE64_PREFIX); if (index < 0) { return null; } String data = base64String.substring(index + PKCS12_BASE64_PREFIX.length()); if (Base64.isBase64(data)) { return new Text(data); } else { return null; } }
From source file:Java_BWS_Sample.SampleBwsClient.java
/******************************************************************************************************************* * * Get the encoded username required to authenticate user to BWS. * * @param username// w ww . ja v a 2 s .c o m * A string containing the username to encode. * @param authenticator * The authenticator. * @return Returns a string containing the encoded username if successful, and a null message string otherwise. * ******************************************************************************************************************* */ public static String getEncodedUserName(String username, Authenticator authenticator) { final String METHOD_NAME = "getEncodedUserName()"; final String BWS_API_NAME = "_bwsUtil.getEncodedUsername()"; logMessage("Entering %s", METHOD_NAME); String returnValue = null; GetEncodedUsernameRequest request = new GetEncodedUsernameRequest(); request.setMetadata(REQUEST_METADATA); request.setUsername(username); request.setOrgUid(REQUEST_METADATA.getOrganizationUid()); request.setAuthenticator(authenticator); CredentialType credentialType = new CredentialType(); credentialType.setPASSWORD(true); credentialType.setValue("PASSWORD"); request.setCredentialType(credentialType); GetEncodedUsernameResponse response = null; try { logRequest(BWS_API_NAME); response = _bwsUtil.getEncodedUsername(request); logResponse(BWS_API_NAME, response.getReturnStatus().getCode(), response.getMetadata()); } catch (WebServiceException e) { // Log and re-throw exception. logMessage("Exiting %s with exception \"%s\"", METHOD_NAME, e.getMessage()); throw e; } if (response.getReturnStatus().getCode().equals("SUCCESS")) { returnValue = response.getEncodedUsername(); } else { logMessage("Error Message: \"%s\"", response.getReturnStatus().getMessage()); } if (Base64.isBase64(returnValue)) { logMessage("Decoded value of encoded username \"%s\"", StringUtils.newStringUtf8(Base64.decodeBase64(returnValue))); } else { logMessage("Value of encoded username \"%s\"", returnValue); } logMessage("Exiting %s", METHOD_NAME); return returnValue; }
From source file:com.google.appengine.tck.logservice.RequestLogsTest.java
/** * These could return different values from the implementations so just assert the basics. *//* w ww .j av a 2s . co m*/ @Test @InSequence(20) public void testMiscProperties() throws Exception { RequestLogs logs = getRequestLogs1(); assertNotNull("App Engine Release, e.g. 1.8.0, or empty string.", logs.getAppEngineRelease()); assertTrue("Estimated cost of this request, in dollars.", logs.getCost() >= 0.0); assertTrue("Time required to process this request in microseconds.", logs.getLatencyUsec() >= 0); assertTrue("Microseconds request spent in pending request queue, if was pending at all.", logs.getPendingTimeUsec() >= 0); assertFalse("This should never be a loading request: " + logs.toString(), logs.isLoadingRequest()); String appId = SystemProperty.applicationId.get(); // appIds have a prefix according to datacenter. assertTrue("The application ID that handled this request.", logs.getAppId().endsWith(appId)); long cycles = logs.getMcycles(); assertTrue("Number of machine cycles used to process this request: " + cycles, cycles >= 0); String getOffsetMsg = "Base64-encoded offset used with subsequent LogQuery to continue reading logs at the point in time immediately following this request."; assertNotNull(getOffsetMsg, logs.getOffset()); assertTrue("Should be Base64: " + logs.getOffset(), Base64.isBase64(logs.getOffset().getBytes())); String mapEntryMsg = "File or class within the URL mapping used for this request: " + logs.getUrlMapEntry(); assertNotNull(mapEntryMsg, logs.getUrlMapEntry()); }
From source file:net.sf.smbt.touchosc.utils.TouchOSCUtils.java
/** * UI initialization/*www .ja va 2 s .c o m*/ * * @param touchOscApp UI model * @param tPage window definition from the .touchosc#index.xml file */ void initTouchOscControls(TouchOscApp touchOscApp, Tabpage tPage, boolean vertical, boolean iphone) { Tab tab = initTouchOscTabPageControls(tPage); if (tab instanceof Tab) { touchOscApp.getTabs().add(tab); for (Control c : tPage.getControl()) { if (c.getName() != null && Base64.isBase64(c.getName())) { String n = new String(Base64.decodeBase64(c.getName()), Charset.forName("UTF-8")); c.setName(n); } if (c.getText() != null && Base64.isBase64(c.getText())) { String t = new String(Base64.decodeBase64(c.getText()), Charset.forName("UTF-8")); c.setText(t); } if (c.getOscCs() != null && Base64.isBase64(c.getOscCs())) { String o = new String(Base64.decodeBase64(c.getOscCs()), Charset.forName("UTF-8")); c.setOscCs(o); } tab.getWidgets().add(initTouchOscTabPageControl(tab, c, vertical, iphone)); } } }
From source file:net.sf.smbt.touchosc.utils.TouchOSCUtils.java
private String getDefaultOSCTag(Tab t, Widget w) { String tn = ""; String wn = ""; if (t.getName() != null && Base64.isBase64(t.getName())) { tn = new String(Base64.decodeBase64(t.getName()), Charset.forName("UTF-8")); }/*from w ww . j a va2s. com*/ if (w.getName() != null && Base64.isBase64(w.getName())) { wn = new String(Base64.decodeBase64(w.getName()), Charset.forName("UTF-8")); } return "/" + tn + "/" + w.getName(); }
From source file:net.java.jaspicoil.MSPacSpnegoServerAuthModule.java
/** * Log some debug data about a token// www .jav a 2 s .c o m * * @param message * the message to display * @param token * the token to log */ private void debugToken(String message, byte[] token) { if (this.debug || LOG.isLoggable(Level.FINE)) { final StringBuffer sb = new StringBuffer(); sb.append("\n"); sb.append("Token "); sb.append(Base64.isBase64(token) ? "is" : "is Not"); sb.append(" Base64 encoded\n"); sb.append("bytes: "); boolean first = true; for (final byte b : token) { final int i = b; if (first) { sb.append(i); first = false; } else { sb.append(", ").append(i); } } LOG.log(this.debugLevel, message, sb); } }
From source file:com.cloud.vm.UserVmManagerImpl.java
private void validateUserData(String userData) { byte[] decodedUserData = null; if (userData != null) { if (!Base64.isBase64(userData)) { throw new InvalidParameterValueException("User data is not base64 encoded"); }/*from w w w .j av a2 s .c o m*/ if (userData.length() >= 2 * MAX_USER_DATA_LENGTH_BYTES) { throw new InvalidParameterValueException("User data is too long"); } decodedUserData = Base64.decodeBase64(userData.getBytes()); if (decodedUserData.length > MAX_USER_DATA_LENGTH_BYTES) { throw new InvalidParameterValueException("User data is too long"); } if (decodedUserData.length < 1) { throw new InvalidParameterValueException("User data is too short"); } } }
From source file:org.apache.nifi.processors.standard.util.ValidatingBase64InputStream.java
@Override public int read(byte[] b, int offset, int len) throws IOException { int numRead = super.read(b, offset, len); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase64 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); }/*from w ww .j av a 2 s .co m*/ if (!Base64.isBase64(copy)) { throw new IOException("Data is not base64 encoded."); } } return numRead; }
From source file:org.apache.nifi.processors.standard.util.ValidatingBase64InputStream.java
@Override public int read(byte[] b) throws IOException { int numRead = super.read(b); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase64 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); }/*w w w. ja va 2s . c o m*/ if (!Base64.isBase64(copy)) { throw new IOException("Data is not base64 encoded."); } } return numRead; }