<commit_before>/**
 *
 * Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
 *
 * 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.speedment.internal.util.document;

import com.speedment.config.db.Project;
import com.google.gson.Gson;
import com.speedment.annotation.Api;
import com.speedment.exception.SpeedmentException;
import com.speedment.internal.core.config.db.ProjectImpl;
import static com.speedment.util.StaticClassUtil.instanceNotAllowed;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;


/**
 *
 * @author <NAME>
 */
@Api(version = "2.3")
public final class DocumentTranscoder {
    
    public static final String ROOT = "config";
    
    public static String save(Project project) throws SpeedmentException {
        final Gson gson   = new Gson();
        final String json = gson.toJson(project);
        return json;
    }
    
    public static void save(Project project, Path location) throws SpeedmentException {
        try {Files.write(location, save(project).getBytes());}
        catch (final IOException ex) {
            throw new SpeedmentException(
                "Could not save json-file to path '" + location + "'."
            );
        }
    }
    
    public static Project load(String json) throws SpeedmentException {
        final Gson gson = new Gson();
        return gson.fromJson(json, ProjectImpl.class);
    }
    
    public static Project load(Path location) throws SpeedmentException {
        try {
            final byte[] content = Files.readAllBytes(location);
            return load(new String(content));
        } catch (final IOException ex) {
            throw new SpeedmentException(
                "Could not load json-file from path '" + location + "'."
            );
        }
    }
    
    private DocumentTranscoder() { instanceNotAllowed(getClass()); }
}<commit_msg>Make json pretty<commit_after>/**
 *
 * Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
 *
 * 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.speedment.internal.util.document;

import com.speedment.config.db.Project;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.speedment.annotation.Api;
import com.speedment.exception.SpeedmentException;
import com.speedment.internal.core.config.db.ProjectImpl;
import static com.speedment.util.StaticClassUtil.instanceNotAllowed;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;


/**
 *
 * @author <NAME>
 */
@Api(version = "2.3")
public final class DocumentTranscoder {
    
    public static final String ROOT = "config";
    
    public static String save(Project project) throws SpeedmentException {
        final Gson gson   = newGson();
        final String json = gson.toJson(project);
        return json;
    }
    
    public static void save(Project project, Path location) throws SpeedmentException {
        try {Files.write(location, save(project).getBytes());}
        catch (final IOException ex) {
            throw new SpeedmentException(
                "Could not save json-file to path '" + location + "'."
            );
        }
    }
    
    public static Project load(String json) throws SpeedmentException {
        final Gson gson = newGson();
        return gson.fromJson(json, ProjectImpl.class);
    }
    
    public static Project load(Path location) throws SpeedmentException {
        try {
            final byte[] content = Files.readAllBytes(location);
            return load(new String(content));
        } catch (final IOException ex) {
            throw new SpeedmentException(
                "Could not load json-file from path '" + location + "'."
            );
        }
    }
    
    private static Gson newGson() {
        return new GsonBuilder()
            .setPrettyPrinting()
            .create();
    }
    
    private DocumentTranscoder() { instanceNotAllowed(getClass()); }
}
{'fraction_non_alphanumeric': 0.09526686807653575, 'fraction_numerical': 0.005639476334340383, 'mean_word_length': 2.8377125193199384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5046148', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1315, 'n_words': 437}