mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-08 06:01:07 +01:00
Create smack.util.stringencoder for Base64, Base32,…
Use Android's Base64 implementation when on Android, otherwise, when on Java7, use the existing one.
This commit is contained in:
parent
90c0064394
commit
5d4aa76d19
32 changed files with 491 additions and 231 deletions
|
|
@ -35,7 +35,7 @@ import org.jivesoftware.smack.packet.Message;
|
|||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
|
||||
|
|
@ -708,7 +708,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
}
|
||||
|
||||
// create data packet
|
||||
String enc = StringUtils.encodeBase64(buffer, 0, bufferPointer, false);
|
||||
String enc = Base64.encodeToString(buffer, 0, bufferPointer);
|
||||
DataPacketExtension data = new DataPacketExtension(byteStreamRequest.getSessionID(),
|
||||
this.seq, enc);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
|
||||
/**
|
||||
* Represents a chunk of data of an In-Band Bytestream within an IQ stanza or a
|
||||
|
|
@ -121,7 +121,7 @@ public class DataPacketExtension implements PacketExtension {
|
|||
}
|
||||
|
||||
// decodeBase64 will return null if bad characters are included
|
||||
this.decodedData = StringUtils.decodeBase64(data);
|
||||
this.decodedData = Base64.decode(data);
|
||||
return this.decodedData;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ import org.jivesoftware.smack.filter.PacketFilter;
|
|||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
||||
import org.jivesoftware.smack.util.Base64;
|
||||
import org.jivesoftware.smack.util.Cache;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.caps.cache.EntityCapsPersistentCache;
|
||||
import org.jivesoftware.smackx.caps.packet.CapsExtension;
|
||||
import org.jivesoftware.smackx.disco.NodeInformationProvider;
|
||||
|
|
@ -663,7 +663,7 @@ public class EntityCapsManager extends Manager {
|
|||
// (note: the Base64 output MUST NOT include whitespace and MUST set
|
||||
// padding bits to zero).
|
||||
byte[] digest = md.digest(sb.toString().getBytes());
|
||||
return Base64.encodeBytes(digest);
|
||||
return Base64.encodeToString(digest);
|
||||
}
|
||||
|
||||
private static void formFieldValuesToCaps(List<String> i, StringBuilder sb) {
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import java.io.IOException;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.util.Base32Encoder;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.util.StringEncoder;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base32;
|
||||
import org.jivesoftware.smack.util.stringencoder.StringEncoder;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
|
||||
/**
|
||||
|
|
@ -48,14 +48,14 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
|||
* Creates a new SimpleDirectoryPersistentCache Object. Make sure that the
|
||||
* cacheDir exists and that it's an directory.
|
||||
* <p>
|
||||
* Default filename encoder {@link Base32Encoder}, as this will work on all
|
||||
* Default filename encoder {@link Base32}, as this will work on all
|
||||
* file systems, both case sensitive and case insensitive. It does however
|
||||
* produce longer filenames.
|
||||
*
|
||||
* @param cacheDir
|
||||
*/
|
||||
public SimpleDirectoryPersistentCache(File cacheDir) {
|
||||
this(cacheDir, Base32Encoder.getInstance());
|
||||
this(cacheDir, Base32.getStringEncoder());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +63,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
|||
* cacheDir exists and that it's an directory.
|
||||
*
|
||||
* If your cacheDir is case insensitive then make sure to set the
|
||||
* StringEncoder to {@link Base32Encoder} (which is the default).
|
||||
* StringEncoder to {@link Base32} (which is the default).
|
||||
*
|
||||
* @param cacheDir The directory where the cache will be stored.
|
||||
* @param filenameEncoder Encodes the node string into a filename.
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
|
||||
/**
|
||||
* Properties provide an easy mechanism for clients to share data. Each property has a
|
||||
|
|
@ -182,7 +182,7 @@ public class JivePropertiesExtension implements PacketExtension {
|
|||
out = new ObjectOutputStream(byteStream);
|
||||
out.writeObject(value);
|
||||
type = "java-object";
|
||||
valueStr = StringUtils.encodeBase64(byteStream.toByteArray());
|
||||
valueStr = Base64.encodeToString(byteStream.toByteArray());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Error encoding java object", e);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
|
@ -94,7 +94,7 @@ public class JivePropertiesExtensionProvider implements PacketExtensionProvider
|
|||
else if ("java-object".equals(type)) {
|
||||
if (JivePropertiesManager.isJavaObjectEnabled()) {
|
||||
try {
|
||||
byte[] bytes = StringUtils.decodeBase64(valueText);
|
||||
byte[] bytes = Base64.decode(valueText);
|
||||
ObjectInputStream in = new ObjectInputStream(
|
||||
new ByteArrayInputStream(bytes));
|
||||
value = in.readObject();
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.vcardtemp.VCardManager;
|
||||
|
||||
/**
|
||||
|
|
@ -372,7 +373,7 @@ public class VCard extends IQ {
|
|||
}
|
||||
|
||||
// Otherwise, add to mappings.
|
||||
String encodedImage = StringUtils.encodeBase64(bytes);
|
||||
String encodedImage = Base64.encodeToString(bytes);
|
||||
|
||||
setAvatar(encodedImage, mimeType);
|
||||
}
|
||||
|
|
@ -425,7 +426,7 @@ public class VCard extends IQ {
|
|||
if (photoBinval == null) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.decodeBase64(photoBinval);
|
||||
return Base64.decode(photoBinval);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue