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:de.fau.cs.osr.hddiff.utils.HDDiffTreeVisualizer.java

private void callDot(File inFile) {
    try {//from ww  w. j  a va 2s.co  m
        String outFname = inFile.getName();
        if (outFname.toLowerCase().endsWith(".dot"))
            outFname = outFname.substring(0, outFname.length() - 4);
        outFname += ".png";
        File outFile = new File(inFile.getParentFile(), outFname);

        String[] cmd = new String[] { bin.getPath(), "-Tpng", "-o", outFile.getPath(), inFile.getPath() };

        Runtime rt = Runtime.getRuntime();
        Process pr = rt.exec(cmd);

        int size = 0;
        int maxSize = 2 << 16;
        StringWriter sw = new StringWriter();
        BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

        String line = null;
        while ((line = input.readLine()) != null) {
            size += line.length() + 1;
            if (size < maxSize) {
                sw.append(line);
                sw.append("\n");
            }
        }

        int exitVal = pr.waitFor();
        if (exitVal != 0) {
            System.err.println("Command failed:");
            System.err.println(Arrays.toString(cmd));
            System.err.println("Command output:");
            String cmdOutput = sw.toString();
            System.err.println(cmdOutput);
            if (size != cmdOutput.length())
                System.err.println("WARNING: Command output exceeded buffer size!");
        }
    } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
}

From source file:com.rdsic.pcm.service.pe.ProcessFunction.java

public String prepareInput(String jsonStr) throws PCMException {
    if (Util.isNullOrEmpty(jsonStr)) {
        throw new PCMException("Invalid json data input", Constant.STATUS_CODE.ERR_SYSTEM_FAIL);
    }/*from w  w w  .j a  va 2  s.  c  o m*/
    JSONObject jsonObj = new JSONObject(jsonStr);

    List<Oprtag> tags = GenericHql.INSTANCE.query("from Oprtag where oprcode=:function order by seq ",
            new Object[] { "function", this.function });
    StringWriter sw = new StringWriter();
    for (int i = 0; i < tags.size(); i++) {
        Oprtag tag = (Oprtag) tags.get(i);
        String tagName = tag.getId().getTag();
        if ((tag.getRequired()) && (!jsonObj.has(tagName))) {
            throw new PCMException("Tag name is required: " + tagName, Constant.STATUS_CODE.ERR_DATA_REQUIRED);
        }
        String tagVal = jsonObj.optString(tagName, tag.getDefval());
        sw.append(tag.getId().getTag().toUpperCase()).append("=").append(tagVal);
        if (i < tags.size() - 1) {
            sw.append(Constant.GLOBAL.PCM_DATA_DELIMITER);
        }
    }
    return sw.toString();
}

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

public static void toExpressionStringIncludeParen(List<ExprNode> parameters, StringWriter buffer) {
    buffer.append("(");
    toExpressionStringParameterList(parameters, buffer);
    buffer.append(")");
}

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

public static void toExpressionStringWFunctionName(String functionName, ExprNode[] childNodes,
        StringWriter writer) {
    writer.append(functionName);
    writer.append("(");
    toExpressionStringParameterList(childNodes, writer);
    writer.append(')');
}

From source file:de.jwi.jfm.FileWrapper.java

