You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/11/04 12:19:39 UTC
svn commit: r711225 -
/jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
Author: sebb
Date: Tue Nov 4 03:19:37 2008
New Revision: 711225
URL: http://svn.apache.org/viewvc?rev=711225&view=rev
Log:
Add csvSplitString() utility method
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java?rev=711225&r1=711224&r2=711225&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java Tue Nov 4 03:19:37 2008
@@ -23,6 +23,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.StringReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -122,6 +123,9 @@
dataReader.mark(400);// Enough to read the header column names
// Get the first line, and see if it is the header
String line = dataReader.readLine();
+ if (line == null){
+ throw new IOException(filename+": unable to read header line");
+ }
long lineNumber=1;
SampleSaveConfiguration saveConfig = CSVSaveService.getSampleSaveConfiguration(line,filename);
if (saveConfig == null) {// not a valid header
@@ -986,4 +990,19 @@
private static boolean isDelimOrEOL(char delim, int ch) {
return ch == delim || ch == '\n' || ch == '\r';
}
+
+ /**
+ * Reads from String and splits into strings according to the delimiter,
+ * taking note of quoted strings.
+ *
+ * Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally.
+ *
+ * @param line input line
+ * @param delim delimiter (e.g. comma)
+ * @return array of strings
+ * @throws IOException also for unexpected quote characters
+ */
+ public static String[] csvSplitString(String line, char delim) throws IOException {
+ return csvReadFile(new BufferedReader(new StringReader(line)), delim);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org