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


Java IOUtils.closeQuietly方法代码示例

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


在下文中一共展示了IOUtils.closeQuietly方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSonarProjectURLFromBuildLogs

import hudson.util.IOUtils; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private String getSonarProjectURLFromBuildLogs(Run<?, ?> build) throws IOException {
	BufferedReader br = null;
	String url = null;
	try {
		br = new BufferedReader(build.getLogReader());
		String strLine;
		Pattern p = Pattern.compile(URL_PATTERN_IN_LOGS);
		while ((strLine = br.readLine()) != null) {
			Matcher match = p.matcher(strLine);
			if (match.matches()) {
				url = match.group(1);
			}
		}
	} finally {
		IOUtils.closeQuietly(br);
	}
	return url;
}
 
开发者ID:jenkinsci,项目名称:influxdb-plugin,代码行数:20,代码来源:SonarQubePointGenerator.java

示例2: doRun

import hudson.util.IOUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void doRun() throws Exception {
    if (isEnabled()) {
        ObjectWriter writer = mapper.writer();
        // always allocate 1kb more that the average compressed size
        ByteArrayOutputStream baos = new ByteArrayOutputStream(averageSize + 1024);
        try {
            GZIPOutputStream gzos = null;
            try {
                gzos = new GZIPOutputStream(baos);
                writer.writeValue(gzos, Metrics.metricRegistry());
            } finally {
                IOUtils.closeQuietly(gzos);
            }
        } finally {
            baos.close();
        }
        byte[] compressedBytes = baos.toByteArray();
        // the compressed size should be an average of the recent values, this will give us
        // a computationally quick exponential move towards the average... we do not need a strict
        // exponential average
        averageSize = Math.max(8192, (7 * averageSize + compressedBytes.length) / 8);
        bucket.add(new Sample(System.currentTimeMillis(), compressedBytes));
    }
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:29,代码来源:MetricsRootAction.java

示例3: downloadAndSaveToCache

import hudson.util.IOUtils; //导入方法依赖的package包/类
/**
 * Downloads and saves JSON files to local cache.
 *
 * @param pathToJSON Relative path to JSON file.
 * @return Returns content of JSON file.
 * @throws IOException When file operations failed.
 */
private String downloadAndSaveToCache(String pathToJSON) throws IOException {
    String fsPath = FilenameUtils.concat(localCachePath, pathToJSON);
    String httpPath = ccrUrl + pathToJSON;
    LOG.info("Local Path " + fsPath);
    // make directory
    IOUtils.mkdirs(new File(FilenameUtils.getFullPath(fsPath)));

    // get content
    String data = IOUtils.toString(new URL(httpPath).openStream());

    // save to cache
    FileWriter writer = null;
    try {
        writer = new FileWriter(fsPath);
        IOUtils.write(data, writer);
        writer.flush();
    } finally {
        IOUtils.closeQuietly(writer);
    }

    return data;
}
 
开发者ID:ederst,项目名称:ccr-parameter-plugin,代码行数:30,代码来源:CacheManager.java

示例4: setWriter

import hudson.util.IOUtils; //导入方法依赖的package包/类
private void setWriter(Writer writer) {
    Writer oldWriter = null;
    boolean success = false;
    outputLock.lock();
    try {
        oldWriter = this.writer;
        if (oldWriter != null) {
            try {
                this.writer.flush();
            } catch (IOException e) {
                // ignore
            }
        }
        this.writer = writer;
    } finally {
        outputLock.unlock();
        IOUtils.closeQuietly(oldWriter);
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:20,代码来源:SupportLogHandler.java

示例5: call

import hudson.util.IOUtils; //导入方法依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
        value = {"NP_LOAD_OF_KNOWN_NULL_VALUE"},
        justification = "Findbugs mis-diagnosing closeQuietly's built-in null check"
)
public String call() throws RuntimeException {
    InputStream is = null;
    try {
        is = hudson.remoting.Channel.class.getResourceAsStream("/jenkins/remoting/jenkins-version.properties");
        if (is == null) {
            return "N/A";
        }
        Properties properties = new Properties();
        try {
            properties.load(is);
            return properties.getProperty("version", "N/A");
        } catch (IOException e) {
            return "N/A";
        }
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:23,代码来源:AboutJenkins.java

示例6: getJSONFile

import hudson.util.IOUtils; //导入方法依赖的package包/类
/**
 * @param fileDestination destination of file on local dist
 * @return String with contents of file
 * @throws IOException file was not found
 */
@JavaScriptMethod
private String getJSONFile(String fileDestination) throws IOException {
    FileInputStream inputStream = null;
    try {
        File jsonFile = new File(fileDestination);
        inputStream = new FileInputStream(jsonFile);
        return IOUtils.toString(inputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
 
开发者ID:ederst,项目名称:ccr-parameter-plugin,代码行数:17,代码来源:DynamicConfigurationDefinition.java

示例7: close

import hudson.util.IOUtils; //导入方法依赖的package包/类
@Override
public void close() throws SecurityException {
    outputLock.lock();
    try {
        if (writer != null) {
            IOUtils.closeQuietly(writer);
            writer = null;
        }
    } finally {
        outputLock.unlock();
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:13,代码来源:SupportLogHandler.java

示例8: setFile

import hudson.util.IOUtils; //导入方法依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
        value = {"RV_RETURN_VALUE_IGNORED_BAD_PRACTICE", "DM_DEFAULT_ENCODING"},
        justification = "Best effort"
)
private void setFile(File file) throws FileNotFoundException {
    outputLock.lock();
    try {
        if (file == null) {
            setWriter(null);
            return;
        }
        final File parentFile = file.getParentFile();
        if (parentFile != null) {
            parentFile.mkdirs();
        }
        boolean success = false;
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        OutputStreamWriter writer = null;
        try {
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            try {
                writer = new OutputStreamWriter(bos, "utf-8");
            } catch (UnsupportedEncodingException e) {
                writer = new OutputStreamWriter(bos); // fall back to something sensible
            }
            setWriter(writer);
            fileCount = 0;
            success = true;
        } finally {
            if (!success) {
                IOUtils.closeQuietly(writer);
                IOUtils.closeQuietly(bos);
                IOUtils.closeQuietly(fos);
            }
        }
    } finally {
        outputLock.unlock();
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:42,代码来源:SupportLogHandler.java

示例9: doRun

import hudson.util.IOUtils; //导入方法依赖的package包/类
@Override
protected void doRun() throws Exception {
    if (DISABLED) {
        return;
    }

    final long now = System.currentTimeMillis();

    long iota = System.currentTimeMillis();

    final long recurrencePeriosMillis = TimeUnit.SECONDS.toMillis(RECURRENCE_PERIOD_SEC);
    long thresholdMillis = recurrencePeriosMillis > THRESHOLD ?
            recurrencePeriosMillis * 2 : THRESHOLD;

    for (InflightRequest req : filter.tracker.values()) {
        long totalTime = now - req.startTime;

        if (totalTime> thresholdMillis) {
            // if the thread has exited while we are taking the thread dump, ignore this.
            if (req.ended)    continue;

            PrintWriter w = null;
            try {
                if (req.record==null) {
                    req.record = logs.file(format.format(new Date(iota++)) + ".txt");
                    logs.add(req.record);

                    w = new PrintWriter(req.record,"UTF-8");
                    req.writeHeader(w);
                } else {
                    w = new PrintWriter(new OutputStreamWriter(new FileOutputStream(req.record,true),"UTF-8"));
                    logs.touch(req.record);
                }

                if (req.record.length() >= FileListCapComponent.MAX_FILE_SIZE)
                  continue;
                ThreadInfo lockedThread = ManagementFactory.getThreadMXBean().getThreadInfo(req.thread.getId(), Integer.MAX_VALUE);
                if (lockedThread != null ) {
                    w.println(lockedThread);
                    w.println(totalTime + "msec elapsed in " + lockedThread.getThreadName());
                    printThreadStackElements(lockedThread, w);

                    long lockOwnerId = lockedThread.getLockOwnerId();
                    if (lockOwnerId != -1) // If the thread is not locked, then getLockOwnerId returns -1.
                    {
                        ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(lockOwnerId, Integer.MAX_VALUE);
                        w.println(threadInfo);
                        if (threadInfo != null) {
                            printThreadStackElements(threadInfo, w);
                        }
                    }
                }
            } finally {
                IOUtils.closeQuietly(w);
            }
        }
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:59,代码来源:SlowRequestChecker.java

示例10: doRun

import hudson.util.IOUtils; //导入方法依赖的package包/类
@Override
protected synchronized void doRun() throws Exception {
    if (Main.isUnitTest) {
        return;
    }
    final SupportPlugin plugin = getInstance();
    if (plugin == null) {
        return;
    }
    if (nextBundleWrite.get() < System.currentTimeMillis() && AUTO_BUNDLE_PERIOD_HOURS > 0) {
        if (thread != null && thread.isAlive()) {
            logger.log(Level.INFO, "Periodic bundle generating thread is still running. Execution aborted.");
            return;
        }
        try {
            thread = new Thread(new Runnable() {
                public void run() {
                    nextBundleWrite.set(System.currentTimeMillis() + TimeUnit2.HOURS.toMillis(AUTO_BUNDLE_PERIOD_HOURS));
                    thread.setName(String.format("%s periodic bundle generator: since %s",
                            SupportPlugin.class.getSimpleName(), new Date()));
                    clearRequesterAuthentication();
                    SecurityContext old = ACL.impersonate(ACL.SYSTEM);
                    try {
                        File bundleDir = getRootDirectory();
                        if (!bundleDir.exists()) {
                            if (!bundleDir.mkdirs()) {
                                return;
                            }
                        }

                        File file = new File(bundleDir, SupportPlugin.getBundleFileName());
                        thread.setName(String.format("%s periodic bundle generator: writing %s since %s",
                                SupportPlugin.class.getSimpleName(), file.getName(), new Date()));
                        FileOutputStream fos = null;
                        try {
                            fos = new FileOutputStream(file);
                            writeBundle(fos);
                        } finally {
                            IOUtils.closeQuietly(fos);
                        }
                        cleanupOldBundles(bundleDir, file);
                    } catch (Throwable t) {
                        logger.log(Level.WARNING, "Could not save support bundle", t);
                    } finally {
                        SecurityContextHolder.setContext(old);
                    }
                }
            }, SupportPlugin.class.getSimpleName() + " periodic bundle generator");
            thread.start();
        } catch (Throwable t) {
            logger.log(Level.SEVERE, "Periodic bundle generating thread failed with error", t);
        }
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:55,代码来源:SupportPlugin.java


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