Example usage for java.io PrintStream append

List of usage examples for java.io PrintStream append

Introduction

In this page you can find the example usage for java.io PrintStream append.

Prototype

public PrintStream append(char c) 

Source Link

Document

Appends the specified character to this output stream.

Usage

From source file:org.apache.cassandra.cli.CliClient.java

/**
 * Creates a CLI script for the CfDef including meta data to the supplied StringBuilder.
 *
 * @param output File to write to.//from ww w .ja v  a  2s.  co  m
 * @param cfDef  CfDef to export attributes from.
 */
private void showColumnFamily(PrintStream output, CfDef cfDef) {
    output.append("create column family ").append(CliUtils.maybeEscapeName(cfDef.name));

    writeAttr(output, true, "column_type", cfDef.column_type);
    writeAttr(output, false, "comparator",
            normaliseType(cfDef.comparator_type, "org.apache.cassandra.db.marshal"));
    if (cfDef.column_type.equals("Super"))
        writeAttr(output, false, "subcomparator",
                normaliseType(cfDef.subcomparator_type, "org.apache.cassandra.db.marshal"));
    if (!StringUtils.isEmpty(cfDef.default_validation_class))
        writeAttr(output, false, "default_validation_class",
                normaliseType(cfDef.default_validation_class, "org.apache.cassandra.db.marshal"));
    writeAttr(output, false, "key_validation_class",
            normaliseType(cfDef.key_validation_class, "org.apache.cassandra.db.marshal"));

    writeAttr(output, false, "read_repair_chance", cfDef.read_repair_chance);
    writeAttr(output, false, "dclocal_read_repair_chance", cfDef.dclocal_read_repair_chance);
    writeAttr(output, false, "populate_io_cache_on_flush", cfDef.populate_io_cache_on_flush);
    writeAttr(output, false, "gc_grace", cfDef.gc_grace_seconds);
    writeAttr(output, false, "min_compaction_threshold", cfDef.min_compaction_threshold);
    writeAttr(output, false, "max_compaction_threshold", cfDef.max_compaction_threshold);
    writeAttr(output, false, "replicate_on_write", cfDef.replicate_on_write);
    writeAttr(output, false, "compaction_strategy", cfDef.compaction_strategy);
    writeAttr(output, false, "caching", cfDef.caching);
    writeAttr(output, false, "default_time_to_live", cfDef.default_time_to_live);
    writeAttr(output, false, "speculative_retry", cfDef.speculative_retry);

    if (cfDef.isSetBloom_filter_fp_chance())
        writeAttr(output, false, "bloom_filter_fp_chance", cfDef.bloom_filter_fp_chance);
    if (!cfDef.compaction_strategy_options.isEmpty()) {
        StringBuilder cOptions = new StringBuilder();

        cOptions.append("{");

        Map<String, String> options = cfDef.compaction_strategy_options;

        int i = 0, size = options.size();

        for (Map.Entry<String, String> entry : options.entrySet()) {
            cOptions.append(CliUtils.quote(entry.getKey())).append(" : ")
                    .append(CliUtils.quote(entry.getValue()));

            if (i != size - 1)
                cOptions.append(", ");

            i++;
        }

        cOptions.append("}");

        writeAttrRaw(output, false, "compaction_strategy_options", cOptions.toString());
    }

    if (!StringUtils.isEmpty(cfDef.comment))
        writeAttr(output, false, "comment", cfDef.comment);

    if (!cfDef.column_metadata.isEmpty()) {
        output.append(NEWLINE).append(TAB).append("and column_metadata = [");

        boolean first = true;
        for (ColumnDef colDef : cfDef.column_metadata) {
            if (!first)
                output.append(",");
            first = false;
            showColumnMeta(output, cfDef, colDef);
        }

        output.append("]");
    }

    if (cfDef.compression_options != null && !cfDef.compression_options.isEmpty()) {
        StringBuilder compOptions = new StringBuilder();

        compOptions.append("{");

        int i = 0, size = cfDef.compression_options.size();

        for (Map.Entry<String, String> entry : cfDef.compression_options.entrySet()) {
            compOptions.append(CliUtils.quote(entry.getKey())).append(" : ")
                    .append(CliUtils.quote(entry.getValue()));

            if (i != size - 1)
                compOptions.append(", ");

            i++;
        }

        compOptions.append("}");

        writeAttrRaw(output, false, "compression_options", compOptions.toString());
    }
    if (cfDef.isSetIndex_interval())
        writeAttr(output, false, "index_interval", cfDef.index_interval);

    output.append(";");
    output.append(NEWLINE);
    output.append(NEWLINE);
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

/**
 * Creates a CLI script for the CfDef including meta data to the supplied StringBuilder.
 *
 * @param output File to write to.//from   w w  w . j  a  v a  2s.  co  m
 * @param cfDef  CfDef to export attributes from.
 */
private void showColumnFamily(PrintStream output, CfDef cfDef) {
    output.append("create column family ").append(CliUtils.maybeEscapeName(cfDef.name));

    writeAttr(output, true, "column_type", cfDef.column_type);
    writeAttr(output, false, "comparator",
            normaliseType(cfDef.comparator_type, "org.apache.cassandra.db.marshal"));
    if (cfDef.column_type.equals("Super"))
        writeAttr(output, false, "subcomparator",
                normaliseType(cfDef.subcomparator_type, "org.apache.cassandra.db.marshal"));
    if (!StringUtils.isEmpty(cfDef.default_validation_class))
        writeAttr(output, false, "default_validation_class",
                normaliseType(cfDef.default_validation_class, "org.apache.cassandra.db.marshal"));
    writeAttr(output, false, "key_validation_class",
            normaliseType(cfDef.key_validation_class, "org.apache.cassandra.db.marshal"));

    writeAttr(output, false, "read_repair_chance", cfDef.read_repair_chance);
    writeAttr(output, false, "dclocal_read_repair_chance", cfDef.dclocal_read_repair_chance);
    writeAttr(output, false, "populate_io_cache_on_flush", cfDef.populate_io_cache_on_flush);
    writeAttr(output, false, "gc_grace", cfDef.gc_grace_seconds);
    writeAttr(output, false, "min_compaction_threshold", cfDef.min_compaction_threshold);
    writeAttr(output, false, "max_compaction_threshold", cfDef.max_compaction_threshold);
    writeAttr(output, false, "replicate_on_write", cfDef.replicate_on_write);
    writeAttr(output, false, "compaction_strategy", cfDef.compaction_strategy);
    writeAttr(output, false, "caching", cfDef.caching);

    if (cfDef.isSetBloom_filter_fp_chance())
        writeAttr(output, false, "bloom_filter_fp_chance", cfDef.bloom_filter_fp_chance);

    if (!cfDef.compaction_strategy_options.isEmpty()) {
        StringBuilder cOptions = new StringBuilder();

        cOptions.append("{");

        Map<String, String> options = cfDef.compaction_strategy_options;

        int i = 0, size = options.size();

        for (Map.Entry<String, String> entry : options.entrySet()) {
            cOptions.append(CliUtils.quote(entry.getKey())).append(" : ")
                    .append(CliUtils.quote(entry.getValue()));

            if (i != size - 1)
                cOptions.append(", ");

            i++;
        }

        cOptions.append("}");

        writeAttrRaw(output, false, "compaction_strategy_options", cOptions.toString());
    }

    if (!StringUtils.isEmpty(cfDef.comment))
        writeAttr(output, false, "comment", cfDef.comment);

    if (!cfDef.column_metadata.isEmpty()) {
        output.append(NEWLINE).append(TAB).append("and column_metadata = [");

        boolean first = true;
        for (ColumnDef colDef : cfDef.column_metadata) {
            if (!first)
                output.append(",");
            first = false;
            showColumnMeta(output, cfDef, colDef);
        }

        output.append("]");
    }

    if (cfDef.compression_options != null && !cfDef.compression_options.isEmpty()) {
        StringBuilder compOptions = new StringBuilder();

        compOptions.append("{");

        int i = 0, size = cfDef.compression_options.size();

        for (Map.Entry<String, String> entry : cfDef.compression_options.entrySet()) {
            compOptions.append(CliUtils.quote(entry.getKey())).append(" : ")
                    .append(CliUtils.quote(entry.getValue()));

            if (i != size - 1)
                compOptions.append(", ");

            i++;
        }

        compOptions.append("}");

        writeAttrRaw(output, false, "compression_options", compOptions.toString());
    }

    output.append(";");
    output.append(NEWLINE);
    output.append(NEWLINE);
}

From source file:org.kalypso.gml.processes.constDelaunay.TriangleExe.java

public GM_Triangle[] triangulate(final GM_Polygon[] boundaries, final GM_Curve[] breaklines,
        final boolean exportZ) {
    final File triangleExe = ConstraintDelaunayHelper.findTriangleExe();
    if (triangleExe == null || !triangleExe.isFile())
        throw new IllegalStateException("triangle.exe not found"); //$NON-NLS-1$

    // FIXME: put into separate class!
    BufferedReader nodeReader = null;
    BufferedReader eleReader = null;
    PrintStream pwSimuLog;

    /* prepare */
    final List<TriangleVertex> nodeList = new ArrayList<>();
    final List<TriangleSegment> segmentList = new ArrayList<>();
    final List<TriangleHole> holeList = new ArrayList<>();

    int i = 0;//from w  w w.  j  a  v  a  2 s .c o  m

    final String crs = boundaries[0].getCoordinateSystem();
    final IGeoTransformer geoTransformer = GeoTransformerFactory.getGeoTransformer(crs);
    for (final GM_Polygon boundary : boundaries) {

        final GM_PolygonPatch surfacePatch = boundary.getSurfacePatch();
        {
            // handle the exterior
            int k = i;
            final GM_Position[] exterior = surfacePatch.getExteriorRing();
            for (; i - k < exterior.length - 2; i++) {
                final GM_Position position = exterior[i - k];
                final TriangleVertex vertex = createVertex(exportZ, position);
                nodeList.add(vertex);
                final TriangleSegment segment = new TriangleSegment(i, i + 1, 1);
                segmentList.add(segment);
            }
            final GM_Position position = exterior[i - k];
            final TriangleVertex vertex = createVertex(exportZ, position);
            nodeList.add(vertex);
            final TriangleSegment segment = new TriangleSegment(i, k, 1);
            segmentList.add(segment);
            i++;
        }

        final GM_Position[][] interiorRings = surfacePatch.getInteriorRings();
        if (interiorRings != null) {
            for (final GM_Position[] ring : interiorRings) {
                // handle the hole
                int j = i;
                for (; i - j < ring.length - 2; i++) {
                    final GM_Position position = ring[i - j];
                    final TriangleVertex vertex = createVertex(exportZ, position);
                    nodeList.add(vertex);
                    final TriangleSegment segment = new TriangleSegment(i, i + 1, 1);
                    segmentList.add(segment);
                }
                final GM_Position position = ring[i - j];
                final TriangleVertex vertex = createVertex(exportZ, position);
                nodeList.add(vertex);
                final TriangleSegment segment = new TriangleSegment(i, j, 1);
                segmentList.add(segment);

                final Coordinate[] coordinates = JTSAdapter.export(ring);
                final com.vividsolutions.jts.geom.GeometryFactory geometryFactory = new com.vividsolutions.jts.geom.GeometryFactory();
                final Polygon jtsHolePolygon = geometryFactory
                        .createPolygon(geometryFactory.createLinearRing(coordinates), null);
                final Point interiorPointJTS = jtsHolePolygon.getInteriorPoint();
                try {
                    final GM_Point interiorPoint = (GM_Point) JTSAdapter.wrap(interiorPointJTS,
                            surfacePatch.getCoordinateSystem());
                    final TriangleHole hole = new TriangleHole(interiorPoint.getPosition());
                    holeList.add(hole);
                } catch (final GM_Exception e) {
                    e.printStackTrace();
                }
                i++;
            }
        }
    }

    if (!ArrayUtils.isEmpty(breaklines)) {
        // handle the breaklines
        for (final GM_Curve rawCurve : breaklines) {
            try {
                final GM_Curve curve = geoTransformer.transform(rawCurve);
                final GM_LineString lineString = curve.getAsLineString();
                final GM_Position[] positions = lineString.getPositions();
                for (int j = 0; j < positions.length - 1; j++) {
                    final GM_Position position = positions[j];
                    final TriangleVertex vertex = createVertex(exportZ, position);
                    nodeList.add(vertex);
                    final TriangleSegment segment = new TriangleSegment(i, i + 1, 0);
                    segmentList.add(segment);
                    i++;
                }
                final GM_Position position = positions[positions.length - 1];
                final TriangleVertex vertex = createVertex(exportZ, position);
                nodeList.add(vertex);
                i++;
            } catch (final GM_Exception | GeoTransformerException e) {
                e.printStackTrace();
            }
        }
    }

    // collect the data
    final TrianglePolyFileData trianglePolyFileData = new TrianglePolyFileData(nodeList, segmentList, holeList);

    File tempDir = null;
    try {
        pwSimuLog = System.out;

        final String polyFileName = "input.poly"; //$NON-NLS-1$

        final String[] args = Arrays.copyOf(m_triangleArgs, m_triangleArgs.length + 2);
        args[m_triangleArgs.length] = "-p"; //$NON-NLS-1$
        args[m_triangleArgs.length + 1] = polyFileName;
        final IProcess process = KalypsoCommonsExtensions.createProcess(
                IProcessFactory.DEFAULT_PROCESS_FACTORY_ID, "Triangle", triangleExe.getName(), args);//$NON-NLS-1$

        tempDir = new File(new URL(process.getSandboxDirectory()).getFile());
        FileUtils.copyFileToDirectory(triangleExe, tempDir);

        final File polyfile = new File(tempDir, polyFileName);

        // prepare the polygon for output
        final IStatus writeStatus = trianglePolyFileData.writePolyFile(polyfile);

        if (writeStatus != Status.OK_STATUS)
            return null;

        // start Triangle
        process.startProcess(pwSimuLog, System.err, System.in, new ICancelable() {

            @Override
            public boolean isCanceled() {
                return false;
            }

            @Override
            public void cancel() {
            }
        });

        // get the triangle list
        final File nodeFile = new File(tempDir, "input.1.node"); //$NON-NLS-1$
        final File eleFile = new File(tempDir, "input.1.ele"); //$NON-NLS-1$

        if (!nodeFile.exists() || !eleFile.exists()) {
            pwSimuLog.append(
                    Messages.getString("org.kalypso.gml.processes.constDelaunay.ConstraintDelaunayHelper.31")); //$NON-NLS-1$
            pwSimuLog.append(
                    Messages.getString("org.kalypso.gml.processes.constDelaunay.ConstraintDelaunayHelper.32")); //$NON-NLS-1$
            pwSimuLog.append(
                    Messages.getString("org.kalypso.gml.processes.constDelaunay.ConstraintDelaunayHelper.33")); //$NON-NLS-1$
            return null;
        }

        nodeReader = new BufferedReader(new InputStreamReader(new FileInputStream(nodeFile)));
        eleReader = new BufferedReader(new InputStreamReader(new FileInputStream(eleFile)));

        final GM_Position[] points = parseTriangleNodeOutput(nodeReader);

        final List<GM_Triangle> triangles = parseTriangleElementOutput(eleReader, crs, points);
        return triangles.toArray(new GM_Triangle[triangles.size()]);
    } catch (final Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        IOUtils.closeQuietly(nodeReader);
        IOUtils.closeQuietly(eleReader);
        if (tempDir != null && tempDir.exists()) {
            try {
                FileUtils.deleteDirectory(tempDir);
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.lockss.tdb.TdbXml.java

/**
 * <p>/*from   w w w. j  av a2s  . c  om*/
 * Produces output from a parsed TDB into the given print stream.
 * </p>
 * 
 * @param options
 *          The options map.
 * @param out
 *          A print stream.
 * @param tdb
 *          A TDB structure.
 * @since 1.67
 */
public void produceOutput(Map<String, Object> options, PrintStream out, Tdb tdb) {
    Predicate<Au> auPredicate = tdbQueryBuilder.getAuPredicate(options);

    preamble(options, out);

    Publisher currentPub = null;
    String escapedPublisherName = null;
    String escapedPublisherNameNoDots = null;
    Title currentTitle = null;
    String escapedTitleName = null;
    String titleIssn = null;
    String titleEissn = null;
    String titleIssnl = null;
    String titleDoi = null;
    String titleType = null;
    for (Au au : tdb.getAus()) {
        /*
         * Maybe skip this AU
         */
        if (!auPredicate.test(au)) {
            continue;
        }

        StringBuilder sb = new StringBuilder(4096);

        /*
         * Per-publisher stuff
         */
        Publisher pub = au.getTitle().getPublisher();
        if (pub != currentPub) {
            if (currentPub != null) {
                sb.append(" </property>\n");
                sb.append("\n");
            }
            currentPub = pub;
            escapedPublisherName = xmlEscaper.translate(currentPub.getName());
            escapedPublisherNameNoDots = escapedPublisherName.replace(".", "");
            sb.append(" <property name=\"org.lockss.titleSet\">\n");
            sb.append("\n");
            sb.append("  <property name=\"");
            sb.append(escapedPublisherNameNoDots);
            sb.append("\">\n");
            sb.append("   <property name=\"name\" value=\"All ");
            sb.append(escapedPublisherName);
            sb.append(" AUs\" />\n");
            sb.append("   <property name=\"class\" value=\"xpath\" />\n");
            sb.append("   <property name=\"xpath\" value='[attributes/publisher=\"");
            sb.append(escapedPublisherName);
            sb.append("\"]' />\n");
            sb.append("  </property>\n");
            sb.append("\n");
            sb.append(" </property>\n");
            sb.append("\n");
            sb.append(" <property name=\"org.lockss.title\">\n");
            sb.append("\n");
        }

        /*
         * Per-title stuff
         */
        Title title = au.getTitle();
        if (title != currentTitle) {
            currentTitle = title;
            escapedTitleName = xmlEscaper.translate(currentTitle.getName());
            titleIssn = title.getIssn();
            titleEissn = title.getEissn();
            titleIssnl = title.getIssnl();
            titleDoi = title.getDoi();
            titleType = title.getType();
        }

        /*
         * Per-AU stuff
         */
        // AU name
        String plugin = au.getPlugin();
        String auName = au.getName();
        String escapedAuName = xmlEscaper.translate(auName);
        StringBuilder ausb = new StringBuilder();
        computeAuShortName(ausb, plugin, auName);
        String escapedAuNameShort = xmlEscaper.translate(ausb.toString());
        ausb = null; // in case ausb accidentally gets re-used below instead of sb

        sb.append("  <property name=\"");
        sb.append(escapedAuNameShort);
        sb.append("\">\n");
        appendOneAttr(sb, "publisher", escapedPublisherName);
        sb.append("   <property name=\"journalTitle\" value=\"");
        sb.append(escapedTitleName);
        sb.append("\" />\n");
        if (titleIssn != null) {
            sb.append("   <property name=\"issn\" value=\"");
            sb.append(titleIssn);
            sb.append("\" />\n");
        }
        if (titleEissn != null) {
            sb.append("   <property name=\"eissn\" value=\"");
            sb.append(titleEissn);
            sb.append("\" />\n");
        }
        if (titleIssnl != null) {
            sb.append("   <property name=\"issnl\" value=\"");
            sb.append(titleIssnl);
            sb.append("\" />\n");
        }
        if (titleDoi != null) {
            sb.append("   <property name=\"journalDoi\" value=\"");
            sb.append(titleDoi);
            sb.append("\" />\n");
        }
        if (titleType != null) {
            sb.append("   <property name=\"type\" value=\"");
            sb.append(titleType);
            sb.append("\" />\n");
        }
        sb.append("   <property name=\"title\" value=\"");
        sb.append(escapedAuName);
        sb.append("\" />\n");
        sb.append("   <property name=\"plugin\" value=\"");
        sb.append(plugin);
        sb.append("\" />\n");

        // Definitional parameters
        Map<String, String> params = au.getParams();
        List<String> paramNames = new ArrayList<String>(params.keySet());
        Collections.sort(paramNames, ParamComparator.INSTANCE);
        int paramIndex = 1;
        for (String param : paramNames) {
            String val = params.get(param);
            if (val == null || val.length() == 0) {
                continue;
            }
            appendOneParam(sb, paramIndex, param, val);
            ++paramIndex;
        }
        // Non-definitional parameters
        for (Map.Entry<String, String> ent : au.getNondefParams().entrySet()) {
            appendOneParam(sb, paramIndex, ent.getKey(), ent.getValue());
            ++paramIndex;
        }

        // au_proxy and pub_down
        String proxy = au.getProxy();
        if (proxy != null) {
            appendOneParam(sb, 98, "crawl_proxy", proxy);
        }
        String status = au.getStatus();
        if (options.get(KEY_NO_PUB_DOWN) == Boolean.FALSE && PUB_DOWN_STATUSES.contains(status)) {
            appendOneParam(sb, 99, "pub_down", "true");
        }

        // Attributes
        for (Map.Entry<String, String> ent : au.getAttrs().entrySet()) {
            appendOneAttr(sb, ent.getKey(), ent.getValue());
        }

        // Miscellaneous
        appendOneAttr(sb, "provider", au.getProvider());
        appendOneAttr(sb, "edition", au.getEdition());
        appendOneAttr(sb, "eisbn", au.getEisbn());
        appendOneAttr(sb, "isbn", au.getIsbn());
        appendOneAttr(sb, "year", au.getYear());
        appendOneAttr(sb, "volume", au.getVolume());
        if ("openaccess".equals(au.getRights())) {
            appendOneAttr(sb, "rights", "openaccess");
        }
        if (Au.STATUS_ZAPPED.equals(status)) {
            appendOneAttr(sb, "status", Au.STATUS_ZAPPED);
        }

        // Output
        sb.append("  </property>\n");
        out.println(sb.toString());
    }

    if (currentPub != null) {
        out.append(" </property>\n");
        out.append("\n");
    }

    postamble(options, out);
}