]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/util/Util.java
1 package org
.asamk
.signal
.util
;
3 import com
.fasterxml
.jackson
.databind
.JsonNode
;
4 import org
.asamk
.signal
.GroupIdFormatException
;
5 import org
.whispersystems
.signalservice
.internal
.util
.Base64
;
7 import java
.io
.IOException
;
8 import java
.io
.InvalidObjectException
;
15 public static String
formatSafetyNumber(String digits
) {
16 final int partCount
= 12;
17 int partSize
= digits
.length() / partCount
;
18 StringBuilder f
= new StringBuilder(digits
.length() + partCount
);
19 for (int i
= 0; i
< partCount
; i
++) {
20 f
.append(digits
, i
* partSize
, (i
* partSize
) + partSize
).append(" ");
25 public static String
join(CharSequence separator
, Iterable
<?
extends CharSequence
> list
) {
26 StringBuilder buf
= new StringBuilder();
27 for (CharSequence str
: list
) {
28 if (buf
.length() > 0) {
29 buf
.append(separator
);
34 return buf
.toString();
37 public static JsonNode
getNotNullNode(JsonNode parent
, String name
) throws InvalidObjectException
{
38 JsonNode node
= parent
.get(name
);
40 throw new InvalidObjectException(String
.format("Incorrect file format: expected parameter %s not found ", name
));
46 public static byte[] decodeGroupId(String groupId
) throws GroupIdFormatException
{
48 return Base64
.decode(groupId
);
49 } catch (IOException e
) {
50 throw new GroupIdFormatException(groupId
, e
);