<commit_before>package com.cloudant.p2p.listener;

import com.cloudant.sync.datastore.BasicDocumentRevision;
import com.cloudant.sync.datastore.Datastore;
import com.cloudant.sync.datastore.DatastoreExtended;
import com.cloudant.sync.datastore.DatastoreManager;
import com.cloudant.sync.datastore.DocumentBody;
import com.cloudant.sync.datastore.DocumentBodyFactory;
import com.cloudant.sync.datastore.DocumentRevision;
import com.cloudant.sync.datastore.DocumentRevisionBuilder;
import com.cloudant.sync.datastore.MutableDocumentRevision;
import com.cloudant.sync.util.ExtendedJSONUtils;
import com.cloudant.sync.util.JSONUtils;

import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.Put;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

// Do not use this code for production - it is only a proof-of-concept.
public class HttpListener extends ServerResource {

    private static final Logger logger = Logger.getLogger(HttpListener.class.getCanonicalName());

    // TODO need to ensure static access is thread-safe
    private static DatastoreManager manager;

    public HttpListener() {

        String databaseDir;

        String runtime = System.getProperty("java.runtime.name");

        if (runtime.toLowerCase().equals("android runtime")) {
            // FIXME allow this path to be configurable
            databaseDir = "/data/data/com.example.snowch.myapplication/app_datastores";
        } else {
            databaseDir = System.getProperty("DB_DIR");
        }

        File path = new File(databaseDir);
        manager = new DatastoreManager(databaseDir);
    }

    @java.lang.Override
    protected void doInit() throws ResourceException {
        //Context context = getContext();

        super.doInit();
    }

    // TODO
    // can hierachical URL's be used here?
    // http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/routing/hierarchical-uris

    @Get() // @Get is required for both GET and HEAD requests
    public Representation handleHeadAndGet() {

        String path = getReference().getPath();

        String dbname = getDatabaseName(path);

        if (!dbNameExists(dbname)) {<commit_msg>add documentation<commit_after>package com.cloudant.p2p.listener;

import com.cloudant.sync.datastore.BasicDocumentRevision;
import com.cloudant.sync.datastore.Datastore;
import com.cloudant.sync.datastore.DatastoreExtended;
import com.cloudant.sync.datastore.DatastoreManager;
import com.cloudant.sync.datastore.DocumentBody;
import com.cloudant.sync.datastore.DocumentBodyFactory;
import com.cloudant.sync.datastore.DocumentRevision;
import com.cloudant.sync.datastore.DocumentRevisionBuilder;
import com.cloudant.sync.datastore.MutableDocumentRevision;
import com.cloudant.sync.util.ExtendedJSONUtils;
import com.cloudant.sync.util.JSONUtils;

import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.Put;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

// Do not use this code for production - it is only a proof-of-concept.
public class HttpListener extends ServerResource {

    private static final Logger logger = Logger.getLogger(HttpListener.class.getCanonicalName());

    // TODO need to ensure static access is thread-safe
    private static DatastoreManager manager;

    public HttpListener() {

        String databaseDir;

        String runtime = System.getProperty("java.runtime.name");

        if (runtime.toLowerCase().equals("android runtime")) {
            // FIXME allow this path to be configurable
            // maybe pass values through restlet Context?
            databaseDir = "/data/data/com.example.snowch.myapplication/app_datastores";
        } else {
            databaseDir = System.getProperty("DB_DIR");
        }

        File path = new File(databaseDir);
        manager = new DatastoreManager(databaseDir);
    }

    @java.lang.Override
    protected void doInit() throws ResourceException {
        //Context context = getContext();

        super.doInit();
    }

    // TODO
    // can hierachical URL's be used here?
    // http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/routing/hierarchical-uris

    @Get() // @Get is required for both GET and HEAD requests
    public Representation handleHeadAndGet() {

        String path = getReference().getPath();

        String dbname = getDatabaseName(path);

        if (!dbNameExists(dbname)) {
{'fraction_non_alphanumeric': 0.10081997763697353, 'fraction_numerical': 0.0011181513231457323, 'mean_word_length': 3.8570135746606335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5448661', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1514, 'n_words': 333}