Search in sources :

Example 31 with CharArrayWriter

use of java.io.CharArrayWriter in project frostwire by frostwire.

the class IOUtils method toCharArray.

/**
 * Get the contents of a <code>Reader</code> as a character array.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedReader</code>.
 *
 * @param input  the <code>Reader</code> to read from
 * @return the requested character array
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @since 1.1
 */
public static char[] toCharArray(Reader input) throws IOException {
    CharArrayWriter sw = new CharArrayWriter();
    copy(input, sw);
    return sw.toCharArray();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 32 with CharArrayWriter

use of java.io.CharArrayWriter in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class IOTinyUtils method toString.

public static String toString(Reader reader) throws IOException {
    CharArrayWriter sw = new CharArrayWriter();
    copy(reader, sw);
    return sw.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 33 with CharArrayWriter

use of java.io.CharArrayWriter in project cuba by cuba-platform.

the class FreeMarkerView method processTemplate.

@Override
protected void processTemplate(Template template, SimpleHash model, HttpServletResponse response) throws IOException, TemplateException {
    CharArrayWriter printWriter = new CharArrayWriter();
    try {
        template.process(model, printWriter);
        response.getWriter().write(printWriter.toCharArray());
    } catch (IOException e) {
        log.error("IO Exception", e);
    } catch (TemplateException e) {
        log.error("Template exception", e);
    }
}
Also used : IOException(java.io.IOException) CharArrayWriter(java.io.CharArrayWriter)

Example 34 with CharArrayWriter

use of java.io.CharArrayWriter in project TOSCAna by StuPro-TOSCAna.

the class DockerfileBuilder method toString.

/**
 *     Builds the dockerfile to a string
 */
@Override
public String toString() {
    CharArrayWriter out = new CharArrayWriter();
    writeTo(out);
    return new String(out.toCharArray());
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 35 with CharArrayWriter

use of java.io.CharArrayWriter in project pentaho-kettle by pentaho.

the class SSHData method OpenConnection.

public static Connection OpenConnection(String serveur, int port, String username, String password, boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost, int proxyport, String proxyusername, String proxypassword) throws KettleException {
    Connection conn = null;
    char[] content = null;
    boolean isAuthenticated = false;
    try {
        // perform some checks
        if (useKey) {
            if (Utils.isEmpty(keyFilename)) {
                throw new KettleException(BaseMessages.getString(SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing"));
            }
            FileObject keyFileObject = KettleVFS.getFileObject(keyFilename);
            if (!keyFileObject.exists()) {
                throw new KettleException(BaseMessages.getString(SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename));
            }
            FileContent keyFileContent = keyFileObject.getContent();
            CharArrayWriter charArrayWriter = new CharArrayWriter((int) keyFileContent.getSize());
            try (InputStream in = keyFileContent.getInputStream()) {
                IOUtils.copy(in, charArrayWriter);
            }
            content = charArrayWriter.toCharArray();
        }
        // Create a new connection
        conn = createConnection(serveur, port);
        /* We want to connect through a HTTP proxy */
        if (!Utils.isEmpty(proxyhost)) {
            // if the proxy requires basic authentication:
            if (!Utils.isEmpty(proxyusername)) {
                conn.setProxyData(new HTTPProxyData(proxyhost, proxyport, proxyusername, proxypassword));
            } else {
                conn.setProxyData(new HTTPProxyData(proxyhost, proxyport));
            }
        }
        // and connect
        if (timeOut == 0) {
            conn.connect();
        } else {
            conn.connect(null, 0, timeOut * 1000);
        }
        // authenticate
        if (useKey) {
            isAuthenticated = conn.authenticateWithPublicKey(username, content, space.environmentSubstitute(passPhrase));
        } else {
            isAuthenticated = conn.authenticateWithPassword(username, password);
        }
        if (isAuthenticated == false) {
            throw new KettleException(BaseMessages.getString(SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username));
        }
    } catch (Exception e) {
        // do not forget to disconnect if connected
        if (conn != null) {
            conn.close();
        }
        throw new KettleException(BaseMessages.getString(SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username), e);
    }
    return conn;
}
Also used : FileContent(org.apache.commons.vfs2.FileContent) KettleException(org.pentaho.di.core.exception.KettleException) InputStream(java.io.InputStream) Connection(com.trilead.ssh2.Connection) FileObject(org.apache.commons.vfs2.FileObject) HTTPProxyData(com.trilead.ssh2.HTTPProxyData) CharArrayWriter(java.io.CharArrayWriter) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

CharArrayWriter (java.io.CharArrayWriter)211 PrintWriter (java.io.PrintWriter)51 IOException (java.io.IOException)39 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)21 Test (org.junit.Test)11 InputStreamReader (java.io.InputStreamReader)9 Map (java.util.Map)9 BufferedReader (java.io.BufferedReader)8 File (java.io.File)8 ArrayList (java.util.ArrayList)8 TitledBorder (javax.swing.border.TitledBorder)8 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)7 Graph (edu.cmu.tetrad.graph.Graph)7 Writable (groovy.lang.Writable)7 CharArrayReader (java.io.CharArrayReader)7 Reader (java.io.Reader)7 Date (java.util.Date)7 InputStream (java.io.InputStream)6 StringReader (java.io.StringReader)6 IKnowledge (edu.cmu.tetrad.data.IKnowledge)5