当前位置: 首页>>代码示例>>Java>>正文


Java JOrphanUtils.closeQuietly方法代码示例

本文整理汇总了Java中org.apache.jorphan.util.JOrphanUtils.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java JOrphanUtils.closeQuietly方法的具体用法?Java JOrphanUtils.closeQuietly怎么用?Java JOrphanUtils.closeQuietly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jorphan.util.JOrphanUtils的用法示例。


在下文中一共展示了JOrphanUtils.closeQuietly方法的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);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:23,代码来源:StreamGobbler.java

示例2: 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);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:24,代码来源:TextFile.java

示例3: 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);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:25,代码来源:SaveGraphicsService.java

示例4: 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;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:24,代码来源:PublisherSampler.java

示例5: 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;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:23,代码来源:JMeterUtils.java

示例6: 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);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:28,代码来源:AuthManager.java

示例7: 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();
        }
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:32,代码来源:PostWriter.java

示例8: load

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
private NodeList load() throws IOException, FileNotFoundException, ParserConfigurationException, SAXException,
        TransformerException {
    InputStream fis = null;
    NodeList nl = null;
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

        fis = new BufferedInputStream(new FileInputStream(fileName));
        nl = XPathUtil.selectNodeList(builder.parse(fis), xpath);
        if(log.isDebugEnabled()) {
            log.debug("found " + nl.getLength());
        }
    } catch (TransformerException | SAXException
            | ParserConfigurationException | IOException e) {
        log.warn(e.toString());
        throw e;
    } finally {
        JOrphanUtils.closeQuietly(fis);
    }
    return nl;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:22,代码来源:XPathFileContainer.java

示例9: save

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
/**
 * Save the authentication data to a file.
 */
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);
    }
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:23,代码来源:AuthManager.java

示例10: 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", e);
  } finally {
      JOrphanUtils.closeQuietly(inputStream);
  }
  return readObject;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:24,代码来源:PublisherSampler.java

示例11: savePNGWithBatik

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
/**
 * Use Batik to save a PNG of the graph
 *
 * @param filename
 * @param image
 */
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);
    }
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:23,代码来源:SaveGraphicsService.java

示例12: setUp

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    establishConnection();
    sampler = new HTTPSampler();// This must be the original (Java) HTTP sampler
    postWriter=new PostWriter();
    
    // Create the test file content
    TEST_FILE_CONTENT = "foo content &?=01234+56789-\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052".getBytes(UTF_8);

    // create a temporary file to make sure we always have a file to give to the PostWriter 
    // Whereever we are or Whatever the current path is.
    temporaryFile = File.createTempFile("foo", "txt");
    OutputStream output = null;
    try {
        output = new FileOutputStream(temporaryFile);
        output.write(TEST_FILE_CONTENT);
        output.flush();
    } finally {
        JOrphanUtils.closeQuietly(output);
    }
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:22,代码来源:PostWriterTest.java

示例13: getText

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
/**
 * Read the whole file content and return it as a string.
 *
 * @return the content of the file
 */
public String getText() {
    String lineEnd = System.getProperty("line.separator"); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    Reader reader = null;
    BufferedReader br = null;
    try {
        if (encoding == null) {
            reader = new FileReader(this);
        } else {
            reader = new InputStreamReader(new FileInputStream(this), encoding);
        }
        br = new BufferedReader(reader);
        String line = "NOTNULL"; //$NON-NLS-1$
        while (line != null) {
            line = br.readLine();
            if (line != null) {
                sb.append(line + lineEnd);
            }
        }
    } catch (IOException ioe) {
        log.error("", ioe); //$NON-NLS-1$
    } finally {
        JOrphanUtils.closeQuietly(br); // closes reader as well
    }

    return sb.toString();
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:33,代码来源:TextFile.java

示例14: loadTree

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
/**
 * Load a Test tree (JMX file)
 * @param reader the JMX file as an {@link InputStream}
 * @return the loaded tree or null if an error occurs
 * @throws IOException if there is a problem reading the file or processing it
 * @deprecated use {@link SaveService}{@link #loadTree(File)}
 */
@Deprecated
public static HashTree loadTree(InputStream reader) throws IOException {
    try {
        return readTree(reader, null);
    } catch(IllegalArgumentException e) {
        log.error("Problem loading XML, message:"+e.getMessage(), e);
        return null;
    } finally {
        JOrphanUtils.closeQuietly(reader);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:19,代码来源:SaveService.java

示例15: loadProperties

import org.apache.jorphan.util.JOrphanUtils; //导入方法依赖的package包/类
/**
 * This method loads a property file that may reside in the user space, or
 * in the classpath
 *
 * @param file
 *            the file to load
 * @param defaultProps a set of default properties
 * @return the Properties from the file; if it could not be processed, the defaultProps are returned.
 */
public static Properties loadProperties(String file, Properties defaultProps) {
    Properties p = new Properties(defaultProps);
    InputStream is = null;
    try {
        File f = new File(file);
        is = new FileInputStream(f);
        p.load(is);
    } catch (IOException e) {
        try {
            final URL resource = JMeterUtils.class.getClassLoader().getResource(file);
            if (resource == null) {
                log.warn("Cannot find " + file);
                return defaultProps;
            }
            is = resource.openStream();
            if (is == null) {
                log.warn("Cannot open " + file);
                return defaultProps;
            }
            p.load(is);
        } catch (IOException ex) {
            log.warn("Error reading " + file + " " + ex.toString());
            return defaultProps;
        }
    } finally {
        JOrphanUtils.closeQuietly(is);
    }
    return p;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:39,代码来源:JMeterUtils.java


注:本文中的org.apache.jorphan.util.JOrphanUtils.closeQuietly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。