<commit_before>/*
 * Copyright 2016 ZJNU ACM.
 *
 * 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 com.ckfinder.connector.errors;

import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import org.junit.Test;

/**
 *
 * @author zhanhb
 */
public class ErrorUtilsTest {

    /**
     * Test of getErrorMsgByLangAndCode method, of class ErrorUtils.
     * @throws java.lang.Exception
     */
    @Test
    public void testGetErrorMsgByLangAndCode() throws Exception {
        System.out.println("getErrorMsgByLangAndCode");
        URL location = ErrorUtils.class.getProtectionDomain().getCodeSource().getLocation();
        Path base = Paths.get(location.toURI()).resolve(ErrorUtils.class.getPackage().getName().replace('.', '/'));
        System.out.println(base);
        ErrorUtils instance = ErrorUtils.getInstance();
        Field field = ErrorUtils.class.getDeclaredField("langMap");
        field.setAccessible(true);
        Object obj = field.get(instance);
        for (Map.Entry<String, Map<Integer, String>> en : ((Map<String, Map<Integer, String>>) obj).entrySet()) {
            String key = en.getKey();
            Map<Integer, String> value = en.getValue();
            Locale locale = new Locale(key);
            Properties p = new Properties();
            for (Map.Entry<Integer, String> entry : value.entrySet()) {
                Integer key1 = entry.getKey();
                String value1 = entry.getValue();
                p.setProperty("" + key1, value1);
            }
            Path path = base.resolve("LocalStrings_" + locale + ".properties");
            try (OutputStream out = Files.newOutputStream(path)) {
                p.store(out, null);
            }
            System.out.println(path);
            ResourceBundle.getBundle("com/ckfinder/connector/errors/LocalStrings", locale);
        }

    }

}<commit_msg>Change ErrorUtilsTest to main class<commit_after>/*
 * Copyright 2016 ZJNU ACM.
 *
 * 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 com.ckfinder.connector.errors;

import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 *
 * @author zhanhb
 */
public class ErrorUtilsTest {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
        URL location = ErrorUtils.class.getProtectionDomain().getCodeSource().getLocation();
        Path base = Paths.get(location.toURI()).resolve(ErrorUtils.class.getPackage().getName().replace('.', '/'));
        ErrorUtils instance = ErrorUtils.getInstance();
        Field field = ErrorUtils.class.getDeclaredField("langMap");
        field.setAccessible(true);
        Object obj = field.get(instance);
        for (Map.Entry<String, Map<Integer, String>> en : ((Map<String, Map<Integer, String>>) obj).entrySet()) {
            String key = en.getKey();
            Map<Integer, String> value = en.getValue();
            Locale locale = new Locale(key);
            Properties p = new Properties();
            for (Map.Entry<Integer, String> entry : value.entrySet()) {
                Integer key1 = entry.getKey();
                String value1 = entry.getValue();
                p.setProperty("" + key1, value1);
            }
            Path path = base.resolve("LocalStrings_" + locale + ".properties");
            try (OutputStream out = Files.newOutputStream(path)) {
                p.store(out, null);
            }
            ResourceBundle.getBundle("com/ckfinder/connector/errors/LocalStrings", locale);
        }

    }

}
{'fraction_non_alphanumeric': 0.11743341404358354, 'fraction_numerical': 0.004842615012106538, 'mean_word_length': 2.8817541111981204, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '531789', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1315, 'n_words': 386}