Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "specifications"]
path = driver-core/src/test/resources/specifications
path = testing/resources/specifications
url = https://github.com/mongodb/specifications
5 changes: 5 additions & 0 deletions bson/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ plugins {

base.archivesName.set("bson")

tasks.processTestResources {
from("${rootProject.projectDir}/testing/resources")
into("${layout.buildDirectory.get()}/resources/test")
}

configureMavenPublication {
pom {
name.set("BSON")
Expand Down
10 changes: 10 additions & 0 deletions bson/src/main/org/bson/BinaryVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.bson.annotations.Beta;
import org.bson.annotations.Reason;
import org.bson.diagnostics.Logger;
import org.bson.diagnostics.Loggers;

import static org.bson.assertions.Assertions.isTrueArgument;
import static org.bson.assertions.Assertions.notNull;
Expand All @@ -33,6 +35,7 @@
* @since 5.3
*/
public abstract class BinaryVector {
protected static final Logger LOGGER = Loggers.getLogger("BinaryVector");
private final DataType dataType;

BinaryVector(final DataType dataType) {
Expand Down Expand Up @@ -67,6 +70,13 @@ public static PackedBitBinaryVector packedBitVector(final byte[] data, final byt
notNull("data", data);
isTrueArgument("Padding must be between 0 and 7 bits. Provided padding: " + padding, padding >= 0 && padding <= 7);
isTrueArgument("Padding must be 0 if vector is empty. Provided padding: " + padding, padding == 0 || data.length > 0);
if (padding > 0) {
int mask = (1 << padding) - 1;
if ((data[data.length - 1] & mask) != 0) {
// JAVA-5848 in version 6.0.0 will convert this logging into an IllegalArgumentException
LOGGER.warn("The last " + padding + " padded bits should be zero in the final byte.");
}
}
return new PackedBitBinaryVector(data, padding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExtendedJsonDoubleConverter implements Converter<Double> {
public void convert(final Double value, final StrictJsonWriter writer) {
writer.writeStartObject();
writer.writeName("$numberDouble");
writer.writeString(Double.toString(value));
writer.writeString(JsonDoubleHelper.toString(value));
writer.writeEndObject();

}
Expand Down
2 changes: 1 addition & 1 deletion bson/src/main/org/bson/json/JsonDoubleConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
class JsonDoubleConverter implements Converter<Double> {
@Override
public void convert(final Double value, final StrictJsonWriter writer) {
writer.writeNumber(Double.toString(value));
writer.writeNumber(JsonDoubleHelper.toString(value));
}
}
32 changes: 32 additions & 0 deletions bson/src/main/org/bson/json/JsonDoubleHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bson.json;

import java.util.regex.Pattern;

final class JsonDoubleHelper {

private static final Pattern POSITIVE_EXPONENT_PATTERN = Pattern.compile("E(\\+?\\d+)");
private static final String POSITIVE_EXPONENT_REPLACER = "E+$1";

static String toString(final double value) {
String doubleString = Double.toString(value);
return POSITIVE_EXPONENT_PATTERN.matcher(doubleString).replaceAll(POSITIVE_EXPONENT_REPLACER);
}

private JsonDoubleHelper() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void convert(final Double value, final StrictJsonWriter writer) {
if (value.isNaN() || value.isInfinite()) {
FALLBACK_CONVERTER.convert(value, writer);
} else {
writer.writeNumber(Double.toString(value));
writer.writeNumber(JsonDoubleHelper.toString(value));
}
}
}
50 changes: 0 additions & 50 deletions bson/src/test/resources/bson-binary-vector/float32.json

This file was deleted.

56 changes: 0 additions & 56 deletions bson/src/test/resources/bson-binary-vector/int8.json

This file was deleted.

97 changes: 0 additions & 97 deletions bson/src/test/resources/bson-binary-vector/packed_bit.json

This file was deleted.

49 changes: 0 additions & 49 deletions bson/src/test/resources/bson/array.json

This file was deleted.

Loading