<commit_before>/*
 * Copyright 2015 the original author or authors.
 *
 * 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 io.atomix.catalyst.serializer;

import io.atomix.catalyst.CatalystException;

import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * Serializable type resolver based on {@link java.util.ServiceLoader}.
 * <p>
 * This type resolver resolves serializable types and serializers via {@link java.util.ServiceLoader}. It searches the
 * classpath for serializable types and serializers registered as implementations of {@link CatalystSerializable},
 * {@link TypeSerializer}, or {@link TypeSerializerFactory}. Serializables can be annotated
 * with the {@link SerializeWith} annotation to identify serializable type IDs and serializers, and
 * serializers and factories can be annotated with the {@link Serialize} annotation to identify
 * serializable types and IDs.
 * <p>
 * All classes that are loadable as services must provide a default no-argument constructor.
 *
 * @author <a href="http://github.com/kuujo"><NAME></a>
 */
public class ServiceLoaderTypeResolver implements SerializableTypeResolver {

  @Override
  public void resolve(SerializerRegistry registry) {
    resolveFactories(registry);
    resolveSerializers(registry);
    resolveSerializables(registry);
  }

  /**
   * Loads a list of classes from the classpath.
   */
  @SuppressWarnings("unchecked")
  private <T> List<Class<? extends T>> load(Class<T> clazz) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> urls;
    try {
      urls = cl.getResources(String.format("META-INF%sservices%s%s", File.separator, File.separator, clazz.getName()));
    } catch (IOException e) {
      throw new CatalystException(e);
    }

    List<Class<? extends T>> classes = new ArrayList<>();
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();<commit_msg>Use OS agnostic path separators when loading classes via ServiceLoader.<commit_after>/*
 * Copyright 2015 the original author or authors.
 *
 * 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 io.atomix.catalyst.serializer;

import io.atomix.catalyst.CatalystException;

import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * Serializable type resolver based on {@link java.util.ServiceLoader}.
 * <p>
 * This type resolver resolves serializable types and serializers via {@link java.util.ServiceLoader}. It searches the
 * classpath for serializable types and serializers registered as implementations of {@link CatalystSerializable},
 * {@link TypeSerializer}, or {@link TypeSerializerFactory}. Serializables can be annotated
 * with the {@link SerializeWith} annotation to identify serializable type IDs and serializers, and
 * serializers and factories can be annotated with the {@link Serialize} annotation to identify
 * serializable types and IDs.
 * <p>
 * All classes that are loadable as services must provide a default no-argument constructor.
 *
 * @author <a href="http://github.com/kuujo"><NAME></a>
 */
public class ServiceLoaderTypeResolver implements SerializableTypeResolver {

  @Override
  public void resolve(SerializerRegistry registry) {
    resolveFactories(registry);
    resolveSerializers(registry);
    resolveSerializables(registry);
  }

  /**
   * Loads a list of classes from the classpath.
   */
  @SuppressWarnings("unchecked")
  private <T> List<Class<? extends T>> load(Class<T> clazz) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> urls;
    try {
      urls = cl.getResources(String.format("META-INF/services/%s", clazz.getName()));
    } catch (IOException e) {
      throw new CatalystException(e);
    }

    List<Class<? extends T>> classes = new ArrayList<>();
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();
{'fraction_non_alphanumeric': 0.09687123947051744, 'fraction_numerical': 0.003208985158443642, 'mean_word_length': 4.368137782561894, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1093390', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1305, 'n_words': 500}