Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you 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.openqa.selenium.json;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.logging.LogLevelMapping;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
public class JsonOutput implements Closeable {
private static final Logger LOG = Logger.getLogger(JsonOutput.class.getName());
private static final int MAX_DEPTH = 10;
private static final Predicate> GSON_ELEMENT;
static {
Predicate> gsonElement;
try {
Class> elementClass = Class.forName("com.google.gson.JsonElement");
gsonElement = elementClass::isAssignableFrom;
} catch (ReflectiveOperationException e) {
gsonElement = clazz -> false;
}
GSON_ELEMENT = gsonElement;
}
// https://www.json.org has some helpful comments on characters to escape
// See also https://tools.ietf.org/html/rfc8259#section-7 and
// https://github.com/google/gson/issues/341 so we escape those as well.
// It's legal to escape any character, so to be nice to HTML parsers,
// we'll also escape "<" and "&"
private static final Map ESCAPES;
static {
// increased initial capacity to avoid hash collisions, especially for the following ranges:
// '0' to '9', 'a' to 'z', 'A' to 'Z'
Map builder = new LinkedHashMap<>(128);
for (int i = 0; i <= 0x1f; i++) {
// We want nice looking escapes for these, which are called out
// by json.org
if (!(i == '\b' || i == '\f' || i == '\n' || i == '\r' || i == '\t')) {
builder.put(i, String.format("\\u%04x", i));
}
}
builder.put((int) '"', "\\\"");
builder.put((int) '\\', "\\\\");
builder.put((int) '/', "\\u002f");
builder.put((int) '\b', "\\b");
builder.put((int) '\f', "\\f");
builder.put((int) '\n', "\\n");
builder.put((int) '\r', "\\r");
builder.put((int) '\t', "\\t");
builder.put((int) '\u2028', "\\u2028");
builder.put((int) '<', String.format("\\u%04x", (int) '<'));
builder.put((int) '&', String.format("\\u%04x", (int) '&'));
ESCAPES = Collections.unmodifiableMap(builder);
}
private final Map>, SafeBiConsumer