本文整理汇总了Java中org.apache.xerces.impl.dv.util.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于org.apache.xerces.impl.dv.util包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeBase64ToFile
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* Decoded a Base64-encoded string and writes the content to a file.
*
* @param filePath the path of the file to write to.
*
* @param base64String the input Base64 string.
* @throws IOException if there is an error writing to the file.
*/
public static void decodeBase64ToFile(String filePath,
String base64String) throws IOException {
File file = new File(filePath);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
FileOutputStream fos = new FileOutputStream(filePath);
try {
byte[] decodedBytes = Base64.decode(base64String);
fos.write(decodedBytes);
fos.flush();
}
finally {
try {
fos.close();
}
catch (Exception e) {
// Ignore.
}
}
}
示例2: post
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
public static String post(URLConnection connection,
String stringWriter,
Credentials credentials) throws Exception {
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Authorization",
"Basic "
+ Base64.encode((credentials.getUserName() + ":" + new String(
credentials.getPassword())).getBytes()));
OutputStreamWriter postData = new OutputStreamWriter(connection.getOutputStream());
postData.write(stringWriter);
postData.flush();
postData.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = "";
String line = "";
while ((line = in.readLine()) != null)
response = response + line;
in.close();
return response;
}
示例3: JiraSiteHandler
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* Constructor of the Jira Site Handler object.
*
* @param tc is the caller test case
* @param environment provide the Environment object of Gepard, it must contain connectivity info to JIRA.
*/
public JiraSiteHandler(final GepardTestClass tc, final Environment environment) {
this.environment = environment;
webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
String phrase = Base64.encode((environment.getProperty(Environment.JIRA_SITE_USERNAME) + ":" + environment.getProperty(Environment.JIRA_SITE_PASSWORD)).getBytes());
webClient.addRequestHeader("Authorization", "Basic " + phrase);
try {
JSONObject serverInfo = getJiraServerInfo();
String serverTitle = serverInfo.get("serverTitle").toString();
String version = serverInfo.get("version").toString();
tc.logComment("Connected to JIRA Server: \"" + serverTitle + "\", version: " + version);
} catch (FailingHttpStatusCodeException | IOException | JSONException e) {
throw new SimpleGepardException("Cannot connect to JIRA properly, pls check the settings, reason: " + e.getMessage(), e);
}
}
示例4: BinaryArrayImpl
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* Constructor that allows the creation of a BinaryArray object using an
* array of double values.
*
* @param doubleArray being the array of double values to be converted to
* base64 and placed in the mzData element .../binaryDataGroup.
* @param aDataEndian The byte order is used when reading or writing
* multibyte values stored as mzData element .../data/endian. Only possible
* values are defined by the static String members of this class
* 'BIG_ENDIAN_LABEL' (or "big") and 'LITTLE_ENDIAN_LABEL' (or "little").
*/
public BinaryArrayImpl(double[] doubleArray,
String aDataEndian) {
this.iDataEndian = aDataEndian;
if (doubleArray == null) {
throw new IllegalArgumentException("The double[] 'doubleArray' that has been passed into the method BinaryArrayImpl is null. This is not valid.");
}
ByteBuffer buffer = ByteBuffer.allocate(doubleArray.length * BYTES_TO_HOLD_DOUBLE);
buffer.order(getByteOrder());
for (double aDoubleArray : doubleArray) {
buffer.putDouble(aDoubleArray);
}
String base64String = Base64.encode(buffer.array());
constructorCommon(base64String, doubleArray.length, DOUBLE_PRECISION);
}
示例5: sendUnicastNotification
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* Send unicast notification.
*
* @param keyHash the key hash
* @param appId the app id
* @param schemaId the schema id
* @param type the type
* @return the endpoint notification dto
* @throws Exception the exception
*/
protected EndpointNotificationDto sendUnicastNotification(byte[] keyHash, String appId,
String schemaId, NotificationTypeDto type) throws Exception {
NotificationDto notification = new NotificationDto();
if (strIsEmpty(appId)) {
ApplicationDto applicationDto = createApplication(tenantAdminDto);
notification.setApplicationId(applicationDto.getId());
} else {
notification.setApplicationId(appId);
}
if (strIsEmpty(schemaId)) {
NotificationSchemaDto schema = createNotificationSchema(appId, type);
notification.setSchemaId(schema.getId());
} else {
notification.setSchemaId(schemaId);
}
TopicDto topic = createTopic(appId, TopicTypeDto.MANDATORY);
notification.setTopicId(topic.getId());
loginTenantDeveloper(tenantDeveloperDto.getUsername());
EndpointNotificationDto savedUnicast = client
.sendUnicastNotification(notification, Base64.encode(keyHash), "body",
"{\"notificationBody\":\"dummy\", \"systemNotificationParam1\":42, \"systemNotificationParam2\":43}");
return savedUnicast;
}
示例6: fromString
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/** Read the object from Base64 string. */
public static Object fromString( String s ) throws IOException, ClassNotFoundException {
byte [] data = Base64.decode( s );
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( data ) );
Object o = ois.readObject();
ois.close();
return o;
}
示例7: toString
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/** Write the object to a Base64 string. */
public static String toString( Serializable o ) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( o );
oos.close();
return new String( Base64.encode( baos.toByteArray() ) );
}
示例8: getDecodedByteArray
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* <p>Returns the contents of the binary array <i>decoded</i> using the
* Base64 algorithm.</p>
*
* @return the contents of the binary array <i>decoded</i> using the Base64
* algorithm.
*/
public byte[] getDecodedByteArray() {
if (this.getBase64String() == null) {
return null;
} else {
return Base64.decode(this.getBase64String());
}
}
示例9: getActualValue
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
byte[] decoded = Base64.decode(content);
if (decoded == null)
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "base64Binary"});
return new XBase64(decoded);
}
示例10: unparse
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* Convert a value of this datatype out
* to lexical form.
*/
@Override
public String unparse(Object value) {
if (value instanceof byte[]) {
return Base64.encode((byte[])value);
} else {
throw new DatatypeFormatException("base64 asked to encode an unwrapped byte array");
}
}
示例11: getActualValue
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
@Override
public Object getActualValue(String content)
throws XSDBuiltinTypeFormatException {
byte[] decoded = Base64.decode(content);
if(decoded == null) throw new XSDBuiltinTypeFormatException(content, "invalid BASE64BINARY data");
return decoded;
}
示例12: toString
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
/**
* @see org.projectforge.xml.stream.converter.IConverter#toString(java.lang.Object)
*/
@Override
public String toString(final Object obj)
{
if (obj == null || obj instanceof byte[] == false) {
return null;
}
final String result = Base64.encode((byte[]) obj);
return result;
}
示例13: loadImage
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
private String loadImage(File picFile) throws IOException {
String picBase64 = null;
t("begin loading " + picFile);
byte[] picData = toByteArray(picFile);
if (picFile.getName().endsWith(".png")) {
picBase64 = "data:image/png;base64," + Base64.encode(picData);
} else if (picFile.getName().endsWith(".jpg")) {
picBase64 = "data:image/jpeg;base64," + Base64.encode(picData);
}
t("end loading " + picFile);
return picBase64;
}
示例14: encodeBase64
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
public static String encodeBase64(String source) throws UnsupportedEncodingException {
return Base64.encode(source.getBytes("UTF-8"));
}
示例15: decodeBase64
import org.apache.xerces.impl.dv.util.Base64; //导入依赖的package包/类
public static String decodeBase64(String base64String) throws UnsupportedEncodingException {
return new String(Base64.decode(base64String), "UTF-8");
}