[apache-rat-pd] r54 committed - I found duplicated function used in code. I correct this and write jav...

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 22, 2009, 1:10:10 PM8/22/09
to apache-rat...@googlegroups.com
Revision: 54
Author: maka82
Date: Sat Aug 22 10:09:36 2009
Log: I found duplicated function used in code. I correct this and write
javadocs for new refactored one.
http://code.google.com/p/apache-rat-pd/source/detail?r=54

Modified:
/trunk/src/main/java/org/apache/rat/pd/core/PdCommandLine.java
/trunk/src/main/java/org/apache/rat/pd/core/SourceCodeAnalyser.java
/trunk/src/main/java/org/apache/rat/pd/util/FileManipulator.java

=======================================
--- /trunk/src/main/java/org/apache/rat/pd/core/PdCommandLine.java Fri Aug
21 17:04:14 2009
+++ /trunk/src/main/java/org/apache/rat/pd/core/PdCommandLine.java Sat Aug
22 10:09:36 2009
@@ -20,6 +20,7 @@
*/
package org.apache.rat.pd.core;

+import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
@@ -393,7 +394,7 @@
this.out.println("Trying to read configuration options from: " +
config);
String[] args = null;
try {
- String content = FileManipulator.readFile(config);
+ String content = FileManipulator.readFile(new
FileReader(config));
content = content.replaceAll("\n", " ");
args = content.split(" ");
} catch (IOException e) {
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/core/SourceCodeAnalyser.java Fri
Aug 21 17:04:14 2009
+++ /trunk/src/main/java/org/apache/rat/pd/core/SourceCodeAnalyser.java Sat
Aug 22 10:09:36 2009
@@ -36,6 +36,7 @@
import org.apache.rat.pd.heuristic.IHeuristicChecker;
import org.apache.rat.pd.report.Report;
import org.apache.rat.pd.report.ReportEntry;
+import org.apache.rat.pd.util.FileManipulator;

/**
* This is implementation of the sliding window algorithm
@@ -119,7 +120,7 @@
try {

System.out.println("\n");
- String code = readFile(document.reader());
+ String code = FileManipulator.readFile(document.reader());

checkOneFile(searchEngines, code, algorithmsForChecking,
document.getName());
} catch (IOException e) {
@@ -127,25 +128,7 @@
}
}

- /**
- * @param reader object which can read a file
- * @return content of file
- * @throws IOException
- */
- private String readFile(Reader reader) throws IOException {
- String toRet = "";
- // TODO encoding is system default now!!!!
- BufferedReader input = new BufferedReader(reader);
- try {
- String line = null;
- while ((line = input.readLine()) != null) {
- toRet += line + "\n";
- }
- } finally {
- input.close();
- }
- return toRet;
- }
+

/**
* Implementation of sliding-window algorithm.
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/util/FileManipulator.java Fri
Aug 21 17:04:14 2009
+++ /trunk/src/main/java/org/apache/rat/pd/util/FileManipulator.java Sat
Aug 22 10:09:36 2009
@@ -22,17 +22,21 @@

import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.Reader;
import java.io.Writer;

public class FileManipulator {

// TODO encoding is system default now!!!!
+ /**
+ * @param filename
+ * @param aContents
+ * @throws IOException
+ */
static public void saveFile(String filename, String aContents) throws
IOException {
Writer output = new BufferedWriter(new FileWriter(filename));
try {
@@ -42,12 +46,17 @@
}
}

- // TODO encoding is system default now!!!!
- static public String readFile(String path) throws IOException {
- File aFile = new File(path);
-
+ /**
+ * To read file and replace all new-line characters ( \n, \r )with "\n"
+ *
+ * @param reader object which can read a file
+ * @return content of file
+ * @throws IOException
+ */
+ public static String readFile(Reader reader) throws IOException {
String toRet = "";
- BufferedReader input = new BufferedReader(new FileReader(aFile));
+ // TODO encoding is system default now!!!!
+ BufferedReader input = new BufferedReader(reader);
try {
String line = null;
while ((line = input.readLine()) != null) {
@@ -59,13 +68,18 @@
return toRet;
}

+ /**
+ * To convert the InputStream to String we use the
BufferedReader.readLine()
+ * method. We iterate until the BufferedReader return null which means
+ * there's no more data to read. Each line will appended to a
StringBuilder
+ * and returned as String. It replace all new-line characters ( \n, \r
)with
+ * "\n".
+ *
+ * @param is inputStream
+ * @return string read from stream
+ */
public static String convertStreamToString(InputStream is) {
- /*
- * To convert the InputStream to String we use the
- * BufferedReader.readLine() method. We iterate until the
BufferedReader
- * return null which means there's no more data to read. Each line
will
- * appended to a StringBuilder and returned as String.
- */
+
BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
StringBuilder sb = new StringBuilder();

Reply all
Reply to author
Forward
0 new messages