public class IPCHelper { static final java.util.logging.Logger LOG = java.util.logging.Logger .getLogger("org.columba.core.base"); //$NON-NLS-1$ protected StreamThread outputStream = null; protected StreamThread errorStream = null; protected OutputStream inputStream = null; protected Process p; public IPCHelper() { // nothing to do } /** * * execute command * * initialize streams * * @param command * @throws Exception */ public void executeCommand(String[] command) throws Exception { this.p = Runtime.getRuntime().exec(command); errorStream = new StreamThread(p.getErrorStream()); outputStream = new StreamThread(p.getInputStream()); inputStream = p.getOutputStream(); errorStream.start(); outputStream.start(); } public void send(String in) throws Exception { inputStream.write(in.getBytes()); inputStream.flush(); inputStream.close(); } public void send(InputStream in) throws Exception { StreamUtils.streamCopy(in, inputStream); inputStream.flush(); inputStream.close(); } public int waitFor() throws Exception { int exitVal = p.waitFor(); return exitVal; } /** * * return error * * @return * @throws Exception */ public String getErrorString() throws Exception { String str = errorStream.getBuffer(); return str; } /** * * return output * * @return * @throws Exception */ public String getOutputString() throws Exception { String str = outputStream.getBuffer(); return str; } /* * wait for stream threads to die * */ public void waitForThreads() throws Exception { outputStream.join(); errorStream.join(); } public class StreamThread extends Thread { InputStream is; StringBuffer buf; public StreamThread(InputStream theInputStream) { this.is = theInputStream; buf = new StringBuffer(); } @Override public void run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { LOG.info(">" + line); //$NON-NLS-1$ buf.append(line + "\n"); //$NON-NLS-1$ } } catch (IOException ioe) { ioe.printStackTrace(); } } public String getBuffer() { return buf.toString()
public class IPCHelper { private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger("org.columba.mail.spam.spamassassin"); //$NON-NLS-1$ protected StreamThread outputStream = null; protected StreamThread errorStream = null; protected OutputStream inputStream = null; protected Process p; public IPCHelper() { } /** * * execute command * * initialize streams * * @param command * @throws Exception */ public void executeCommand(String command) throws Exception { p = Runtime.getRuntime().exec(command); errorStream = new StreamThread(p.getErrorStream()); outputStream = new StreamThread(p.getInputStream()); inputStream = p.getOutputStream(); errorStream.start(); outputStream.start(); } public void send(String in) throws Exception { inputStream.write(in.getBytes()); inputStream.flush(); inputStream.close(); } public void send(InputStream in) throws Exception { StreamUtils.streamCopy(in, inputStream); inputStream.flush(); inputStream.close(); } public int waitFor() throws Exception { int exitVal = p.waitFor(); return exitVal; } /** * * return error * * @return @throws * Exception */ public String getErrorString() throws Exception { String str = errorStream.getBuffer(); return str; } /** * * return output * * @return @throws * Exception */ public String getOutputString() throws Exception { String str = outputStream.getBuffer(); return str; } /* * wait for stream threads to die * */ public void waitForThreads() throws Exception { outputStream.join(); errorStream.join(); } public class StreamThread extends Thread { InputStream is; StringBuffer buf; public StreamThread(InputStream is) { this.is = is; buf = new StringBuffer(); } public void run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { LOG.info(">" + line); //$NON-NLS-1$ buf.append(line + "\n"); } } catch (IOException ioe) { ioe.printStackTrace(); } } public String getBuffer() { return buf.toString()
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/core/src/main/java/org/columba/core/base/IPCHelper.java File path: /columba-1.4-src/mail/src/main/java/org/columba/mail/spam/spamassassin/IPCHelper.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class IPCHelper {
1
public class IPCHelper {
2
   
2
	
3
 static final java.util.logging.Logger LOG = 
3
	private static final java.util.logging.Logger LOG = 
4
java.util.logging.Logger
4
        java.util.logging.Logger
5
	    .getLogger("org.columba.core.base"); //$NON-NLS-1$
5
.getLogger("org.columba.mail.spam.spamassassin"); //$NON-NLS-1$
6
	
6
    protected StreamThread outputStream = null;
7
    protected StreamThread outputStream = null;
7
    protected StreamThread errorStream = null;
8
    protected StreamThread errorStream = null;
8
    protected OutputStream inputStream = null;
9
    protected OutputStream inputStream = null;
9
    protected Process p;
10
    protected Process p;
10
    public IPCHelper() {
11
    public IPCHelper() {
11
	// nothing to do
12
    }
12
    }
13
    /**
13
    /**
14
         * 
14
     *
15
    
16
     * execute command
15
     * execute command
17
         * 
16
     
18
 
17
*
19
        * initialize streams
18
     * initialize streams
20
         * 
19
     
21
    
20
*
22
     * @param command
21
     * @param command
23
         * @throws Exception
22
     * @throws Exception
24
         */
23
     */
25
    public void executeCommand(String[] command) throws Exception {
24
    public void executeCommand(String command) throws Exception {
26
	this.p = Runtime.getRuntime().exec(command);
25
        p = Runtime.getRuntime().exec(command);
27
	errorStream = new StreamThread(p.getErrorStream());
26
        errorStream = new StreamThread(p.getErrorStream());
28
	outputStream = new StreamThread(p.getInputStream());
27
        outputStream = new StreamThread(p.getInputStream());
29
	inputStream = p.getOutputStream();
28
        inputStream = p.getOutputStream();
30
	errorStream.start();
29
        errorStream.start();
31
	outputStream.start();
30
        outputStream.start();
32
    }
31
    }
33
    public void send(String in) throws Exception {
32
    public void send(String in) throws Exception {
34
	inputStream.write(in.getBytes());
33
        inputStream.write(in.getBytes());
35
	inputStream.flush();
34
        inputStream.flush();
36
	inputStream.close();
35
        inputStream.close();
37
    }
36
    }
38
    public void send(InputStream in) throws Exception {
37
    public void send(InputStream in) throws Exception {
39
	StreamUtils.streamCopy(in, inputStream);
38
        StreamUtils.streamCopy(in, inputStream);
40
	inputStream.flush();
39
        inputStream.flush();
41
	inputStream.close();
40
        inputStream.close();
42
    }
41
    }
43
    public int waitFor() throws Exception {
42
    public int waitFor() throws Exception {
44
	int exitVal = p.waitFor();
43
        int exitVal = p.waitFor();
45
	return exitVal;
44
        return exitVal;
46
    }
45
    }
47
    /**
46
    /**
48
         * 
47
     
49
    
48
*
50
     * return error
49
     * return error
51
         * 
50
     *
52
         * @return
51
     * @return
53
         * @throws
52
 @throws
54
 Exception
53
     *         Exception
55
         */
54
     */
56
    public String getErrorString() throws Exception {
55
    public String getErrorString() throws Exception {
57
	String str = errorStream.getBuffer();
56
        String str = errorStream.getBuffer();
58
	return str;
57
        return str;
59
    }
58
    }
60
    /**
59
    /**
61
         * 
60
     *
62
         * return output
61
     * return output
63
         * 
62
     
64
    
63
*
65
     * @return
64
     * @return @throws
66
         * @throws Exception
65
     *         Exception
67
         */
66
     */
68
    public String getOutputString() throws Exception {
67
    public String getOutputString() throws Exception {
69
	String str = outputStream.getBuffer();
68
        String str = outputStream.getBuffer();
70
	return str;
69
        return str;
71
    }
70
    }
72
    /*
71
    /*
73
         * wait for stream threads to die
72
     * wait for stream threads to die
74
         * 
73
     
75
    
74
*
76
     */
75
     */
77
    public void waitForThreads() throws Exception {
76
    public void waitForThreads() throws Exception {
78
	outputStream.join();
77
        outputStream.join();
79
	errorStream.join();
78
        errorStream.join();
80
    }
79
    }
81
    public class StreamThread extends Thread {
80
    public class StreamThread extends Thread {
82
	InputStream is;
81
        InputStream is;
83
	StringBuffer buf;
82
        StringBuffer buf;
84
	public StreamThread(InputStream theInputStream) {
83
        public StreamThread(InputStream 
85
	
84
is) {
86
    this.is = theInputStream;
85
            this.is = 
87
	
86
is;
88
    buf = new StringBuffer();
87
            buf = new StringBuffer();
89
	}
90
	@Override
91
	
88
        }
92
public void run() {
89
        public void run() {
93
	    try {
90
            try {
94
		InputStreamReader isr = new InputStreamReader(is);
91
                InputStreamReader isr = new InputStreamReader(is);
95
		BufferedReader br = new BufferedReader(isr);
92
                BufferedReader br = new BufferedReader(isr);
96
		String line = null;
93
                String line = null;
97
		while ((line = br.readLine()) != null) {
94
                while ((line = br.readLine()) != null) {
98
		    LOG.info(">" + line); //$NON-NLS-1$
95
                    LOG.info(">" + line); //$NON-NLS-1$
99
		    buf.append(line + "\n"); //$NON-NLS-1$
96
                    buf.append(line + "\n");
100
		}
101
	
97
                }
102
    } catch (IOException ioe) {
98
            } catch (IOException ioe) {
103
		ioe.printStackTrace();
99
                ioe.printStackTrace();
104
	    }
105
	}
106
	
100
            }
101
        }
107
public String getBuffer() {
102
        public String getBuffer() {
108
	    return buf.toString()
103
            return buf.toString()
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0