本文整理汇总了Java中org.apache.jorphan.util.JOrphanUtils类的典型用法代码示例。如果您正苦于以下问题:Java JOrphanUtils类的具体用法?Java JOrphanUtils怎么用?Java JOrphanUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JOrphanUtils类属于org.apache.jorphan.util包,在下文中一共展示了JOrphanUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* @see java.lang.Thread#run()
*/
@Override
public void run() {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(is)); // default charset
String line = null;
while ((line = br.readLine()) != null)
{
buffer.append(line);
buffer.append("\r\n");
}
} catch (IOException e) {
buffer.append(e.getMessage());
}
finally
{
JOrphanUtils.closeQuietly(br);
}
}
示例2: fixPathEntry
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Fix a path:
* - replace "." by current directory
* - trim any trailing spaces
* - replace \ by /
* - replace // by /
* - remove all trailing /
*/
private static String fixPathEntry(String path){
if (path == null ) {
return null;
}
if (path.equals(".")) { // $NON-NLS-1$
return System.getProperty("user.dir"); // $NON-NLS-1$
}
path = path.trim().replace('\\', '/'); // $NON-NLS-1$ // $NON-NLS-2$
path = JOrphanUtils.substitute(path, "//", "/"); // $NON-NLS-1$// $NON-NLS-2$
while (path.endsWith("/")) { // $NON-NLS-1$
path = path.substring(0, path.length() - 1);
}
return path;
}
示例3: setText
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Create the file with the given string as content -- or replace it's
* content with the given string if the file already existed.
*
* @param body
* New content for the file.
*/
public void setText(String body) {
Writer writer = null;
try {
if (encoding == null) {
writer = new FileWriter(this);
} else {
writer = new OutputStreamWriter(new FileOutputStream(this), encoding);
}
writer.write(body);
writer.flush();
} catch (IOException ioe) {
log.error("", ioe);
} finally {
JOrphanUtils.closeQuietly(writer);
}
}
示例4: parseResponse
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Converts (X)HTML response to DOM object Tree.
* This version cares of charset of response.
* @param unicodeData
* @return the parsed document
*
*/
private Document parseResponse(String unicodeData)
throws UnsupportedEncodingException, IOException, ParserConfigurationException,SAXException,TidyException
{
//TODO: validate contentType for reasonable types?
// NOTE: responseData encoding is server specific
// Therefore we do byte -> unicode -> byte conversion
// to ensure UTF-8 encoding as required by XPathUtil
// convert unicode String -> UTF-8 bytes
byte[] utf8data = unicodeData.getBytes("UTF-8"); // $NON-NLS-1$
ByteArrayInputStream in = new ByteArrayInputStream(utf8data);
boolean isXML = JOrphanUtils.isXML(utf8data);
// this method assumes UTF-8 input data
return XPathUtil.makeDocument(in,false,false,useNameSpace(),isTolerant(),isQuiet(),showWarnings(),reportErrors()
,isXML, isDownloadDTDs());
}
示例5: savePNGWithBatik
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Use Batik to save a PNG of the graph
*
* @param filename
* name of the file to store the image into
* @param image
* to be stored
*/
public void savePNGWithBatik(String filename, BufferedImage image) {
File outfile = new File(filename);
OutputStream fos = createFile(outfile);
if (fos == null) {
return;
}
PNGEncodeParam param = PNGEncodeParam.getDefaultEncodeParam(image);
PNGImageEncoder encoder = new PNGImageEncoder(fos, param);
try {
encoder.encode(image);
} catch (IOException e) {
JMeterUtils.reportErrorToUser("PNGImageEncoder reported: "+e.getMessage(), "Problem creating image file");
} finally {
JOrphanUtils.closeQuietly(fos);
}
}
示例6: loadJMeterProperties
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Load the JMeter properties file; if not found, then
* default to "org/apache/jmeter/jmeter.properties" from the classpath
*
* <p>
* c.f. loadProperties
*
* @param file Name of the file from which the JMeter properties should be loaded
*/
public static void loadJMeterProperties(String file) {
Properties p = new Properties(System.getProperties());
InputStream is = null;
try {
File f = new File(file);
is = new FileInputStream(f);
p.load(is);
} catch (IOException e) {
try {
is =
ClassLoader.getSystemResourceAsStream("org/apache/jmeter/jmeter.properties"); // $NON-NLS-1$
if (is == null) {
throw new RuntimeException("Could not read JMeter properties file:"+file);
}
p.load(is);
} catch (IOException ex) {
// JMeter.fail("Could not read internal resource. " +
// "Archive is broken.");
}
} finally {
JOrphanUtils.closeQuietly(is);
}
appProperties = p;
}
示例7: loadJmeterProperties
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
public static void loadJmeterProperties(InputStream is){
Properties p = new Properties(System.getProperties());
try {
p.load(is);
} catch (IOException e) {
try {
is =
ClassLoader.getSystemResourceAsStream("org/apache/jmeter/jmeter.properties"); // $NON-NLS-1$
if (is == null) {
throw new RuntimeException("Could not read JMeter properties file: jmeter.properties");
}
p.load(is);
} catch (IOException ex) {
// JMeter.fail("Could not read internal resource. " +
// "Archive is broken.");
}
} finally {
JOrphanUtils.closeQuietly(is);
}
appProperties = p;
}
示例8: processFileOrScript
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Process the file or script from the test element.
* <p>
* Sets the following script variables:
* <ul>
* <li>FileName</li>
* <li>Parameters</li>
* <li>bsh.args</li>
* </ul>
* @param bsh the interpreter, not {@code null}
* @return the result of the script, may be {@code null}
*
* @throws JMeterException when working with the bsh fails
*/
protected Object processFileOrScript(BeanShellInterpreter bsh) throws JMeterException{
String fileName = getFilename();
String params = getParameters();
bsh.set("FileName", fileName);//$NON-NLS-1$
// Set params as a single line
bsh.set("Parameters", params); // $NON-NLS-1$
// and set as an array
bsh.set("bsh.args",//$NON-NLS-1$
JOrphanUtils.split(params, " "));//$NON-NLS-1$
if (fileName.length() == 0) {
return bsh.eval(getScript());
}
return bsh.source(fileName);
}
示例9: testStarted
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
@Override
public void testStarted() {
this.setRunningVersion(true);
TestBeanHelper.prepare(this);
JMeterVariables variables = getThreadContext().getVariables();
String poolName = getDataSource();
if(JOrphanUtils.isBlank(poolName)) {
throw new IllegalArgumentException("Variable Name must not be empty for element:"+getName());
} else if (variables.getObject(poolName) != null) {
log.error("JDBC data source already defined for: "+poolName);
} else {
String maxPool = getPoolMax();
perThreadPoolSet = Collections.synchronizedSet(new HashSet<BasicDataSource>());
if (maxPool.equals("0")){ // i.e. if we want per thread pooling
variables.putObject(poolName, new DataSourceComponentImpl()); // pool will be created later
} else {
BasicDataSource src = initPool(maxPool);
synchronized(this){
dbcpDataSource = src;
variables.putObject(poolName, new DataSourceComponentImpl(dbcpDataSource));
}
}
}
}
示例10: read
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Reads data until the defined EOM byte is reached.
* If there is no EOM byte defined, then reads until
* the end of the stream is reached.
* Response data is converted to hex-encoded binary
* @return hex-encoded binary string
* @throws ReadException when reading fails
*/
@Override
public String read(InputStream is) throws ReadException {
ByteArrayOutputStream w = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[4096];
int x = 0;
while ((x = is.read(buffer)) > -1) {
w.write(buffer, 0, x);
if (useEolByte && (buffer[x - 1] == eolByte)) {
break;
}
}
IOUtils.closeQuietly(w); // For completeness
final String hexString = JOrphanUtils.baToHexString(w.toByteArray());
if(log.isDebugEnabled()) {
log.debug("Read: " + w.size() + "\n" + hexString);
}
return hexString;
} catch (IOException e) {
throw new ReadException("", e, JOrphanUtils.baToHexString(w.toByteArray()));
}
}
示例11: read
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String read(InputStream is) throws ReadException{
byte[] msg = new byte[0];
int msgLen = 0;
byte[] lengthBuffer = new byte[lengthPrefixLen];
try {
if (is.read(lengthBuffer, 0, lengthPrefixLen) == lengthPrefixLen) {
msgLen = byteArrayToInt(lengthBuffer);
msg = new byte[msgLen];
int bytes = JOrphanUtils.read(is, msg, 0, msgLen);
if (bytes < msgLen) {
log.warn("Incomplete message read, expected: "+msgLen+" got: "+bytes);
}
}
String buffer = JOrphanUtils.baToHexString(msg);
if(log.isDebugEnabled()) {
log.debug("Read: " + msgLen + "\n" + buffer);
}
return buffer;
}
catch(IOException e) {
throw new ReadException("", e, JOrphanUtils.baToHexString(msg));
}
}
示例12: save
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Save the authentication data to a file.
*
* @param authFile
* path of the file to save the authentication data to
* @throws IOException
* when writing to the file fails
*/
public void save(String authFile) throws IOException {
File file = new File(authFile);
if (!file.isAbsolute()) {
file = new File(System.getProperty("user.dir"),authFile);
}
PrintWriter writer = null;
try {
writer = new PrintWriter(new FileWriter(file));
writer.println("# JMeter generated Authorization file");
for (int i = 0; i < getAuthObjects().size(); i++) {
Authorization auth = (Authorization) getAuthObjects().get(i).getObjectValue();
writer.println(auth.toString());
}
writer.flush();
writer.close();
} finally {
JOrphanUtils.closeQuietly(writer);
}
}
示例13: getImplementation
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
public static HTTPAbstractImpl getImplementation(String impl, HTTPSamplerBase base){
if (HTTPSamplerBase.PROTOCOL_FILE.equals(base.getProtocol())) {
return new HTTPFileImpl(base);
}
if (JOrphanUtils.isBlank(impl)){
impl = DEFAULT_CLASSNAME;
}
if (IMPL_JAVA.equals(impl) || HTTP_SAMPLER_JAVA.equals(impl)) {
return new HTTPJavaImpl(base);
} else if (IMPL_HTTP_CLIENT3_1.equals(impl) || HTTP_SAMPLER_APACHE.equals(impl)) {
return new HTTPHC3Impl(base);
} else if (IMPL_HTTP_CLIENT4.equals(impl)) {
return new HTTPHC4Impl(base);
} else {
throw new IllegalArgumentException("Unknown implementation type: '"+impl+"'");
}
}
示例14: writeFileToStream
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Write the content of a file to the output stream
*
* @param filename the filename of the file to write to the stream
* @param out the stream to write to
* @throws IOException
*/
private static void writeFileToStream(String filename, OutputStream out) throws IOException {
byte[] buf = new byte[1024];
// 1k - the previous 100k made no sense (there's tons of buffers
// elsewhere in the chain) and it caused OOM when many concurrent
// uploads were being done. Could be fixed by increasing the evacuation
// ratio in bin/jmeter[.bat], but this is better.
InputStream in = new BufferedInputStream(new FileInputStream(filename));
int read;
boolean noException = false;
try {
while ((read = in.read(buf)) > 0) {
out.write(buf, 0, read);
}
noException = true;
}
finally {
if(!noException) {
// Exception in progress
JOrphanUtils.closeQuietly(in);
} else {
in.close();
}
}
}
示例15: getFileObjectContent
import org.apache.jorphan.util.JOrphanUtils; //导入依赖的package包/类
/**
* Try to load an object from a provided file, so that it can be used as body
* for a JMS message.
* An {@link IllegalStateException} will be thrown if loading the object fails.
*
* @param path Path to the file that will be serialized
* @return Serialized object instance
*/
private static Serializable getFileObjectContent(final String path) {
Serializable readObject = null;
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(path));
XStream xstream = new XStream();
readObject = (Serializable) xstream.fromXML(inputStream, readObject);
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
throw new IllegalStateException("Unable to load object instance from file:'"+path+"'", e);
} finally {
JOrphanUtils.closeQuietly(inputStream);
}
return readObject;
}