本文整理汇总了Java中jetbrains.buildServer.util.FileUtil.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.close方法的具体用法?Java FileUtil.close怎么用?Java FileUtil.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jetbrains.buildServer.util.FileUtil
的用法示例。
在下文中一共展示了FileUtil.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeToTempFile
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
@NotNull
private File writeToTempFile(@NotNull final File buildTempDir,
@NotNull final String text,
@NotNull final Map<String, String> runnerParameters) throws RunBuildException {
Closeable handle = null;
File file;
try {
file = FileUtil.createTempFile(buildTempDir, "powershell", ".ps1", true);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
handle = w;
if (PowerShellExecutionMode.PS1 == PowerShellExecutionMode.fromString(runnerParameters.get(RUNNER_EXECUTION_MODE))) {
w.write(BOM);
}
w.write(text);
return file;
} catch (IOException e) {
LOG.error("Error occurred while processing file for PowerShell script", e);
throw new RunBuildException("Failed to generate temporary resulting PowerShell script due to exception", e);
} finally {
FileUtil.close(handle);
}
}
示例2: download
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
protected byte[] download(final String urlString) throws IOException {
final HttpMethod getMethod = new GetMethod(urlString);
InputStream in = null;
try {
myHttpClient.executeMethod(getMethod);
if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
throw new IOException(String.format("Problem [%d] while downloading %s: %s", getMethod.getStatusCode(), urlString, getMethod.getStatusText()));
}
in = getMethod.getResponseBodyAsStream();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
StreamUtil.copyStreamContent(in, bOut);
return bOut.toByteArray();
} finally {
FileUtil.close(in);
getMethod.releaseConnection();
}
}
示例3: loadConfiguration
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
private void loadConfiguration(@NotNull File configFile) {
Properties properties = new Properties();
FileReader fileReader = null;
try {
fileReader = new FileReader(configFile);
properties.load(fileReader);
if (properties.get(DOWNLOAD_ENABLED) == null) {
properties.put(DOWNLOAD_ENABLED, Boolean.FALSE.toString());
}
myConfiguration = properties;
} catch (IOException e) {
Loggers.SERVER.warn("Failed to load configuration file: " + configFile.getAbsolutePath() + ", error: " + e.toString());
} finally {
FileUtil.close(fileReader);
}
}
示例4: loadDb
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
private void loadDb() throws IOException {
// expecting rows to be sorted from oldest to newest,
// then if max torrents limit is decreased newest entries will remove oldest in the cache automatically
BufferedReader reader = null;
try {
InputStreamReader isReader = new InputStreamReader(new FileInputStream(myTorrentsDbFile), ENCODING);
reader = new BufferedReader(isReader);
String line;
while ((line = reader.readLine()) != null) {
List<String> paths = StringUtil.split(line, SEPARATOR);
if (paths.size() != 2) continue;
File srcFile = myPathConverter.convertToFile(paths.get(0));
File torrentFile = myPathConverter.convertToFile(paths.get(1));
addFileAndTorrent(srcFile, torrentFile);
}
} catch (FileNotFoundException e) {
// no database on disk
} finally {
FileUtil.close(reader);
}
}
示例5: upload
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
private int upload(Map<File, String> filePathMap, SmbFile destination) throws IOException {
int count = 0;
for (Map.Entry<File, String> fileDestEntry : filePathMap.entrySet()) {
checkIsInterrupted();
final File source = fileDestEntry.getKey();
final String targetPath = fileDestEntry.getValue();
final SmbFile destDirectory;
if (StringUtil.isEmpty(targetPath)) {
destDirectory = destination;
} else {
destDirectory = new SmbFile(destination, targetPath + "/");
}
final SmbFile destFile = new SmbFile(destDirectory, source.getName());
Loggers.AGENT.debug("Uploading source=[" + source.getAbsolutePath() + "] to \n" +
"destDirectory=[" + destDirectory.getCanonicalPath() +
"] destFile=[" + destFile.getCanonicalPath() + "]");
FileInputStream inputStream = null;
OutputStream outputStream = null;
LOG.debug("Transferring [" + source.getAbsolutePath() + "] to [" + destDirectory.getCanonicalPath() + "] destFile=[" + destFile.getCanonicalPath() + "]");
try {
if (!destDirectory.exists()) {
destDirectory.mkdirs();
}
inputStream = new FileInputStream(source);
outputStream = destFile.getOutputStream();
copyInterruptibly(inputStream, outputStream);
outputStream.flush();
} finally {
FileUtil.close(inputStream);
FileUtil.close(outputStream);
}
LOG.debug("Done transferring [" + source.getAbsolutePath() + "]");
count++;
}
return count;
}
示例6: execute
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
@Override
public void execute(@NotNull final OutputStream out,
@NotNull final InputStream in) throws IOException {
final String command = "C0755 " + myFile.length() + " " + myFile.getName() + "\n";
out.write(command.getBytes());
out.flush();
ScpExecUtil.checkScpAck(in);
// send the content
FileInputStream fis = null;
byte[] buf = new byte[1024];
try {
fis = new FileInputStream(myFile);
while (true) {
int len = fis.read(buf, 0, buf.length);
if (len <= 0) break;
out.write(buf, 0, len); //out.flush();
}
} finally {
FileUtil.close(fis);
}
// send '\0'
buf[0] = 0;
out.write(buf, 0, 1);
out.flush();
ScpExecUtil.checkScpAck(in);
}
示例7: loadParserFromFile
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
@NotNull
public static RegexParser loadParserFromFile(@NotNull final File file) throws FileNotFoundException, ParserLoadingException {
if (file.exists() && file.isFile()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
return ParserLoader.loadParser(fis);
} finally {
FileUtil.close(fis);
}
}
throw new FileNotFoundException(file.getAbsolutePath());
}
示例8: doHandle
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
@Override
protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception {
String buildIdParam = request.getParameter("buildId");
String path = request.getParameter("file");
String torrentPath = path + TorrentUtil.TORRENT_FILE_SUFFIX;
File torrentFile = null;
long buildId = Long.parseLong(buildIdParam);
SBuild build = myBuildsManager.findBuildInstanceById(buildId);
if (build != null) {
torrentFile = myTorrentsManager.getTorrentFile(build, torrentPath);
if (!torrentFile.isFile()) {
torrentFile = null;
}
}
if (torrentFile == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
response.setContentType(WebUtil.getMimeType(request, torrentFile.getName()));
// force set content-disposition to attachment
WebUtil.setContentDisposition(request, response, torrentFile.getName(), false);
ServletOutputStream output = response.getOutputStream();
FileInputStream fis = null;
try {
fis = new FileInputStream(torrentFile);
StreamUtil.copyStreamContent(fis, output);
} finally {
FileUtil.close(fis);
output.close();
}
}
return null;
}
示例9: flush
import jetbrains.buildServer.util.FileUtil; //导入方法依赖的package包/类
public void flush() throws IOException {
File parentFile = myTorrentsDbFile.getParentFile();
if (!parentFile.isDirectory() && !parentFile.mkdirs()) {
throw new IOException("Failed to create directory for torrent database file: " + myTorrentsDbFile.getAbsolutePath());
}
PrintWriter writer = null;
try {
OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(myTorrentsDbFile), ENCODING);
writer = new PrintWriter(osWriter);
List<FileInfo> sorted = getSortedKeys();
synchronized (myFile2TorrentMap) {
for (FileInfo srcFile : sorted) {
final FileInfo torrentFile = myFile2TorrentMap.get().get(srcFile);
if (torrentFile == null) continue;
String srcPath = srcFile.myPath;
String torrentPath = torrentFile.myPath;
writer.print(srcPath);
writer.print(SEPARATOR);
writer.print(torrentPath);
writer.println();
}
}
} finally {
FileUtil.close(writer);
}
}