]>
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
;
5 import org
.asamk
.signal
.GroupIdFormatException
;
6 import org
.whispersystems
.signalservice
.internal
.util
.Base64
;
8 import java
.io
.IOException
;
9 import java
.io
.InvalidObjectException
;
16 public static String
formatSafetyNumber(String digits
) {
17 final int partCount
= 12;
18 int partSize
= digits
.length() / partCount
;
19 StringBuilder f
= new StringBuilder(digits
.length() + partCount
);
20 for (int i
= 0; i
< partCount
; i
++) {
21 f
.append(digits
, i
* partSize
, (i
* partSize
) + partSize
).append(" ");
26 public static String
join(CharSequence separator
, Iterable
<?
extends CharSequence
> list
) {
27 StringBuilder buf
= new StringBuilder();
28 for (CharSequence str
: list
) {
29 if (buf
.length() > 0) {
30 buf
.append(separator
);
35 return buf
.toString();
38 public static JsonNode
getNotNullNode(JsonNode parent
, String name
) throws InvalidObjectException
{
39 JsonNode node
= parent
.get(name
);
41 throw new InvalidObjectException(String
.format("Incorrect file format: expected parameter %s not found ", name
));
47 public static byte[] decodeGroupId(String groupId
) throws GroupIdFormatException
{
49 return Base64
.decode(groupId
);
50 } catch (IOException e
) {
51 throw new GroupIdFormatException(groupId
, e
);