diff --git a/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java b/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java index 709e0dbf6c4b..f1a747385fbe 100644 --- a/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java +++ b/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java @@ -37,7 +37,6 @@ import org.jetbrains.annotations.NotNull; import org.junit.Assert; import java.io.File; -import java.io.FileOutputStream; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -130,13 +129,7 @@ public class OutputChecker { } if (!outFile.exists()) { - FileOutputStream fos = new FileOutputStream(outFile, false); - try { - fos.write(actual.getBytes()); - } - finally { - fos.close(); - } + FileUtil.writeToFile(outFile, actual); LOG.error("Test file created " + outFile.getPath() + "\n" + "**************** Don't forget to put it into VCS! *******************"); } else { diff --git a/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java b/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java index 7fb48b80c32e..3eae9e04f919 100644 --- a/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java +++ b/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.platform.templates.github; import com.intellij.openapi.diagnostic.Logger; @@ -186,13 +201,7 @@ public class ZipUtil { else { byte[] content = contentProcessor.processContent(FileUtil.loadBytes(entryContentStream), child); if (content != null) { - FileOutputStream fileOutputStream = new FileOutputStream(child); - try { - fileOutputStream.write(content); - } - finally { - fileOutputStream.close(); - } + FileUtil.writeToFile(child, content); } } LOG.info("Extract: " + relativeExtractPath); diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/ExternalToolContentExternalizer.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/ExternalToolContentExternalizer.java index ce28f6c2cd9a..a5d0e7d763fa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/ExternalToolContentExternalizer.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/ExternalToolContentExternalizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; /** @@ -52,14 +51,9 @@ class ExternalToolContentExternalizer implements ContentExternalizer { catch (IOException e) { tempFile = FileUtil.createTempFile(STD_PREFIX, extension); } - FileOutputStream stream = null; - try { - stream = new FileOutputStream(tempFile); - final DiffContent content = getContent(); - stream.write(myRequest instanceof MergeRequest ? content.getDocument().getText().getBytes() : content.getBytes()); - } finally { - if (stream != null) stream.close(); - } + final DiffContent content = getContent(); + byte[] bytes = myRequest instanceof MergeRequest ? content.getDocument().getText().getBytes() : content.getBytes(); + FileUtil.writeToFile(tempFile, bytes); return tempFile; } diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index 5a1b2106ac44..f0027b5a7df3 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -1247,7 +1247,10 @@ public class FileUtil extends FileUtilRt { } public static void writeToFile(@NotNull File file, @NotNull String text) throws IOException { - writeToFile(file, text.getBytes(CharsetToolkit.UTF8_CHARSET), false); + writeToFile(file, text, false); + } + public static void writeToFile(@NotNull File file, @NotNull String text, boolean append) throws IOException { + writeToFile(file, text.getBytes(CharsetToolkit.UTF8_CHARSET), append); } public static void writeToFile(@NotNull File file, @NotNull byte[] text, int off, int len) throws IOException { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java index a1be75afdf93..fb70a90f375b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,7 @@ import com.intellij.openapi.util.Clock; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.actions.AnnotateRevisionActionBase; @@ -88,7 +89,6 @@ import java.awt.event.InputEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.*; import java.util.List; @@ -1063,13 +1063,7 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton { } private void writeContentToIOFile(byte[] revisionContent) throws IOException { - FileOutputStream outputStream = new FileOutputStream(getIOFile()); - try { - outputStream.write(revisionContent); - } - finally { - outputStream.close(); - } + FileUtil.writeToFile(getIOFile(), revisionContent); } private void writeContentToDocument(final Document document, byte[] revisionContent) throws IOException { diff --git a/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java b/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java index 14ba949ec5ae..6a0171eb2204 100644 --- a/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java +++ b/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java @@ -26,9 +26,7 @@ import com.intellij.util.PathUtilRt; import com.intellij.util.io.ZipUtil; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -284,13 +282,7 @@ public abstract class AbstractJavaFxPackager { try { File tempFile = FileUtil.createTempFile("build", ".xml"); tempFile.deleteOnExit(); - OutputStream outputStream = new FileOutputStream(tempFile.getAbsolutePath()); - try { - outputStream.write(buildText.getBytes(Charset.defaultCharset())); - } - finally { - outputStream.close(); - } + FileUtil.writeToFile(tempFile, buildText.getBytes(Charset.defaultCharset())); commands.add(tempFile.getCanonicalPath()); } catch (IOException e) { diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/make/PreviewNestedFormLoader.java b/plugins/ui-designer/src/com/intellij/uiDesigner/make/PreviewNestedFormLoader.java index 4ee096e4d9c8..e91f734fe805 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/make/PreviewNestedFormLoader.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/make/PreviewNestedFormLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package com.intellij.uiDesigner.make; import com.intellij.compiler.PsiClassWriter; import com.intellij.compiler.instrumentation.InstrumentationClassFinder; import com.intellij.openapi.module.Module; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.uiDesigner.actions.PreviewFormAction; import com.intellij.uiDesigner.compiler.AsmCodeGenerator; import com.intellij.uiDesigner.compiler.CodeGenerationException; @@ -33,7 +34,6 @@ import org.jetbrains.org.objectweb.asm.Opcodes; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.Set; @@ -87,12 +87,6 @@ public class PreviewNestedFormLoader extends PsiNestedFormLoader { throw new CodeGenerationException(errors [0].getComponentId(), errors [0].getErrorMessage()); } - FileOutputStream fos = new FileOutputStream(new File(myTempPath, generatedClassName + ".class")); - try { - fos.write(data); - } - finally { - fos.close(); - } + FileUtil.writeToFile(new File(myTempPath, generatedClassName + ".class"), data); } } diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java index c12096a83fe7..04dbb4c2d152 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +57,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.util.*; @@ -379,13 +378,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat File res = new File(resPath); - FileOutputStream out = new FileOutputStream(res); - try { - out.write(result.bytes); - } - finally { - out.close(); - } + FileUtil.writeToFile(res, result.bytes); return resPath; } diff --git a/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java b/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java index 57f53d77b23e..96814e7e864b 100644 --- a/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java +++ b/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ import org.jetbrains.annotations.Nullable; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.LinkedList; import java.util.List; @@ -158,18 +157,11 @@ public class GenerateInstanceDocumentFromSchemaAction extends AnAction { final VirtualFile baseDirForCreatedInstanceDocument1 = relativeFileDir; String xmlFileName = baseDirForCreatedInstanceDocument1.getPath() + File.separatorChar + dialog.getOutputFileName(); - FileOutputStream fileOutputStream; try { - fileOutputStream = new FileOutputStream(xmlFileName); - try { // the generated XML doesn't have any XML declaration -> utf-8 - fileOutputStream.write(xml.getBytes("utf-8")); - } - finally { - fileOutputStream.close(); - } - final File xmlFile = new File(xmlFileName); + FileUtil.writeToFile(xmlFile, xml); + VirtualFile virtualFile = ApplicationManager.getApplication().runWriteAction(new Computable() { @Override @Nullable diff --git a/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java b/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java index d263c5d44f5c..6736abbe4fe6 100644 --- a/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java +++ b/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java @@ -39,7 +39,6 @@ import com.intellij.xml.util.XmlTagUtil; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.util.Arrays; @@ -911,10 +910,7 @@ public class XmlTagTest extends LightCodeInsightTestCase { String text = " "; final File tempFile = FileUtil.createTempFile("idea-test", ".xml"); tempFile.createNewFile(); - final FileOutputStream fileOutputStream = new FileOutputStream(tempFile); - fileOutputStream.write(text.getBytes()); - fileOutputStream.flush(); - fileOutputStream.close(); + FileUtil.writeToFile(tempFile, text); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override