Package com.google.refine.util

Examples of com.google.refine.util.Pool


    }

    protected static void saveToFile(Project project, File file) throws Exception {
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
        try {
            Pool pool = new Pool();

            out.putNextEntry(new ZipEntry("data.txt"));
            try {
                project.saveToOutputStream(out, pool);
            } finally {
                out.closeEntry();
            }

            out.putNextEntry(new ZipEntry("pool.txt"));
            try {
                pool.save(out);
            } finally {
                out.closeEntry();
            }
        } finally {
            out.close();
View Full Code Here


            File file,
            long id
    ) throws Exception {
        ZipFile zipFile = new ZipFile(file);
        try {
            Pool pool = new Pool();
            ZipEntry poolEntry = zipFile.getEntry("pool.txt");
            if (poolEntry != null) {
                pool.load(zipFile.getInputStream(poolEntry));
            } // else, it's a legacy project file

            return Project.loadFromInputStream(
                    zipFile.getInputStream(zipFile.getEntry("data.txt")),
                    id,
View Full Code Here

            String callback = request.getParameter("callback");
           
            int start = Math.min(project.rows.size(), Math.max(0, getIntegerParameter(request, "start", 0)));
            int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20)));
           
            Pool pool = new Pool();
            Properties options = new Properties();
            options.put("project", project);
            options.put("reconCandidateOmitTypes", true);
            options.put("pool", pool);
           
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", callback == null ? "application/json" : "text/javascript");
           
            PrintWriter writer = response.getWriter();
            if (callback != null) {
                writer.write(callback);
                writer.write("(");
            }
           
            JSONWriter jsonWriter = new JSONWriter(writer);
            jsonWriter.object();
           
            RowWritingVisitor rwv = new RowWritingVisitor(start, limit, jsonWriter, options);
           
            JSONObject sortingJson = null;
            try{
                String json = request.getParameter("sorting");
                sortingJson = (json == null) ? null :
                    ParsingUtilities.evaluateJsonStringToObject(json);
            } catch (JSONException e) {
            }

            if (engine.getMode() == Mode.RowBased) {
                FilteredRows filteredRows = engine.getAllFilteredRows();
                RowVisitor visitor = rwv;
               
                if (sortingJson != null) {
                    SortingRowVisitor srv = new SortingRowVisitor(visitor);
                   
                    srv.initializeFromJSON(project, sortingJson);
                    if (srv.hasCriteria()) {
                        visitor = srv;
                    }
                }
               
                jsonWriter.key("mode"); jsonWriter.value("row-based");
                jsonWriter.key("rows"); jsonWriter.array();
                filteredRows.accept(project, visitor);
                jsonWriter.endArray();
                jsonWriter.key("filtered"); jsonWriter.value(rwv.total);
                jsonWriter.key("total"); jsonWriter.value(project.rows.size());
            } else {
                FilteredRecords filteredRecords = engine.getFilteredRecords();
                RecordVisitor visitor = rwv;
               
                if (sortingJson != null) {
                    SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
                   
                    srv.initializeFromJSON(project, sortingJson);
                    if (srv.hasCriteria()) {
                        visitor = srv;
                    }
                }
               
                jsonWriter.key("mode"); jsonWriter.value("record-based");
                jsonWriter.key("rows"); jsonWriter.array();
                filteredRecords.accept(project, visitor);
                jsonWriter.endArray();
                jsonWriter.key("filtered"); jsonWriter.value(rwv.total);
                jsonWriter.key("total"); jsonWriter.value(project.recordModel.getRecordCount());
            }
           
           
            jsonWriter.key("start"); jsonWriter.value(start);
            jsonWriter.key("limit"); jsonWriter.value(limit);
            jsonWriter.key("pool"); pool.write(jsonWriter, options);
           
            jsonWriter.endObject();
           
            if (callback != null) {
                writer.write(")");
View Full Code Here

                 * If the process is done, write back the cell's data so that the
                 * client side can update its UI right away.
                 */
                JSONWriter writer = new JSONWriter(response.getWriter());

                Pool pool = new Pool();
                Properties options = new Properties();
                options.put("pool", pool);

                writer.object();
                writer.key("code"); writer.value("ok");
                writer.key("historyEntry"); historyEntry.write(writer, options);
                writer.key("cell"); process.newCell.write(writer, options);
                writer.key("pool"); pool.write(writer, options);
                writer.endObject();
            } else {
                respond(response, "{ \"code\" : \"pending\" }");
            }
        } catch (Exception e) {
View Full Code Here

                 * If the process is done, write back the cell's data so that the
                 * client side can update its UI right away.
                 */
                JSONWriter writer = new JSONWriter(response.getWriter());

                Pool pool = new Pool();
                Properties options = new Properties();
                options.put("pool", pool);

                writer.object();
                writer.key("code"); writer.value("ok");
                writer.key("historyEntry"); historyEntry.write(writer, options);
                writer.key("cell"); process.newCell.write(writer, options);
                writer.key("pool"); pool.write(writer, options);
                writer.endObject();
            } else {
                respond(response, "{ \"code\" : \"pending\" }");
            }
        } catch (Exception e) {
View Full Code Here

       
        if (recon != null) {
            writer.key("r");
            writer.value(Long.toString(recon.id));
           
            Pool pool = (Pool) options.get("pool");
            pool.pool(recon);
        }
        writer.endObject();
    }
