Example usage for java.io StringWriter getBuffer

List of usage examples for java.io StringWriter getBuffer

Introduction

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

Prototype

public StringBuffer getBuffer() 

Source Link

Document

Return the string buffer itself.

Usage

From source file:org.apache.axiom.soap.impl.llom.Checker.java

public static String exceptionToString(Throwable e) {
    java.io.StringWriter sw = new java.io.StringWriter();
    java.io.BufferedWriter bw = new java.io.BufferedWriter(sw);
    java.io.PrintWriter pw = new java.io.PrintWriter(bw);
    e.printStackTrace(pw);// w ww .  j a v a 2s . co m
    pw.close();
    String text = sw.getBuffer().toString();
    return text;
}

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.SecurityTokenServicePortImpl.java

static String toString(Node dom) throws TransformerException {
    Source source = new DOMSource(dom);
    StringWriter stringWriter = new StringWriter();
    Result result = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.transform(source, result);
    return stringWriter.getBuffer().toString();
}

From source file:Main.java

/**
 * /*from   w  ww. ja v a2s .c o m*/
 * <B>Purpose:</B>Converts an XML Document to a String Object
 * 
 * @param node
 * @return
 * @throws TransformerException
 */
public static String xmlToString(Node node) throws TransformerException {
    if (node == null) {
        return "";
    }
    Source source = new DOMSource(node);
    StringWriter stringWriter = new StringWriter();
    Result result = new StreamResult(stringWriter);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    transformer.setOutputProperty("{http://xml.apache.org/xalan}line-separator", "\n");
    transformer.setOutputProperty("omit-xml-declaration", "yes");
    transformer.transform(source, result);
    return stringWriter.getBuffer().toString();
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

public static String toJsonString(HystrixCommandMetrics commandMetrics) {
    StringWriter jsonString = new StringWriter();

    try {//from w ww . j a  v  a 2  s  .c om
        JsonGenerator json = jsonFactory.createGenerator(jsonString);
        writeCommandMetrics(commandMetrics, json);
        json.close();
        return jsonString.getBuffer().toString();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

public static String toJsonString(HystrixCollapserMetrics collapserMetrics) {
    StringWriter jsonString = new StringWriter();

    try {//from www .j  ava2s. c  o m
        JsonGenerator json = jsonFactory.createGenerator(jsonString);
        writeCollapserMetrics(collapserMetrics, json);
        json.close();
        return jsonString.getBuffer().toString();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

public static String toJsonString(HystrixThreadPoolMetrics threadPoolMetrics) {
    StringWriter jsonString = new StringWriter();

    try {//from  w  w w.j  a v a  2 s . c  om
        JsonGenerator json = jsonFactory.createGenerator(jsonString);
        writeThreadPoolMetrics(threadPoolMetrics, json);
        json.close();
        return jsonString.getBuffer().toString();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:eu.sisob.uma.restserver.AuthorizationManager.java

/**
 * /* www . jav  a2s . co  m*/
 * @param user
 * @param pass
 * @param message 
 * @return
 */
public static boolean validateAccess(String user, String pass, StringWriter message) {
    boolean valid = true;

    //getCrawkerTaskStatus(code)
    if (message != null)
        message.getBuffer().setLength(0);

    if (!SystemManager.getInstance().IsRunning()) {
        message.write("The back system is off. Please contact with the administrator."); //FIXME
        valid = false;
        return valid;
    }

    if (user != null && pass != null) {
        if (DBAuthorizeUserIn(user, pass)) {
            String code_task_folder = TASKS_USERS_PATH + File.separator + user;

            File f = new File(code_task_folder);
            if (!f.exists())
                f.mkdir();

            valid = true;
            if (message != null)
                message.write(TheResourceBundle.getString("Jsp Auth Msg")); //FIXME               
        } else {
            valid = false;
            if (message != null)
                message.write(TheResourceBundle.getString("Jsp Unauth Msg")); //FIXME                
        }
    } else {
        valid = false;
        if (message != null)
            message.write(TheResourceBundle.getString("Jsp Params Invalid Msg")); //FIXME
    }

    return valid;
}

From source file:eu.sisob.uma.restserver.AuthorizationManager.java

/**
 *
 * @param user//ww w.  j  a  va2s  .c  o  m
 * @param pass
 * @param out_attributes
 * @param message
 * @return
 */
public static boolean validateAccess(String user, String pass, UserAttributes out_attributes,
        StringWriter message) {
    boolean valid = true;

    //getCrawkerTaskStatus(code)
    if (message != null)
        message.getBuffer().setLength(0);

    if (!SystemManager.getInstance().IsRunning()) {
        message.write("The back system is off. Please contact with the administrator."); //FIXME
        valid = false;
        return valid;
    }

    if (user != null && pass != null) {
        if (DBAuthorizeUserIn(user, pass, out_attributes)) {
            String code_task_folder = TASKS_USERS_PATH + File.separator + user;

            File f = new File(code_task_folder);
            if (!f.exists())
                f.mkdir();

            valid = true;
            if (message != null)
                message.write(TheResourceBundle.getString("Jsp Auth Msg")); //FIXME               
        } else {
            valid = false;
            if (message != null)
                message.write(TheResourceBundle.getString("Jsp Unauth Msg")); //FIXME                
        }
    } else {
        valid = false;
        if (message != null)
            message.write(TheResourceBundle.getString("Jsp Params Invalid Msg")); //FIXME
    }

    return valid;
}

From source file:com.vmware.demo.SamlUtils.java

/**
 * Convert the given private key into a PEM formatted key string, but
 * strip newlines, header and footer (raw base64).
 *
 * @param key//w  w w.ja v a2 s  .com
 * @return String representing key in PEM format
 */
public static String convertKeyToString(Key key) {
    String keyString = null;
    try {
        StringWriter strWriter = new StringWriter();
        PEMWriter pemWriter = new PEMWriter(strWriter);
        pemWriter.writeObject(key);
        pemWriter.close();
        String temp = new String(strWriter.getBuffer());
        keyString = temp.replace(SamlConstants.BEGIN_PRIVATE_FULL, "");
        keyString = keyString.replace(SamlConstants.END_PRIVATE_FULL, "");
        keyString = keyString.replace("\r\n", "");
    } catch (IOException ioEx) {
        // TODO: Error handling
        return null;
    }
    return keyString;
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

public static String toJsonString(HystrixDashboardStream.DashboardData dashboardData) {
    StringWriter jsonString = new StringWriter();

    try {//  w ww .  j  a va  2 s .co  m
        JsonGenerator json = jsonFactory.createGenerator(jsonString);
        writeDashboardData(json, dashboardData);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return jsonString.getBuffer().toString();
}