mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Do not use ambiguous String.getBytes(), use FileUtil.writeFile
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+4
-10
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
-9
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+3
-11
@@ -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<VirtualFile>() {
|
||||
@Override
|
||||
@Nullable
|
||||
|
||||
@@ -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 = "<wpd><methods> </methods></wpd>";
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user