Author: sebb Date: Mon Dec 14 23:12:57 2009 New Revision: 890544 URL: http://svn.apache.org/viewvc?rev=890544&view=rev Log: Add optional encoding parameter to FileToString function
Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/FileToString.java jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=890544&r1=890543&r2=890544&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original) +++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Mon Dec 14 23:12:57 2009 @@ -799,7 +799,8 @@ stopping_test=Shutting down all test threads. Please be patient. stopping_test_failed=One or more test threads won't exit; see log file. stopping_test_title=Stopping Test -string_from_file_file_name=Enter full path to file +string_from_file_encoding=File encoding if not the platform default (opt) +string_from_file_file_name=Enter path (absolute or relative) to file string_from_file_seq_final=Final file sequence number (opt) string_from_file_seq_start=Start file sequence number (opt) summariser_title=Generate Summary Results Modified: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/FileToString.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/FileToString.java?rev=890544&r1=890543&r2=890544&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/FileToString.java (original) +++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/FileToString.java Mon Dec 14 23:12:57 2009 @@ -39,6 +39,7 @@ * * Parameters: * - file name + * - file encoding (optional) * - variable name (optional) * * Returns: @@ -58,14 +59,17 @@ static { desc.add(JMeterUtils.getResString("string_from_file_file_name"));//$NON-NLS-1$ + desc.add(JMeterUtils.getResString("string_from_file_encoding"));//$NON-NLS-1$ desc.add(JMeterUtils.getResString("function_name_paropt"));//$NON-NLS-1$ } private static final int MIN_PARAM_COUNT = 1; - private static final int MAX_PARAM_COUNT = 2; + private static final int MAX_PARAM_COUNT = 3; - private static final int PARAM_NAME = 2; + private static final int ENCODING = 2; + + private static final int PARAM_NAME = 3; private Object[] values; @@ -79,6 +83,11 @@ String fileName = ((CompoundVariable) values[0]).execute(); + String encoding = null;//means platform default + if (values.length >= ENCODING) { + encoding = ((CompoundVariable) values[ENCODING - 1]).execute().trim(); + } + String myName = "";//$NON-NLS-1$ if (values.length >= PARAM_NAME) { myName = ((CompoundVariable) values[PARAM_NAME - 1]).execute().trim(); @@ -87,7 +96,7 @@ String myValue = ERR_IND; try { - myValue = FileUtils.readFileToString(new File(fileName), null); + myValue = FileUtils.readFileToString(new File(fileName), encoding); } catch (IOException e) { log.warn("Could not read file: "+fileName+" "+e.getMessage()); throw new JMeterStopThreadException("End of sequence"); Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=890544&r1=890543&r2=890544&view=diff ============================================================================== --- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original) +++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Mon Dec 14 23:12:57 2009 @@ -1105,11 +1105,14 @@ <property name="File Name" required="Yes">Path to the file name. (The path can be relative to the JMeter launch directory) </property> + <property name="File encoding if not the platform default" required="No"> + The encoding to be used to read the file. If not specified, the platform default is used. + </property> <property name="Variable Name" required="No"> A reference name - refName - for reusing the value created by this function. Stored values are of the form ${refName}. </property> </properties> -<p>The file name parameter and reference name parameter (if supplied) are resolved every time the function is executed.</p> +<p>The file name, encoding and reference name parameters are resolved every time the function is executed.</p> </component> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org