public String getAttributes() throws IOException {
    FileSystem fileSystem = FileSystems.getDefault();
    Set<String> fileSystemViews = fileSystem.supportedFileAttributeViews();

    File file = getFile();//from  w  w w. j  ava  2s .com
    Path p = file.toPath();

    try {
        if (fileSystemViews.contains("posix")) {
            Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(p,
                    LinkOption.NOFOLLOW_LINKS);

            PosixFileAttributes attrs = Files.getFileAttributeView(p, PosixFileAttributeView.class)
                    .readAttributes();

            String owner = attrs.owner().toString();
            String group = attrs.group().toString();

            String permissions = PosixFilePermissions.toString(attrs.permissions());

            String res = String.format("%s %s %s", permissions, owner, group);
            return res;
        } else if (fileSystemViews.contains("dos")) {
            StringWriter sw = new StringWriter();
            DosFileAttributeView attributeView = Files.getFileAttributeView(p, DosFileAttributeView.class);
            DosFileAttributes dosFileAttributes = null;

            dosFileAttributes = attributeView.readAttributes();
            if (dosFileAttributes.isArchive()) {
                sw.append('A');
            }
            if (dosFileAttributes.isHidden()) {
                sw.append('H');
            }
            if (dosFileAttributes.isReadOnly()) {
                sw.append('R');
            }
            if (dosFileAttributes.isSystem()) {
                sw.append('S');
            }

            return sw.toString();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "";
}

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

public static List<EPLModuleParseItem> parse(String module) {

    CharStream input;// w  w  w .j av  a2 s .  c o  m
    try {
        input = new NoCaseSensitiveStream(new StringReader(module));
    } catch (IOException ex) {
        log.error("Exception reading model expression: " + ex.getMessage(), ex);
        return null;
    }

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

    List<EPLModuleParseItem> statements = new ArrayList<EPLModuleParseItem>();
    StringWriter current = new StringWriter();
    Integer lineNum = null;
    int charPosStart = 0;
    int charPos = 0;
    List<Token> tokenList = tokens.getTokens();
    Set<Integer> skippedSemicolonIndexes = getSkippedSemicolons(tokenList);
    int index = -1;
    for (Object token : tokenList) // Call getTokens first before invoking tokens.size! ANTLR problem
    {
        index++;
        Token t = (Token) token;
        boolean semi = t.getType() == EsperEPL2GrammarParser.SEMI && !skippedSemicolonIndexes.contains(index);
        if (semi) {
            if (current.toString().trim().length() > 0) {
                statements.add(new EPLModuleParseItem(current.toString().trim(), lineNum == null ? 0 : lineNum,
                        charPosStart, charPos));
                lineNum = null;
            }
            current = new StringWriter();
        } else {
            if ((lineNum == null) && (t.getType() != EsperEPL2GrammarParser.WS)) {
                lineNum = t.getLine();
                charPosStart = charPos;
            }
            current.append(t.getText());
            charPos += t.getText().length();
        }
    }

    if (current.toString().trim().length() > 0) {
        statements.add(new EPLModuleParseItem(current.toString().trim(), lineNum == null ? 0 : lineNum, 0, 0));
    }
    return statements;
}

From source file:org.eclipse.packagedrone.utils.deb.build.DebianPackageWriter.java

protected ContentProvider createChecksumContent() throws IOException {
    if (this.checkSums.isEmpty()) {
        return ContentProvider.NULL_CONTENT;
    }//from   w ww  .  j av a2 s  .  c  o m

    final StringWriter sw = new StringWriter();

    for (final Map.Entry<String, String> entry : this.checkSums.entrySet()) {
        final String filename = entry.getKey().substring(2); // without the leading dot and slash

        sw.append(entry.getValue());
        sw.append("  ");
        sw.append(filename);
        sw.append('\n');
    }

    sw.close();

    return new StaticContentProvider(sw.toString());
}

From source file:com.bigdata.rdf.sail.webapp.AbstractTestNanoSparqlClient.java

protected static String getResponseBody(final HttpURLConnection conn) throws IOException {

    final Reader r = new InputStreamReader(conn.getInputStream());

    try {/*from   ww w . jav a2 s .  com*/

        final StringWriter w = new StringWriter();

        int ch;
        while ((ch = r.read()) != -1) {

            w.append((char) ch);

        }

        return w.toString();

    } finally {

        r.close();

    }

}

From source file:org.qi4j.entitystore.sql.SQLEntityStoreMixin.java

public StateCommitter applyChanges(final EntityStoreUnitOfWork unitofwork, final Iterable<EntityState> states) {
    return new StateCommitter() {

        public void commit() {
            Connection connection = null;
            PreparedStatement insertPS = null;
            PreparedStatement updatePS = null;
            PreparedStatement removePS = null;
            try {
                connection = database.getConnection();
                insertPS = database.prepareInsertEntityStatement(connection);
                updatePS = database.prepareUpdateEntityStatement(connection);
                removePS = database.prepareRemoveEntityStatement(connection);
                for (EntityState state : states) {
                    EntityStatus status = state.status();
                    DefaultEntityState defState = ((SQLEntityState) state).getDefaultEntityState();
                    Long entityPK = ((SQLEntityState) state).getEntityPK();
                    if (EntityStatus.REMOVED.equals(status)) {
                        database.populateRemoveEntityStatement(removePS, entityPK, state.identity());
                        removePS.addBatch();
                    } else {
                        StringWriter writer = new StringWriter();
                        writeEntityState(defState, writer, unitofwork.identity());
                        writer.flush();//w ww.j  a v  a  2s .  co  m
                        if (EntityStatus.UPDATED.equals(status)) {
                            Long entityOptimisticLock = ((SQLEntityState) state).getEntityOptimisticLock();
                            database.populateUpdateEntityStatement(updatePS, entityPK, entityOptimisticLock,
                                    defState.identity(), writer.toString(), unitofwork.currentTime());
                            updatePS.addBatch();
                        } else if (EntityStatus.NEW.equals(status)) {
                            database.populateInsertEntityStatement(insertPS, entityPK, defState.identity(),
                                    writer.toString(), unitofwork.currentTime());
                            insertPS.addBatch();
                        }
                    }
                }

                removePS.executeBatch();
                insertPS.executeBatch();
                updatePS.executeBatch();

                connection.commit();

            } catch (SQLException sqle) {
                SQLUtil.rollbackQuietly(connection);
                if (LOGGER.isDebugEnabled()) {
                    StringWriter sb = new StringWriter();
                    sb.append(
                            "SQLException during commit, logging nested exceptions before throwing EntityStoreException:\n");
                    SQLException e = sqle;
                    while (e != null) {
                        e.printStackTrace(new PrintWriter(sb, true));
                        e = e.getNextException();
                    }
                    LOGGER.debug(sb.toString());
                }
                throw new EntityStoreException(sqle);
            } catch (RuntimeException re) {
                SQLUtil.rollbackQuietly(connection);
                throw new EntityStoreException(re);
            } finally {
                SQLUtil.closeQuietly(insertPS);
                SQLUtil.closeQuietly(updatePS);
                SQLUtil.closeQuietly(removePS);
                SQLUtil.closeQuietly(connection);
            }
        }

        public void cancel() {
        }

    };
}

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

public static void toExpressionStringParams(StringWriter writer, ExprNode[] params) {
    writer.append('(');
    String delimiter = "";
    for (ExprNode childNode : params) {
        writer.append(delimiter);/*from w  w w  .  j  a va2 s  .c o m*/
        delimiter = ",";
        writer.append(ExprNodeUtility.toExpressionStringMinPrecedenceSafe(childNode));
    }
    writer.append(')');
}