mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
Make StringEncoder generic
This commit is contained in:
parent
e91a8336f6
commit
7374caefef
7 changed files with 22 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © 2014 Florian Schmaus
|
* Copyright © 2014-2018 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,7 +23,7 @@ import org.jivesoftware.smack.util.stringencoder.StringEncoder;
|
||||||
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
public final class AndroidBase64UrlSafeEncoder implements StringEncoder {
|
public final class AndroidBase64UrlSafeEncoder implements StringEncoder<String> {
|
||||||
|
|
||||||
private static AndroidBase64UrlSafeEncoder instance = new AndroidBase64UrlSafeEncoder();
|
private static AndroidBase64UrlSafeEncoder instance = new AndroidBase64UrlSafeEncoder();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.jivesoftware.smack.util.StringUtils;
|
||||||
*/
|
*/
|
||||||
public class Base32 {
|
public class Base32 {
|
||||||
|
|
||||||
private static final StringEncoder base32Stringencoder = new StringEncoder() {
|
private static final StringEncoder<String> base32Stringencoder = new StringEncoder<String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String encode(String string) {
|
public String encode(String string) {
|
||||||
|
@ -49,7 +49,7 @@ public class Base32 {
|
||||||
};
|
};
|
||||||
private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ2345678";
|
private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ2345678";
|
||||||
|
|
||||||
public static StringEncoder getStringEncoder() {
|
public static StringEncoder<String> getStringEncoder() {
|
||||||
return base32Stringencoder;
|
return base32Stringencoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © 2014-2015 Florian Schmaus
|
* Copyright © 2014-2018 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,14 +20,14 @@ import org.jivesoftware.smack.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
public class Base64UrlSafeEncoder {
|
public class Base64UrlSafeEncoder {
|
||||||
private static StringEncoder base64UrlSafeEncoder;
|
private static StringEncoder<String> base64UrlSafeEncoder;
|
||||||
|
|
||||||
public static void setEncoder(StringEncoder encoder) {
|
public static void setEncoder(StringEncoder<String> encoder) {
|
||||||
Objects.requireNonNull(encoder, "encoder must no be null");
|
Objects.requireNonNull(encoder, "encoder must no be null");
|
||||||
base64UrlSafeEncoder = encoder;
|
base64UrlSafeEncoder = encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StringEncoder getStringEncoder() {
|
public static StringEncoder<String> getStringEncoder() {
|
||||||
return base64UrlSafeEncoder;
|
return base64UrlSafeEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2013-2014 Florian Schmaus
|
* Copyright 2013-2018 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,20 +21,20 @@ package org.jivesoftware.smack.util.stringencoder;
|
||||||
*
|
*
|
||||||
* @author Florian Schmaus
|
* @author Florian Schmaus
|
||||||
*/
|
*/
|
||||||
public interface StringEncoder {
|
public interface StringEncoder<O> {
|
||||||
/**
|
/**
|
||||||
* Encodes an string to another representation.
|
* Encodes an object to another representation.
|
||||||
*
|
*
|
||||||
* @param string
|
* @param object the object to encode.
|
||||||
* @return the encoded String
|
* @return the encoded String
|
||||||
*/
|
*/
|
||||||
String encode(String string);
|
String encode(O object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes an string back to it's initial representation.
|
* Decodes a string back to it's initial representation.
|
||||||
*
|
*
|
||||||
* @param string
|
* @param string the string to decode.
|
||||||
* @return the decoded String
|
* @return the decoded object
|
||||||
*/
|
*/
|
||||||
String decode(String string);
|
O decode(String string);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © 2011-2014 Florian Schmaus
|
* Copyright © 2011-2018 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,7 +43,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
||||||
private static final Logger LOGGER = Logger.getLogger(SimpleDirectoryPersistentCache.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(SimpleDirectoryPersistentCache.class.getName());
|
||||||
|
|
||||||
private final File cacheDir;
|
private final File cacheDir;
|
||||||
private final StringEncoder filenameEncoder;
|
private final StringEncoder<String> filenameEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SimpleDirectoryPersistentCache Object. Make sure that the
|
* Creates a new SimpleDirectoryPersistentCache Object. Make sure that the
|
||||||
|
@ -69,7 +69,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
||||||
* @param cacheDir The directory where the cache will be stored.
|
* @param cacheDir The directory where the cache will be stored.
|
||||||
* @param filenameEncoder Encodes the node string into a filename.
|
* @param filenameEncoder Encodes the node string into a filename.
|
||||||
*/
|
*/
|
||||||
public SimpleDirectoryPersistentCache(File cacheDir, StringEncoder filenameEncoder) {
|
public SimpleDirectoryPersistentCache(File cacheDir, StringEncoder<String> filenameEncoder) {
|
||||||
if (!cacheDir.exists())
|
if (!cacheDir.exists())
|
||||||
throw new IllegalStateException("Cache directory \"" + cacheDir + "\" does not exist");
|
throw new IllegalStateException("Cache directory \"" + cacheDir + "\" does not exist");
|
||||||
if (!cacheDir.isDirectory())
|
if (!cacheDir.isDirectory())
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class EntityCapsManagerTest extends InitExtensions {
|
||||||
assertTrue(di.containsDuplicateIdentities());
|
assertTrue(di.containsDuplicateIdentities());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testSimpleDirectoryCache(StringEncoder stringEncoder) throws IOException {
|
private static void testSimpleDirectoryCache(StringEncoder<String> stringEncoder) throws IOException {
|
||||||
|
|
||||||
EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(createTempDirectory());
|
EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(createTempDirectory());
|
||||||
EntityCapsManager.setPersistentCache(cache);
|
EntityCapsManager.setPersistentCache(cache);
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.jivesoftware.smack.util.stringencoder.StringEncoder;
|
||||||
*
|
*
|
||||||
* @author Robin Collier
|
* @author Robin Collier
|
||||||
*/
|
*/
|
||||||
public final class Java7Base64UrlSafeEncoder implements StringEncoder {
|
public final class Java7Base64UrlSafeEncoder implements StringEncoder<String> {
|
||||||
|
|
||||||
private static final Java7Base64UrlSafeEncoder instance = new Java7Base64UrlSafeEncoder();
|
private static final Java7Base64UrlSafeEncoder instance = new Java7Base64UrlSafeEncoder();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue