[jOOQ/jOOQ#13393] Replace internal usage of
DatatypeConverter::parseBase64Binary by java.util.Base64
This commit is contained in:
parent
ddcff2b86f
commit
fd05a97f92
@ -39,7 +39,6 @@ package org.jooq.codegen;
|
||||
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.nCopies;
|
||||
import static java.util.function.Function.identity;
|
||||
import static java.util.stream.Collectors.counting;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
@ -71,9 +70,9 @@ import java.math.BigInteger;
|
||||
import java.sql.Date;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -85,14 +84,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jooq.AggregateFunction;
|
||||
@ -105,7 +102,6 @@ import org.jooq.Domain;
|
||||
import org.jooq.EnumType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.Function2;
|
||||
import org.jooq.Identity;
|
||||
import org.jooq.Index;
|
||||
// ...
|
||||
@ -197,8 +193,6 @@ import org.jooq.tools.reflect.Reflect;
|
||||
import org.jooq.tools.reflect.ReflectException;
|
||||
// ...
|
||||
|
||||
import jakarta.xml.bind.DatatypeConverter;
|
||||
|
||||
|
||||
/**
|
||||
* A default implementation for code generation.
|
||||
@ -398,7 +392,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
@Override
|
||||
public final void generate0(Database db) {
|
||||
this.isoDate = DatatypeConverter.printDateTime(Calendar.getInstance(TimeZone.getTimeZone("UTC")));
|
||||
this.isoDate = Instant.now().toString();
|
||||
this.schemaVersions = new LinkedHashMap<>();
|
||||
this.catalogVersions = new LinkedHashMap<>();
|
||||
this.database.addFilter(new AvoidAmbiguousClassesFilter());
|
||||
|
||||
@ -57,6 +57,7 @@ import java.sql.Timestamp;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
@ -107,7 +108,6 @@ import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import jakarta.xml.bind.DatatypeConverter;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -621,7 +621,7 @@ abstract class AbstractResult<R extends Record> extends AbstractFormattable impl
|
||||
|
||||
// [#2741] TODO: This logic will be externalised in new SPI
|
||||
if (value instanceof byte[]) { byte[] a = (byte[]) value;
|
||||
JSONValue.writeJSONString(DatatypeConverter.printBase64Binary(a), writer);
|
||||
JSONValue.writeJSONString(Base64.getEncoder().encodeToString(a), writer);
|
||||
}
|
||||
|
||||
// [#6563] Arrays can be serialised natively in JSON
|
||||
@ -1378,12 +1378,12 @@ abstract class AbstractResult<R extends Record> extends AbstractFormattable impl
|
||||
if (value == null) {
|
||||
formatted += visual ? "{null}" : null;
|
||||
}
|
||||
else if (value.getClass() == byte[].class) {
|
||||
formatted += DatatypeConverter.printBase64Binary((byte[]) value);
|
||||
else if (value instanceof byte[]) { byte[] a = (byte[]) value;
|
||||
formatted += Base64.getEncoder().encodeToString(a);
|
||||
}
|
||||
else if (value.getClass().isArray()) {
|
||||
else if (value instanceof Object[]) { Object[] a = (Object[]) value;
|
||||
// [#6545] Nested arrays are handled recursively
|
||||
formatted += Arrays.stream((Object[]) value).map(f -> format0(f, false, visual)).collect(joining(", ", "[", "]"));
|
||||
formatted += Arrays.stream(a).map(f -> format0(f, false, visual)).collect(joining(", ", "[", "]"));
|
||||
}
|
||||
else if (value instanceof EnumType) { EnumType e = (EnumType) value;
|
||||
formatted += e.getLiteral();
|
||||
@ -1398,8 +1398,8 @@ abstract class AbstractResult<R extends Record> extends AbstractFormattable impl
|
||||
.collect(joining(", ", "(", ")"));
|
||||
}
|
||||
// [#6080] Support formatting of nested ROWs
|
||||
else if (value instanceof Param) {
|
||||
formatted += format0(((Param<?>) value).getValue(), false, visual);
|
||||
else if (value instanceof Param) { Param<?> p = (Param<?>) value;
|
||||
formatted += format0(p.getValue(), false, visual);
|
||||
}
|
||||
|
||||
// [#5238] Oracle DATE is really a TIMESTAMP(0)...
|
||||
|
||||
@ -43,6 +43,7 @@ import static org.jooq.impl.DSL.field;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.DefaultDataType.getDataType;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
import static org.jooq.impl.Tools.convertHexToBytes;
|
||||
import static org.jooq.impl.Tools.fields;
|
||||
import static org.jooq.impl.Tools.newRecord;
|
||||
import static org.jooq.tools.StringUtils.defaultIfBlank;
|
||||
@ -50,6 +51,7 @@ import static org.jooq.tools.StringUtils.defaultIfBlank;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -63,8 +65,6 @@ import org.jooq.Result;
|
||||
import org.jooq.tools.json.ContainerFactory;
|
||||
import org.jooq.tools.json.JSONParser;
|
||||
|
||||
import jakarta.xml.bind.DatatypeConverter;
|
||||
|
||||
/**
|
||||
* A very simple JSON reader based on Simple JSON.
|
||||
*
|
||||
@ -232,8 +232,15 @@ final class JSONReader<R extends Record> {
|
||||
|
||||
// [#8829] LoaderImpl expects binary data to be encoded in base64,
|
||||
// not according to org.jooq.tools.Convert
|
||||
if (field.getType() == byte[].class && record.get(i) instanceof String)
|
||||
record.set(i, DatatypeConverter.parseBase64Binary((String) record.get(i)));
|
||||
if (field.getType() == byte[].class && record.get(i) instanceof String) {
|
||||
String s = (String) record.get(i);
|
||||
|
||||
// [#12134] SQL/JSON MULTISET and other forms of serialisation may produce hex encoded binary data
|
||||
if (s.startsWith("\\x"))
|
||||
record.set(i, convertHexToBytes(s, 1, Integer.MAX_VALUE));
|
||||
else
|
||||
record.set(i, Base64.getDecoder().decode(s));
|
||||
}
|
||||
|
||||
// [#12155] Recurse for nested data types
|
||||
else if (multiset && field.getDataType().isMultiset())
|
||||
|
||||
@ -57,6 +57,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@ -66,8 +67,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.jooq.BatchBindStep;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.DSLContext;
|
||||
@ -805,7 +804,7 @@ final class LoaderImpl<R extends Record> implements
|
||||
row[i] = null;
|
||||
else if (i < fields.length && fields[i] != null)
|
||||
if (fields[i].getType() == byte[].class && row[i] instanceof String)
|
||||
row[i] = DatatypeConverter.parseBase64Binary((String) row[i]);
|
||||
row[i] = Base64.getDecoder().decode((String) row[i]);
|
||||
|
||||
// [#10583] Pad row to the fields length
|
||||
if (row.length < fields.length)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user