Example usage for java.io StringWriter append

List of usage examples for java.io StringWriter append

Introduction

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

Prototype

public StringWriter append(char c) 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:com.espertech.esper.core.deploy.EPLModuleUtil.java

public static ParseNode getModule(EPLModuleParseItem item, String resourceName)
        throws ParseException, IOException {
    CharStream input = new NoCaseSensitiveStream(new StringReader(item.getExpression()));

    EsperEPL2GrammarLexer lex = new EsperEPL2GrammarLexer(input);
    CommonTokenStream tokenStream = new CommonTokenStream(lex);

    List tokens = tokenStream.getTokens();
    int beginIndex = 0;
    boolean isMeta = false;
    boolean isModule = false;
    boolean isUses = false;
    boolean isExpression = false;

    while (beginIndex < tokens.size()) {
        Token t = (Token) tokens.get(beginIndex);
        if ((t.getType() == EsperEPL2GrammarParser.WS) || (t.getType() == EsperEPL2GrammarParser.SL_COMMENT)
                || (t.getType() == EsperEPL2GrammarParser.ML_COMMENT)) {
            beginIndex++;//from  w  w  w.  j  a va 2s. c om
            continue;
        }
        String tokenText = t.getText().trim().toLowerCase();
        if (tokenText.equals("module")) {
            isModule = true;
            isMeta = true;
        } else if (tokenText.equals("uses")) {
            isUses = true;
            isMeta = true;
        } else if (tokenText.equals("import")) {
            isMeta = true;
        } else {
            isExpression = true;
            break;
        }
        beginIndex++;
        beginIndex++; // skip space
        break;
    }

    if (isExpression) {
        return new ParseNodeExpression(item);
    }
    if (!isMeta) {
        return new ParseNodeComment(item);
    }

    // check meta tag (module, uses, import)
    StringWriter buffer = new StringWriter();
    for (int i = beginIndex; i < tokens.size(); i++) {
        Token t = (Token) tokens.get(i);
        if ((t.getType() != EsperEPL2GrammarParser.IDENT) && (t.getType() != EsperEPL2GrammarParser.DOT)
                && (t.getType() != EsperEPL2GrammarParser.STAR) && (!t.getText().matches("[a-zA-Z]*"))) {
            throw getMessage(isModule, isUses, resourceName, t.getType());
        }
        buffer.append(t.getText().trim());
    }

    String result = buffer.toString().trim();
    if (result.length() == 0) {
        throw getMessage(isModule, isUses, resourceName, -1);
    }

    if (isModule) {
        return new ParseNodeModule(item, result);
    } else if (isUses) {
        return new ParseNodeUses(item, result);
    }
    return new ParseNodeImport(item, result);
}

From source file:it.geosolutions.geocollect.android.core.mission.utils.MissionUtils.java

/**
 * get "created" {@link MissionFeature} from the database, adding the distance property if possible
 * @param tableName//www. j  av a2  s. c  om
 * @param db
 * @return a list of created {@link MissionFeature}
 */