View Full Code Here

                 * If the operation has been done, return the new cell's data
                 * so the client side can update the cell's rendering right away.
                 */
                JSONWriter writer = new JSONWriter(response.getWriter());

                Pool pool = new Pool();
                Properties options = new Properties();
                options.put("pool", pool);

                writer.object();
                writer.key("code"); writer.value("ok");
                writer.key("historyEntry"); historyEntry.write(writer, options);
                writer.key("cell"); process.newCell.write(writer, options);
                writer.key("pool"); pool.write(writer, options);
                writer.endObject();
            } else {
                respond(response, "{ \"code\" : \"pending\" }");
            }
        } catch (Exception e) {
View Full Code Here

    }
   
    protected void writeRecons(Writer writer, Properties options, Map<Long, Recon> recons, String key) throws IOException {
        writer.write(key + "="); writer.write(Integer.toString(recons.size())); writer.write('\n');
        for (Recon recon : recons.values()) {
            Pool pool = (Pool) options.get("pool");
            pool.poolReconCandidates(recon);

            JSONWriter jsonWriter = new JSONWriter(writer);
            try {
                recon.write(jsonWriter, options);
            } catch (JSONException e) {
View Full Code Here

    }

    protected void loadChange(HistoryEntry historyEntry, File file) throws Exception {
        ZipFile zipFile = new ZipFile(file);
        try {
            Pool pool = new Pool();
            ZipEntry poolEntry = zipFile.getEntry("pool.txt");
            if (poolEntry != null) {
                pool.load(new InputStreamReader(
                    zipFile.getInputStream(poolEntry)));
            } // else, it's a legacy project file

            historyEntry.setChange(History.readOneChange(
                    zipFile.getInputStream(zipFile.getEntry("change.txt")), pool));
View Full Code Here

    }

    protected void saveChange(HistoryEntry historyEntry, File file) throws Exception {
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
        try {
            Pool pool = new Pool();

            out.putNextEntry(new ZipEntry("change.txt"));
            try {
                History.writeOneChange(out, historyEntry.getChange(), pool);
            } finally {
                out.closeEntry();
            }

            out.putNextEntry(new ZipEntry("pool.txt"));
            try {
                pool.save(out);
            } finally {
                out.closeEntry();
            }
        } finally {
            out.close();
View Full Code Here

TOP

Related Classes of com.google.refine.util.Pool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.