mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Extract util methods to separate classes
This commit is contained in:
parent
4ab904b88e
commit
7443225d96
6 changed files with 168 additions and 131 deletions
|
@ -1,10 +1,56 @@
|
|||
package org.asamk.signal.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Util {
|
||||
public static File createTempFile() throws IOException {
|
||||
return File.createTempFile("signal_tmp_", ".tmp");
|
||||
|
||||
private Util() {
|
||||
}
|
||||
|
||||
public static String formatSafetyNumber(String digits) {
|
||||
final int partCount = 12;
|
||||
int partSize = digits.length() / partCount;
|
||||
StringBuilder f = new StringBuilder(digits.length() + partCount);
|
||||
for (int i = 0; i < partCount; i++) {
|
||||
f.append(digits, i * partSize, (i * partSize) + partSize).append(" ");
|
||||
}
|
||||
return f.toString();
|
||||
}
|
||||
|
||||
public static Map<String, String> getQueryMap(String query) {
|
||||
String[] params = query.split("&");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String param : params) {
|
||||
String name = null;
|
||||
final String[] paramParts = param.split("=");
|
||||
try {
|
||||
name = URLDecoder.decode(paramParts[0], "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Impossible
|
||||
}
|
||||
String value = null;
|
||||
try {
|
||||
value = URLDecoder.decode(paramParts[1], "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Impossible
|
||||
}
|
||||
map.put(name, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String join(CharSequence separator, Iterable<? extends CharSequence> list) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (CharSequence str : list) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(separator);
|
||||
}
|
||||
buf.append(str);
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue