Java Code Examples for com.intellij.openapi.util.io.StreamUtil#closeStream()
The following examples show how to use
com.intellij.openapi.util.io.StreamUtil#closeStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpRequests.java From leetcode-editor with Apache License 2.0 | 5 votes |
@Override public void close() { StreamUtil.closeStream(myInputStream); StreamUtil.closeStream(myReader); if (myConnection instanceof HttpURLConnection) { ((HttpURLConnection)myConnection).disconnect(); } }
Example 2
Source File: ConfirmingTrustManager.java From consulo with Apache License 2.0 | 5 votes |
private void flushKeyStore() throws Exception { FileOutputStream stream = new FileOutputStream(myPath); try { myKeyStore.store(stream, myPassword.toCharArray()); } finally { StreamUtil.closeStream(stream); } }
Example 3
Source File: HttpRequests.java From consulo with Apache License 2.0 | 5 votes |
@Override public void close() { StreamUtil.closeStream(myInputStream); StreamUtil.closeStream(myReader); if (myConnection instanceof HttpURLConnection) { ((HttpURLConnection)myConnection).disconnect(); } }
Example 4
Source File: AbstractModelBuilderTest.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@Before public void setUp() throws Exception { assumeThat(gradleVersion, versionMatcherRule.getMatcher()); ensureTempDirCreated(); String methodName = name.getMethodName(); Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName); if (m.matches()) { methodName = m.group(1); } testDir = new File(ourTempDir, methodName); FileUtil.ensureExists(testDir); final InputStream buildScriptStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME); try { FileUtil.writeToFile( new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME), FileUtil.loadTextAndClose(buildScriptStream) ); } finally { StreamUtil.closeStream(buildScriptStream); } final InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME); try { if(settingsStream != null) { FileUtil.writeToFile( new File(testDir, GradleConstants.SETTINGS_FILE_NAME), FileUtil.loadTextAndClose(settingsStream) ); } } finally { StreamUtil.closeStream(settingsStream); } GradleConnector connector = GradleConnector.newConnector(); GradleVersion _gradleVersion = GradleVersion.version(gradleVersion); final URI distributionUri = new DistributionLocator().getDistributionFor(_gradleVersion); connector.useDistribution(distributionUri); connector.forProjectDirectory(testDir); int daemonMaxIdleTime = 10; try { daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10")); } catch (NumberFormatException ignore) {} ((DefaultGradleConnector)connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS); ProjectConnection connection = connector.connect(); try { boolean isGradleProjectDirSupported = _gradleVersion.compareTo(GradleVersion.version("2.4")) >= 0; boolean isCompositeBuildsSupported = isGradleProjectDirSupported && _gradleVersion.compareTo(GradleVersion.version("3.1")) >= 0; final ProjectImportAction projectImportAction = new ProjectImportAction(false, isGradleProjectDirSupported, isCompositeBuildsSupported); projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); assertNotNull(initScript); String jdkHome = IdeaTestUtil.requireRealJdkHome(); buildActionExecutor.setJavaHome(new File(jdkHome)); buildActionExecutor.setJvmArguments("-Xmx128m", "-XX:MaxPermSize=64m"); buildActionExecutor.withArguments("--info", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath()); allModels = buildActionExecutor.run(); assertNotNull(allModels); } finally { connection.close(); } }
Example 5
Source File: ZipUtil.java From consulo with Apache License 2.0 | 4 votes |
public static boolean addFileToZip(@Nonnull ZipOutputStream zos, @Nonnull File file, @Nonnull String relativeName, @Nullable Set<String> writtenItemRelativePaths, @Nullable FileFilter fileFilter, @Nonnull FileContentProcessor contentProcessor) throws IOException { while (relativeName.length() != 0 && relativeName.charAt(0) == '/') { relativeName = relativeName.substring(1); } boolean isDir = file.isDirectory(); if (isDir && !StringUtil.endsWithChar(relativeName, '/')) { relativeName += "/"; } if (fileFilter != null && !FileUtil.isFilePathAcceptable(file, fileFilter)) return false; if (writtenItemRelativePaths != null && !writtenItemRelativePaths.add(relativeName)) return false; if (LOG.isDebugEnabled()) { LOG.debug("Add " + file + " as " + relativeName); } long size = isDir ? 0 : file.length(); ZipEntry e = new ZipEntry(relativeName); e.setTime(file.lastModified()); if (size == 0) { e.setMethod(ZipEntry.STORED); e.setSize(0); e.setCrc(0); } zos.putNextEntry(e); if (!isDir) { InputStream is = null; try { is = contentProcessor.getContent(file); FileUtil.copy(is, zos); } finally { StreamUtil.closeStream(is); } } zos.closeEntry(); return true; }