public static ArrayList<MissionFeature> getMissionFeatures(final String mTableName, final Database db,
        Context ctx) {

    ArrayList<MissionFeature> mFeaturesList = new ArrayList<MissionFeature>();

    String tableName = mTableName;

    // Reader for the Geometry field
    WKBReader wkbReader = new WKBReader();

    //create query
    ////////////////////////////////////////////////////////////////
    // SQLite Geometry cannot be read with direct wkbreader
    // We must do a double conversion with ST_AsBinary and CastToXY 
    ////////////////////////////////////////////////////////////////

    // Cycle all the columns to find the "Point" type one
    HashMap<String, String> columns = SpatialiteUtils.getPropertiesFields(db, tableName);
    if (columns == null) {
        if (BuildConfig.DEBUG) {
            Log.w(TAG, "Cannot retrieve columns from database");
        }
        return mFeaturesList;
    }

    List<String> selectFields = new ArrayList<String>();
    for (String columnName : columns.keySet()) {
        //Spatialite custom field point
        if ("point".equalsIgnoreCase(columns.get(columnName))) {
            selectFields.add("ST_AsBinary(CastToXY(" + columnName + ")) AS GEOMETRY");
        } else {
            selectFields.add(columnName);
        }
    }

    // Merge all the column names
    String selectString = TextUtils.join(",", selectFields);

    if (ctx != null) {

        SharedPreferences prefs = ctx.getSharedPreferences(SQLiteCascadeFeatureLoader.PREF_NAME,
                Context.MODE_PRIVATE);

        boolean useDistance = prefs.getBoolean(SQLiteCascadeFeatureLoader.ORDER_BY_DISTANCE, false);
        double posX = Double.longBitsToDouble(
                prefs.getLong(SQLiteCascadeFeatureLoader.LOCATION_X, Double.doubleToLongBits(0)));
        double posY = Double.longBitsToDouble(
                prefs.getLong(SQLiteCascadeFeatureLoader.LOCATION_Y, Double.doubleToLongBits(0)));

        if (useDistance) {
            selectString = selectString + ", Distance(ST_Transform(GEOMETRY,4326), MakePoint(" + posX + ","
                    + posY + ", 4326)) * 111195 AS '" + MissionFeature.DISTANCE_VALUE_ALIAS + "'";
        }

        //Add Spatial filtering
        int filterSrid = prefs.getInt(SQLiteCascadeFeatureLoader.FILTER_SRID, -1);
        // If the SRID is not defined, skip the filter
        if (filterSrid != -1) {
            double filterN = Double.longBitsToDouble(
                    prefs.getLong(SQLiteCascadeFeatureLoader.FILTER_N, Double.doubleToLongBits(0)));
            double filterS = Double.longBitsToDouble(
                    prefs.getLong(SQLiteCascadeFeatureLoader.FILTER_S, Double.doubleToLongBits(0)));
            double filterW = Double.longBitsToDouble(
                    prefs.getLong(SQLiteCascadeFeatureLoader.FILTER_W, Double.doubleToLongBits(0)));
            double filterE = Double.longBitsToDouble(
                    prefs.getLong(SQLiteCascadeFeatureLoader.FILTER_E, Double.doubleToLongBits(0)));

            tableName += " WHERE MbrIntersects(GEOMETRY, BuildMbr(" + filterW + ", " + filterN + ", " + filterE
                    + ", " + filterS + ")) ";
        }

    }

    // Build the query
    StringWriter queryWriter = new StringWriter();
    queryWriter.append("SELECT ").append(selectString).append(" FROM ").append(tableName).append(";");

    // The resulting query
    String query = queryWriter.toString();

    Stmt stmt;
    //do the query
    if (jsqlite.Database.complete(query)) {
        try {
            if (BuildConfig.DEBUG) {
                Log.i("getCreatedMissionFeatures", "Loading from query: " + query);
            }
            stmt = db.prepare(query);
            MissionFeature f;
            while (stmt.step()) {
                f = new MissionFeature();

                SpatialiteUtils.populateFeatureFromStmt(wkbReader, stmt, f);

                if (f.geometry == null) {
                    //workaround for a bug which does not read out the "Point" geometry in WKBreader
                    //read single x and y coordinates instead and create the geometry by hand
                    double[] xy = PersistenceUtils.getXYCoord(db, tableName, f.id);
                    if (xy != null) {
                        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
                        f.geometry = geometryFactory.createPoint(new Coordinate(xy[0], xy[1]));
                    }
                }
                f.typeName = mTableName;
                mFeaturesList.add(f);
            }
            stmt.close();
        } catch (Exception e) {
            Log.d(TAG, "Error getCreatedMissions", e);
        }
    } else {
        if (BuildConfig.DEBUG) {
            Log.w(TAG, "Query is not complete: " + query);
        }
    }

    return mFeaturesList;
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java

private static void marshallToFile(Collection<Package> installPackages, String filePath) {
    try {//ww w. j a v  a  2s.  c  om
        Marshaller marshaller = jaxbContext.createMarshaller();

        // removes the xml header:
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        StringWriter stringWriter = new StringWriter();
        for (Package installPackage : installPackages) {
            marshaller.marshal(
                    new JAXBElement<Package>(new QName(null, "installPackage"), Package.class, installPackage),
                    stringWriter);

            stringWriter.append("\n");
        }

        FileUtils.writeStringToFile(new File(filePath), stringWriter.toString(), "UTF-8");
    } catch (Exception e) {
        logger.error("", e);
        //            e.printStackTrace();
    }
}

From source file:org.apache.clerezza.utils.UriUtil.java

/**
 * Get the all escaped and encoded string with a given charset.
 * If the specified string contains already escaped characters, then
 * the '%' will not be escaped.//from   w  w  w . j a  v  a 2 s .c o  m
 *
 * @param partlyEscaped a string that may containg already escaped chararcters
 * @param charset the charset
 * @return the escaped string
 *
 * @throws URIException if the charset is not supported
 *
 * @see #encode
 */
public static String encodePartlyEncodedPath(String partlyEscaped, String charset) throws UriException {
    StringWriter sw = new StringWriter();
    for (int i = 0; i < partlyEscaped.length(); i++) {
        char c = partlyEscaped.charAt(i);
        if (c == '%') {
            try {
                String hexString = partlyEscaped.substring(i + 1, i + 3);
                Integer.parseInt(hexString, 16);
                sw.append(c);
                sw.append(hexString);
                i += 2;
                continue;
            } catch (NumberFormatException ex) { //encode it
            }
        }
        sw.append(UriUtil.encodePath(String.valueOf(c), charset));
    }
    return sw.toString();
}

From source file:com.github.thesmartenergy.mdq.entities.Vocabulary.java

@Override
public String asTurtle() {
    StringWriter sw = new StringWriter();
    sw.append(ontology.asTurtle());
    model.write(sw, "TTL");
    return sw.toString();
}

From source file:com.espertech.esper.epl.expression.core.ExprNumberSetFrequency.java

public void toPrecedenceFreeEPL(StringWriter writer) {
    writer.append("*/");
    this.getChildNodes()[0].toEPL(writer, ExprPrecedenceEnum.MINIMUM);
}

From source file:org.schedulesdirect.api.exception.InvalidJsonObjectException.java

private String generateMsg() {
    StringWriter sw = new StringWriter();
    sw.append(String.format("*** S T A C K  T R A C E ***%n"));
    try (PrintWriter pw = new PrintWriter(sw)) {
        printStackTrace(pw);//from  w  ww.ja va  2s .  co m
    }
    sw.append(String.format("%n*** I N P U T ***%n%s", src));
    return sw.toString();
}

From source file:com.espertech.esper.epl.expression.core.ExprNumberSetList.java

public void toPrecedenceFreeEPL(StringWriter writer) {
    String delimiter = "";

    writer.append('[');
    Iterator<ExprNode> it = Arrays.asList(this.getChildNodes()).iterator();
    do {// ww  w .  j  a  v a2s .  co m
        ExprNode expr = it.next();
        writer.append(delimiter);
        expr.toEPL(writer, ExprPrecedenceEnum.MINIMUM);
        delimiter = ",";
    } while (it.hasNext());
    writer.append(']');
}

From source file:com.controlj.addon.weather.noaa.WeatherServiceUIImpl.java

public String getServiceConfigHTML() {
    StringWriter result = new StringWriter();
    result.append(super.getServiceConfigHTML());
    copyHTMLTemplate(WeatherServiceUIImpl.class, "serviceconfig.html", result);
    return result.getBuffer().toString();
}

From source file:com.example.switchyard.sap.Transformers.java

@Transformer
public Node throwableToNode(Throwable t) {
    StringWriter sw = new StringWriter();
    sw.append("<error>").append(System.getProperty("line.separator"));
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);/*  ww  w  .j av  a  2  s  .  co m*/
    sw.append(System.getProperty("line.separator")).append("</error>");
    return toElement(sw.toString());
}