remove java.util.logging from core, json, yaml, settings

This commit is contained in:
Jörg Prante 2020-05-07 20:07:21 +02:00
parent 0e37917c47
commit 00639d970b
23 changed files with 43 additions and 136 deletions

View file

@ -20,16 +20,12 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public final class XContentBuilder implements ToXContent, Flushable, Closeable {
private static final Logger logger = Logger.getLogger(XContentBuilder.class.getName());
private final OutputStream outputStream;
private final XContentGenerator generator;
@ -802,12 +798,8 @@ public final class XContentBuilder implements ToXContent, Flushable, Closeable {
generator.close();
}
public BytesReference bytes() {
try {
generator.close();
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
}
public BytesReference bytes() throws IOException {
generator.close();
return ((BytesStreamOutput) outputStream).bytes();
}
@ -815,8 +807,9 @@ public final class XContentBuilder implements ToXContent, Flushable, Closeable {
* Returns a string representation of the builder (only applicable for text based xcontent).
* Only applicable when the builder is constructed with {@link BytesStreamOutput}.
* @return string
* @throws IOException if string can not be converted to UTF-8
*/
public String string() {
public String string() throws IOException {
return bytes().toUtf8();
}

View file

@ -7,16 +7,12 @@ import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class XContentHelper {
private static final Logger logger = Logger.getLogger(XContentHelper.class.getName());
private static final String UNKNOWN_FORMAT = "unknown format";
private XContentHelper() {
@ -169,7 +165,6 @@ public class XContentHelper {
try {
generator.writeBinary(parseBase16(parser.text()));
} catch (IllegalArgumentException e) {
logger.log(Level.FINE, e.getMessage(), e);
generator.writeString(parser.text());
}
} else {

View file

@ -8,37 +8,23 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class XContentService {
private static final Logger logger = Logger.getLogger(XContentService.class.getName());
private static final Map<String, XContent> xcontents = new HashMap<>();
private static final XContentService instance = new XContentService();
private XContentService() {
try {
ServiceLoader<XContent> loader = ServiceLoader.load(XContent.class);
for (XContent xContent : loader) {
if (!xcontents.containsKey(xContent.name())) {
xcontents.put(xContent.name(), xContent);
}
static {
ServiceLoader<XContent> loader = ServiceLoader.load(XContent.class);
for (XContent xContent : loader) {
if (!xcontents.containsKey(xContent.name())) {
xcontents.put(xContent.name(), xContent);
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
public static XContentService getInstance() {
return instance;
}
public static XContentBuilder builder(String name) throws IOException {
return xcontents.containsKey(name) ? XContentBuilder.builder(xcontents.get(name)) : null;
}
@ -59,5 +45,4 @@ public class XContentService {
}
return null;
}
}

View file

@ -30,21 +30,17 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class Settings implements AutoCloseable {
private static final Logger logger = Logger.getLogger(Settings.class.getName());
public static final Settings EMPTY_SETTINGS = new Builder().build();
public static final String[] EMPTY_ARRAY = new String[0];
public static final int BUFFER_SIZE = 1024 * 8;
public static final int BUFFER_SIZE = 1024 * 4;
private DefaultSettingsRefresher refresher;
@ -621,7 +617,8 @@ public class Settings implements AutoCloseable {
* @return builder
*/
public Builder loadFromString(String source) {
SettingsLoader settingsLoader = SettingsLoaderService.loaderFromString(source);
SettingsLoaderService settingsLoaderService = new SettingsLoaderService();
SettingsLoader settingsLoader = settingsLoaderService.loaderFromString(source);
try {
Map<String, String> loadedSettings = settingsLoader.load(source);
put(loadedSettings);
@ -666,7 +663,8 @@ public class Settings implements AutoCloseable {
* @return builder
*/
public Builder loadFromStream(String resourceName, InputStream inputStream) throws SettingsException {
SettingsLoader settingsLoader = SettingsLoaderService.loaderFromResource(resourceName);
SettingsLoaderService settingsLoaderService = new SettingsLoaderService();
SettingsLoader settingsLoader = settingsLoaderService.loaderFromResource(resourceName);
try {
Map<String, String> loadedSettings = settingsLoader
.load(copyToString(new InputStreamReader(inputStream, StandardCharsets.UTF_8)));
@ -725,7 +723,6 @@ public class Settings implements AutoCloseable {
try {
return DateTimeFormatter.ofPattern(placeholderName).format(LocalDate.now());
} catch (IllegalArgumentException | DateTimeException e) {
logger.log(Level.FINER, e.getMessage(), e);
return map.get(placeholderName);
}
}
@ -759,11 +756,14 @@ public class Settings implements AutoCloseable {
private final AtomicBoolean closed;
private final SettingsLoaderService settingsLoaderService;
DefaultSettingsRefresher(Path path, long initialDelay, long period, TimeUnit timeUnit) {
this.path = path;
this.executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(this, initialDelay, period, timeUnit);
this.closed = new AtomicBoolean();
this.settingsLoaderService = new SettingsLoaderService();
}
@Override
@ -771,7 +771,7 @@ public class Settings implements AutoCloseable {
try {
if (!closed.get()) {
String settingsSource = Files.readString(path);
SettingsLoader settingsLoader = SettingsLoaderService.loaderFromResource(path.toString());
SettingsLoader settingsLoader = settingsLoaderService.loaderFromResource(path.toString());
map = settingsLoader.load(settingsSource);
}
} catch (IOException e) {

View file

@ -6,41 +6,30 @@ import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A settings loader service for loading {@link SettingsLoader} implementations.
*/
public final class SettingsLoaderService {
private static final Logger logger = Logger.getLogger(SettingsLoaderService.class.getName());
private final Map<Set<String>, SettingsLoader> settingsLoaderMap;
private static final Map<Set<String>, SettingsLoader> settingsLoaderMap;
static {
settingsLoaderMap = new HashMap<>();
try {
ServiceLoader<SettingsLoader> serviceLoader = ServiceLoader.load(SettingsLoader.class);
for (SettingsLoader settingsLoader : serviceLoader) {
if (!settingsLoaderMap.containsKey(settingsLoader.suffixes())) {
settingsLoaderMap.put(settingsLoader.suffixes(), settingsLoader);
}
public SettingsLoaderService() {
this.settingsLoaderMap = new HashMap<>();
ServiceLoader<SettingsLoader> serviceLoader = ServiceLoader.load(SettingsLoader.class);
for (SettingsLoader settingsLoader : serviceLoader) {
if (!settingsLoaderMap.containsKey(settingsLoader.suffixes())) {
settingsLoaderMap.put(settingsLoader.suffixes(), settingsLoader);
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
private SettingsLoaderService() {
}
/**
* Returns a {@link SettingsLoader} based on the resource name.
* @param resourceName the resource
* @return the settings loader
*/
public static SettingsLoader loaderFromResource(String resourceName) {
public SettingsLoader loaderFromResource(String resourceName) {
for (Map.Entry<Set<String>, SettingsLoader> entry : settingsLoaderMap.entrySet()) {
Set<String> suffixes = entry.getKey();
for (String suffix : suffixes) {
@ -57,7 +46,7 @@ public final class SettingsLoaderService {
* @param source the source
* @return the settings loader
*/
public static SettingsLoader loaderFromString(String source) {
public SettingsLoader loaderFromString(String source) {
for (SettingsLoader loader : settingsLoaderMap.values()) {
if (loader.canLoad(source)) {
return loader;

View file

@ -20,15 +20,12 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
/**
*
*/
public class SettingsTest extends Assert {
private static final Logger logger = Logger.getLogger(SettingsTest.class.getName());
@Test
public void testEmpty() {
Settings settings = Settings.EMPTY_SETTINGS;
@ -60,7 +57,6 @@ public class SettingsTest extends Assert {
for (Map.Entry<String, Object> entry : map.entrySet()) {
list.add((Map<String, Object>) entry.getValue());
}
logger.info(list.toString());
assertEquals("[{name=Name 0, code=Code 0}, {name=Name 1, code=Code 1}]", list.toString());
}

View file

@ -14,8 +14,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utility class for Jackson.
@ -27,8 +25,6 @@ import java.util.logging.Logger;
*/
public final class JacksonUtils {
private static final Logger logger = Logger.getLogger(JacksonUtils.class.getName());
private static final JsonNodeFactory FACTORY = JsonNodeFactory.instance;
private static final ObjectReader READER;
@ -91,17 +87,11 @@ public final class JacksonUtils {
*
* @param node the JSON value to print
* @return the pretty printed value as a string
* @see #newMapper()
* @throws IOException if writing as UTF-8 fails
*/
public static String prettyPrint(final JsonNode node) {
public static String prettyPrint(final JsonNode node) throws IOException {
final StringWriter writer = new StringWriter();
try {
WRITER.writeValue(writer, node);
writer.flush();
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
}
WRITER.writeValue(writer, node);
return writer.toString();
}

View file

@ -11,8 +11,6 @@ import com.fasterxml.jackson.databind.ObjectReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Class dedicated to reading JSON values from {@link java.io.InputStream}s and {@link
@ -33,8 +31,6 @@ import java.util.logging.Logger;
*/
public final class JsonNodeReader {
private static final Logger logger = Logger.getLogger(JsonNodeReader.class.getName());
private final ObjectReader reader;
public JsonNodeReader(final ObjectMapper mapper) {
@ -59,7 +55,6 @@ public final class JsonNodeReader {
throw builder.build();
}
} catch (JsonParseException e) {
logger.log(Level.FINE, e.getMessage(), e);
throw builder.setLocation(e.getLocation()).build();
}
return ret;

View file

@ -6,8 +6,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -16,8 +14,6 @@ import java.util.regex.Pattern;
*/
public final class Lang extends SubtagSet {
private static final Logger logger = Logger.getLogger(Lang.class.getName());
private static final String LANGUAGE = "((?:[a-zA-Z]{2,3}(?:[-_][a-zA-Z]{3}){0,3})|[a-zA-Z]{4}|[a-zA-Z]{5,8})";
private static final String SCRIPT = "((?:[-_][a-zA-Z]{4})?)";
private static final String REGION = "((?:[-_](?:(?:[a-zA-Z]{2})|(?:[0-9]{3})))?)";
@ -69,7 +65,6 @@ public final class Lang extends SubtagSet {
try {
return parse(locale.toString()).primary;
} catch (Exception e) {
logger.log(Level.FINE, e.getMessage(), e);
Subtag c = null;
Subtag primary = new Subtag(Type.PRIMARY, locale.getLanguage());
String country = locale.getCountry();

View file

@ -116,14 +116,14 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
return this;
}
public String string() {
public String string() throws IOException {
if (builder != null) {
return builder.string();
}
return null;
}
public String get() {
public String get() throws IOException {
return string();
}

View file

@ -14,8 +14,6 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -24,8 +22,6 @@ import java.util.regex.Pattern;
*/
public class IRI implements Comparable<IRI>, Node {
private static final Logger logger = Logger.getLogger(IRI.class.getName());
private static final SchemeRegistry registry = SchemeRegistry.getInstance();
private static final Pattern IRIPATTERN =
Pattern.compile("^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?");
@ -202,7 +198,7 @@ public class IRI implements Comparable<IRI>, Node {
try {
buf.append(PercentEncoders.getMatrixEncoder(StandardCharsets.UTF_8).encode(percentDecoder.decode(segment)));
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
//logger.log(Level.FINE, e.getMessage(), e);
}
}
}
@ -431,7 +427,7 @@ public class IRI implements Comparable<IRI>, Node {
try {
asciiFragment = PercentEncoders.getFragmentEncoder(StandardCharsets.UTF_8).encode(fragment);
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
//logger.log(Level.FINE, e.getMessage(), e);
}
}
return asciiFragment;
@ -442,7 +438,7 @@ public class IRI implements Comparable<IRI>, Node {
try {
asciiPath = PercentEncoders.getPathEncoder(StandardCharsets.UTF_8).encode(path);
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
//logger.log(Level.FINE, e.getMessage(), e);
}
}
return asciiPath;
@ -453,7 +449,7 @@ public class IRI implements Comparable<IRI>, Node {
try {
asciiQuery = PercentEncoders.getQueryEncoder(StandardCharsets.UTF_8).encode(query);
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
//logger.log(Level.FINE, e.getMessage(), e);
}
}
return asciiQuery;
@ -464,7 +460,7 @@ public class IRI implements Comparable<IRI>, Node {
try {
asciiUserinfo = PercentEncoders.getUnreservedEncoder(StandardCharsets.UTF_8).encode(userinfo);
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
//logger.log(Level.FINE, e.getMessage(), e);
}
}
return asciiUserinfo;
@ -527,7 +523,7 @@ public class IRI implements Comparable<IRI>, Node {
try {
return PercentEncoders.getUnreservedEncoder(StandardCharsets.UTF_8).encode(toString());
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
//logger.log(Level.FINE, e.getMessage(), e);
return null;
}
}

View file

@ -6,16 +6,12 @@ import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public final class IRINamespaceContext extends XmlNamespaceContext {
private static final Logger logger = Logger.getLogger(IRINamespaceContext.class.getName());
/**
* Share namespace.properties with {@link XmlNamespaceContext}.
*/
@ -49,7 +45,6 @@ public final class IRINamespaceContext extends XmlNamespaceContext {
try {
instance = new IRINamespaceContext(ResourceBundle.getBundle(bundleName, locale, classLoader));
} catch (MissingResourceException e) {
logger.log(Level.FINE, e.getMessage(), e);
instance = new IRINamespaceContext();
}
}

View file

@ -9,8 +9,6 @@ import java.util.ResourceBundle;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.NamespaceContext;
@ -19,8 +17,6 @@ import javax.xml.namespace.NamespaceContext;
*/
public class XmlNamespaceContext implements NamespaceContext {
private static final Logger logger = Logger.getLogger(XmlNamespaceContext.class.getName());
private static final String DEFAULT_RESOURCE =
XmlNamespaceContext.class.getPackage().getName().replace('.', '/') + '/' + "namespace";
@ -79,7 +75,6 @@ public class XmlNamespaceContext implements NamespaceContext {
try {
return new XmlNamespaceContext(ResourceBundle.getBundle(bundleName, locale, classLoader));
} catch (MissingResourceException e) {
logger.log(Level.WARNING, e.getMessage(), e);
return new XmlNamespaceContext();
}
}

View file

@ -2,15 +2,12 @@ package org.xbib.content.resource.text;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Provides an iterator over Unicode Codepoints.
*/
public abstract class CodepointIterator implements Iterator<Codepoint> {
private static final Logger logger = Logger.getLogger(CodepointIterator.class.getName());
protected int position = -1;
protected int limit = -1;
@ -346,7 +343,6 @@ public abstract class CodepointIterator implements Iterator<Codepoint> {
return false;
}
} catch (InvalidCharacterException e) {
logger.log(Level.FINE, e.getMessage(), e);
return false;
}
}

View file

@ -5,13 +5,11 @@ import org.junit.Test;
import org.xbib.content.XContentBuilder;
import org.xbib.content.XContentHelper;
import org.xbib.content.resource.XmlNamespaceContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.namespace.QName;
/**

View file

@ -2,11 +2,9 @@ package org.xbib.content.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.xbib.content.XContentBuilder;
import org.xbib.content.resource.XmlNamespaceContext;
import javax.xml.namespace.QName;
/**

View file

@ -3,7 +3,6 @@ package org.xbib.content.xml.json;
import org.junit.Test;
import org.xbib.content.resource.XmlNamespaceContext;
import org.xml.sax.InputSource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -13,7 +12,6 @@ import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import javax.xml.namespace.QName;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;

View file

@ -4,12 +4,10 @@ import org.junit.Test;
import org.xbib.content.resource.XmlNamespaceContext;
import org.xbib.content.xml.transform.StylesheetTransformer;
import org.xml.sax.InputSource;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.transform.sax.SAXSource;
@ -20,7 +18,7 @@ public class StylesheetTransformerTest {
private final QName root = new QName("http://example.org", "result", "ex");
private XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance();
private final XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance();
@Test
public void testJsonAsXML() throws Exception {

View file

@ -3,10 +3,8 @@ package org.xbib.content.xml.util;
import org.junit.Test;
import org.xbib.content.xml.stream.SaxEventConsumer;
import org.xml.sax.helpers.DefaultHandler;
import java.util.LinkedList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.events.Attribute;

View file

@ -2,7 +2,6 @@ package org.xbib.content.yaml;
import org.xbib.content.XContent;
import org.xbib.content.settings.AbstractSettingsLoader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;

View file

@ -7,7 +7,6 @@ import org.xbib.content.XContentBuilder;
import org.xbib.content.XContentGenerator;
import org.xbib.content.XContentParser;
import org.xbib.content.io.BytesReference;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

View file

@ -5,7 +5,6 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
import org.xbib.content.XContent;
import org.xbib.content.io.BytesReference;
import org.xbib.content.json.JsonXContentGenerator;
import java.io.IOException;
import java.io.OutputStream;

View file

@ -1,6 +1,6 @@
group = org.xbib
name = content
version = 2.0.6
version = 2.1.0
xbib-net.version = 2.0.3
jackson.version = 2.9.10
@ -8,9 +8,9 @@ jackson-databind.version = 2.9.10.1
woodstox.version = 6.0.2
# test
junit.version = 5.5.2
junit4.version = 4.12
hamcrest.version = 2.1
junit.version = 5.6.2
junit4.version = 4.13
hamcrest.version = 2.2
mockito.version = 3.1.0
# doc