|
1 | 1 | package org.javawebstack.abstractdata.bson; |
2 | 2 |
|
3 | 3 | import org.bson.*; |
4 | | -import org.bson.internal.Base64; |
5 | 4 | import org.bson.types.Decimal128; |
6 | 5 | import org.bson.types.ObjectId; |
7 | 6 | import org.javawebstack.abstractdata.*; |
8 | 7 |
|
| 8 | +import java.nio.charset.StandardCharsets; |
9 | 9 | import java.text.DateFormat; |
10 | 10 | import java.text.ParseException; |
11 | 11 | import java.text.SimpleDateFormat; |
| 12 | +import java.util.Base64; |
12 | 13 | import java.util.Date; |
13 | 14 |
|
14 | 15 | public class BsonConverter { |
@@ -77,8 +78,9 @@ public AbstractElement toAbstract(BsonValue value) { |
77 | 78 | .set("i", Integer.toUnsignedLong(value.asTimestamp().getInc())) |
78 | 79 | ); |
79 | 80 | case BINARY: |
| 81 | + String base64 = new String(Base64.getEncoder().encode(value.asBinary().getData())); |
80 | 82 | return new AbstractObject().set("$binary", new AbstractObject() |
81 | | - .set("base64", Base64.encode(value.asBinary().getData())) |
| 83 | + .set("base64", base64) |
82 | 84 | .set("subType", String.format("%02x", value.asBinary().getType())) |
83 | 85 | ); |
84 | 86 | case ARRAY: { |
@@ -155,7 +157,7 @@ public BsonValue toBson(AbstractElement element) { |
155 | 157 | if(o.size() == 1 && o.has("$binary") && o.get("$binary").isObject()) { |
156 | 158 | AbstractObject bin = o.object("$binary"); |
157 | 159 | if(bin.has("base64") && bin.has("subType") && bin.get("base64").isString() && bin.get("subType").isString()) { |
158 | | - byte[] data = Base64.decode(bin.string("base64")); |
| 160 | + byte[] data = Base64.getDecoder().decode(bin.string("base64")); |
159 | 161 | byte type = (byte) Integer.parseInt(bin.string("subType"), 16); |
160 | 162 | return new BsonBinary(type, data); |
161 | 163 | } |
|
0 commit comments