mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup: migrate code to use 'try' with resources
It became possible after these modules were migrated to Java 7 (IDEA-297573). GitOrigin-RevId: 4899ecf2fcd6715e7e746f0ec5803b5e35756bb1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6509b82b27
commit
abaa3dd03f
@@ -69,8 +69,7 @@ public final class CommandLineWrapper {
|
||||
List<String> properties = Collections.emptyList();
|
||||
String[] mainArgs;
|
||||
|
||||
JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile));
|
||||
try {
|
||||
try (JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile))) {
|
||||
Manifest manifest = inputStream.getManifest();
|
||||
|
||||
String vmOptions = manifest != null ? manifest.getMainAttributes().getValue("VM-Options") : null;
|
||||
@@ -88,7 +87,6 @@ public final class CommandLineWrapper {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
jarFile.deleteOnExit();
|
||||
}
|
||||
|
||||
@@ -194,15 +192,13 @@ public final class CommandLineWrapper {
|
||||
|
||||
/** @noinspection ResultOfMethodCallIgnored */
|
||||
private static List<String> readLinesAndDeleteFile(File file) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||
try {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) lines.add(line);
|
||||
return lines;
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,8 @@ public final class AppMainV2 {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Socket client = new Socket("127.0.0.1", portNumber);
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "US-ASCII"));
|
||||
try {
|
||||
try (Socket client = new Socket("127.0.0.1", portNumber)) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "US-ASCII"))) {
|
||||
while (true) {
|
||||
String msg = reader.readLine();
|
||||
if (msg == null || "TERM".equals(msg)) {
|
||||
@@ -66,12 +64,6 @@ public final class AppMainV2 {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ignored) { }
|
||||
|
||||
@@ -149,13 +149,9 @@ public class ComparisonFailureData {
|
||||
try {
|
||||
//noinspection SSBasedInspection
|
||||
File tempFile = File.createTempFile(expectedOrActualPrefix, "");
|
||||
OutputStream stream = new FileOutputStream(tempFile);
|
||||
try {
|
||||
try (OutputStream stream = new FileOutputStream(tempFile)) {
|
||||
stream.write(text.getBytes(StandardCharsets.UTF_8), 0, text.length());
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
attrs.put(expectedOrActualPrefix + "File", tempFile.getAbsolutePath());
|
||||
attrs.put(expectedOrActualPrefix + "IsTempFile", "true");
|
||||
return;
|
||||
|
||||
+6
-16
@@ -88,13 +88,9 @@ public abstract class ForkedByModuleSplitter {
|
||||
if ("ARGS_FILE".equals(myDynamicClasspath)) {
|
||||
File argFile = File.createTempFile("arg_file", null);
|
||||
argFile.deleteOnExit();
|
||||
FileOutputStream writer = new FileOutputStream(argFile);
|
||||
try {
|
||||
try (FileOutputStream writer = new FileOutputStream(argFile)) {
|
||||
writer.write(classpath.getBytes(Charset.defaultCharset()));
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
builder.add("@" + argFile.getAbsolutePath());
|
||||
}
|
||||
else {
|
||||
@@ -131,17 +127,13 @@ public abstract class ForkedByModuleSplitter {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
try {
|
||||
try (BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
while (true) {
|
||||
String line = inputReader.readLine();
|
||||
if (line == null) break;
|
||||
outputStream.println(line);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
inputReader.close();
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException ignored) { }
|
||||
catch (IOException e) {
|
||||
@@ -154,8 +146,7 @@ public abstract class ForkedByModuleSplitter {
|
||||
//read file with classes grouped by module
|
||||
protected int splitPerModule(String repeatCount) throws IOException {
|
||||
int result = 0;
|
||||
final BufferedReader perDirReader = new BufferedReader(new FileReader(myWorkingDirsPath));
|
||||
try {
|
||||
try (BufferedReader perDirReader = new BufferedReader(new FileReader(myWorkingDirsPath))) {
|
||||
final String packageName = perDirReader.readLine();
|
||||
String workingDir;
|
||||
while ((workingDir = perDirReader.readLine()) != null) {
|
||||
@@ -186,7 +177,9 @@ public abstract class ForkedByModuleSplitter {
|
||||
}
|
||||
|
||||
String filters = perDirReader.readLine();
|
||||
final int childResult = startPerModuleFork(moduleName, classNames, packageName, workingDir, classpath, moduleOptions, repeatCount, result, filters != null ? filters : "");
|
||||
final int childResult =
|
||||
startPerModuleFork(moduleName, classNames, packageName, workingDir, classpath, moduleOptions, repeatCount, result,
|
||||
filters != null ? filters : "");
|
||||
result = Math.min(childResult, result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -194,9 +187,6 @@ public abstract class ForkedByModuleSplitter {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
perDirReader.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -16,8 +16,7 @@ public class ForkedDebuggerHelper {
|
||||
|
||||
// copied from NetUtils
|
||||
protected static int findAvailableSocketPort() throws IOException {
|
||||
final ServerSocket serverSocket = new ServerSocket(0);
|
||||
try {
|
||||
try (ServerSocket serverSocket = new ServerSocket(0)) {
|
||||
int port = serverSocket.getLocalPort();
|
||||
// workaround for linux : calling close() immediately after opening socket
|
||||
// may result that socket is not closed
|
||||
@@ -33,9 +32,6 @@ public class ForkedDebuggerHelper {
|
||||
}
|
||||
return port;
|
||||
}
|
||||
finally {
|
||||
serverSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setupDebugger(List<String> parameters) throws IOException {
|
||||
|
||||
@@ -73,13 +73,9 @@ public final class BinaryContent {
|
||||
}
|
||||
|
||||
private static void _writeToFile(final File file, BinaryContent content) throws IOException {
|
||||
final OutputStream stream = new FileOutputStream(file);
|
||||
try {
|
||||
try (OutputStream stream = new FileOutputStream(file)) {
|
||||
stream.write(content.getBuffer(), content.getOffset(), content.getLength());
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,10 +61,8 @@ public abstract class JpsFileObject extends SimpleJavaFileObject {
|
||||
@NotNull
|
||||
protected static CharSequence loadCharContent(@NotNull File file, @Nullable String encoding) throws IOException {
|
||||
// FileUtil.loadText clones char array if length mismatch
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
final Reader reader = encoding == null ? new InputStreamReader(stream) : new InputStreamReader(stream, encoding);
|
||||
try {
|
||||
try (FileInputStream stream = new FileInputStream(file)) {
|
||||
try (Reader reader = encoding == null ? new InputStreamReader(stream) : new InputStreamReader(stream, encoding)) {
|
||||
// channel allows to avoid extra call to get file size because fd is reused, see Files.readAllBytes
|
||||
char[] chars = new char[(int)stream.getChannel().size()];
|
||||
int count = 0;
|
||||
@@ -77,12 +75,6 @@ public abstract class JpsFileObject extends SimpleJavaFileObject {
|
||||
}
|
||||
return CharBuffer.wrap(chars, 0, count);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,18 +102,10 @@ public final class ZipFileObject extends JpsFileObject {
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
|
||||
// todo: consider adding content caching if needed
|
||||
// todo: currently ignoreEncodingErrors is not honored. Do we actually need to support it?
|
||||
final InputStream in = openInputStream();
|
||||
try {
|
||||
final InputStreamReader reader = myEncoding != null ? new InputStreamReader(in, myEncoding) : new InputStreamReader(in);
|
||||
try {
|
||||
try (InputStream in = openInputStream()) {
|
||||
try (InputStreamReader reader = myEncoding != null ? new InputStreamReader(in, myEncoding) : new InputStreamReader(in)) {
|
||||
return CharBuffer.wrap(FileUtilRt.loadText(reader, (int)myEntry.getSize()));
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -52,13 +52,9 @@ public class ExternalSystemException extends RuntimeException {
|
||||
}
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(stringWriter);
|
||||
try {
|
||||
try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
|
||||
cause.printStackTrace(printWriter);
|
||||
}
|
||||
finally {
|
||||
printWriter.close();
|
||||
}
|
||||
myOriginalReason = stringWriter.toString();
|
||||
}
|
||||
|
||||
|
||||
+3
-15
@@ -58,29 +58,20 @@ public final class ForkedDebuggerHelper {
|
||||
|
||||
private static void send(String debuggerId, String processName, String processParameters, int dispatchPort) throws IOException {
|
||||
String dispatchAddr = getAddrFromProperty();
|
||||
Socket socket = new Socket(dispatchAddr, dispatchPort);
|
||||
try {
|
||||
DataOutputStream stream = new DataOutputStream(socket.getOutputStream());
|
||||
try {
|
||||
try (Socket socket = new Socket(dispatchAddr, dispatchPort)) {
|
||||
try (DataOutputStream stream = new DataOutputStream(socket.getOutputStream())) {
|
||||
stream.writeUTF(debuggerId);
|
||||
stream.writeUTF(processName);
|
||||
stream.writeUTF(processParameters);
|
||||
// wait for the signal handling
|
||||
int read = socket.getInputStream().read();
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
// copied from NetUtils
|
||||
private static int findAvailableSocketPort() throws IOException {
|
||||
final ServerSocket serverSocket = new ServerSocket(0);
|
||||
try {
|
||||
try (ServerSocket serverSocket = new ServerSocket(0)) {
|
||||
int port = serverSocket.getLocalPort();
|
||||
// workaround for linux : calling close() immediately after opening socket
|
||||
// may result that socket is not closed
|
||||
@@ -101,9 +92,6 @@ public final class ForkedDebuggerHelper {
|
||||
|
||||
return port;
|
||||
}
|
||||
finally {
|
||||
serverSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAddrFromProperty() {
|
||||
|
||||
@@ -627,24 +627,18 @@ public class FileUtilRt {
|
||||
@NotNull
|
||||
public static char[] loadFileText(@NotNull File file, @Nullable String encoding) throws IOException {
|
||||
InputStream stream = new FileInputStream(file);
|
||||
Reader reader = encoding == null ? new InputStreamReader(stream, Charset.defaultCharset()) : new InputStreamReader(stream, encoding);
|
||||
try {
|
||||
try (Reader reader = encoding == null
|
||||
? new InputStreamReader(stream, Charset.defaultCharset())
|
||||
: new InputStreamReader(stream, encoding)) {
|
||||
return loadText(reader, (int)file.length());
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static char[] loadFileText(@NotNull File file, @NotNull Charset encoding) throws IOException {
|
||||
Reader reader = new InputStreamReader(new FileInputStream(file), encoding);
|
||||
try {
|
||||
try (Reader reader = new InputStreamReader(new FileInputStream(file), encoding)) {
|
||||
return loadText(reader, (int)file.length());
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -682,14 +676,10 @@ public class FileUtilRt {
|
||||
@NotNull
|
||||
public static List<String> loadLines(@NotNull String path, @Nullable String encoding) throws IOException {
|
||||
InputStream stream = new FileInputStream(path);
|
||||
BufferedReader reader =
|
||||
new BufferedReader(encoding == null ? new InputStreamReader(stream, Charset.defaultCharset()) : new InputStreamReader(stream, encoding));
|
||||
try {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
encoding == null ? new InputStreamReader(stream, Charset.defaultCharset()) : new InputStreamReader(stream, encoding))) {
|
||||
return loadLines(reader);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -925,18 +915,10 @@ public class FileUtilRt {
|
||||
return;
|
||||
}
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(toFile);
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(fromFile);
|
||||
try {
|
||||
try (FileOutputStream fos = new FileOutputStream(toFile)) {
|
||||
try (FileInputStream fis = new FileInputStream(fromFile)) {
|
||||
copy(fis, fos);
|
||||
}
|
||||
finally {
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
fos.close();
|
||||
}
|
||||
|
||||
long timeStamp = fromFile.lastModified();
|
||||
@@ -950,18 +932,10 @@ public class FileUtilRt {
|
||||
|
||||
public static void copy(@NotNull InputStream inputStream, @NotNull OutputStream outputStream) throws IOException {
|
||||
if (USE_FILE_CHANNELS && inputStream instanceof FileInputStream && outputStream instanceof FileOutputStream) {
|
||||
FileChannel fromChannel = ((FileInputStream)inputStream).getChannel();
|
||||
try {
|
||||
FileChannel toChannel = ((FileOutputStream)outputStream).getChannel();
|
||||
try {
|
||||
try (FileChannel fromChannel = ((FileInputStream)inputStream).getChannel()) {
|
||||
try (FileChannel toChannel = ((FileOutputStream)outputStream).getChannel()) {
|
||||
fromChannel.transferTo(0, Long.MAX_VALUE, toChannel);
|
||||
}
|
||||
finally {
|
||||
toChannel.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
fromChannel.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -9,9 +9,8 @@ import java.util.Map;
|
||||
|
||||
public final class ReadEnv {
|
||||
public static void main(String[] args) throws Exception {
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr") Writer out = new BufferedWriter(new OutputStreamWriter(System.out,
|
||||
StandardCharsets.UTF_8));
|
||||
try {
|
||||
try (Writer out = new BufferedWriter(new OutputStreamWriter(System.out,
|
||||
StandardCharsets.UTF_8))) {
|
||||
for (Map.Entry<String, String> each : System.getenv().entrySet()) {
|
||||
// On Windows, the environment may include variables that start with '=' (https://stackoverflow.com/questions/30102750).
|
||||
// Such variables break the output parser and are unimportant, hence are filtered out.
|
||||
@@ -23,8 +22,5 @@ public final class ReadEnv {
|
||||
out.write('\0');
|
||||
}
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-8
@@ -105,9 +105,7 @@ public final class CucumberJvmSMFormatterUtil {
|
||||
|
||||
private static String readLineWithNumber(String filePath, int lineNumber) throws IOException {
|
||||
int currentLineNumber = 0;
|
||||
FileReader fileStream = null;
|
||||
try {
|
||||
fileStream = new FileReader(filePath);
|
||||
try (FileReader fileStream = new FileReader(filePath)) {
|
||||
BufferedReader bufferedReader = new BufferedReader(fileStream);
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
@@ -117,11 +115,6 @@ public final class CucumberJvmSMFormatterUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (fileStream != null) {
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-10
@@ -13,8 +13,7 @@ public final class DefaultSerializationService implements SerializationService {
|
||||
@Override
|
||||
public byte[] write(Object object, Class modelClazz) throws IOException {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ObjectOutput outputStream = new ObjectOutputStream(os);
|
||||
try {
|
||||
try (ObjectOutput outputStream = new ObjectOutputStream(os)) {
|
||||
outputStream.writeObject(object);
|
||||
}
|
||||
catch (NotSerializableException e) {
|
||||
@@ -22,24 +21,17 @@ public final class DefaultSerializationService implements SerializationService {
|
||||
"Implement Serializable or provide related org.jetbrains.plugins.gradle.tooling.serialization.SerializationService for the tooling model: '%s'",
|
||||
object.getClass().getName()), e);
|
||||
}
|
||||
finally {
|
||||
outputStream.close();
|
||||
}
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(byte[] object, final Class modelClazz) throws IOException {
|
||||
ObjectInput inputStream = new ClassLoaderObjectInputStream(modelClazz.getClassLoader(), new ByteArrayInputStream(object));
|
||||
try {
|
||||
try (ObjectInput inputStream = new ClassLoaderObjectInputStream(modelClazz.getClassLoader(), new ByteArrayInputStream(object))) {
|
||||
return inputStream.readObject();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -30,25 +30,17 @@ public final class AnnotationProcessingModelSerializationService implements Seri
|
||||
public byte[] write(AnnotationProcessingModel annotationProcessingModel, Class<? extends AnnotationProcessingModel> modelClazz)
|
||||
throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, annotationProcessingModel);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationProcessingModel read(byte[] object, Class<? extends AnnotationProcessingModel> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return read(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void write(final IonWriter writer, final WriteContext context, final AnnotationProcessingModel model) throws IOException {
|
||||
|
||||
+2
-10
@@ -33,25 +33,17 @@ public final class BuildScriptClasspathModelSerializationService implements Seri
|
||||
@Override
|
||||
public byte[] write(BuildScriptClasspathModel classpathModel, Class<? extends BuildScriptClasspathModel> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, classpathModel);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildScriptClasspathModel read(byte[] object, Class<? extends BuildScriptClasspathModel> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return read(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -36,25 +36,17 @@ public final class ExternalProjectSerializationService implements SerializationS
|
||||
@Override
|
||||
public byte[] write(ExternalProject project, Class<? extends ExternalProject> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out)) {
|
||||
writeProject(writer, myWriteContext, project);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalProject read(byte[] object, Class<? extends ExternalProject> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return readProject(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -32,25 +32,17 @@ public final class ExternalTestsSerializationService implements SerializationSer
|
||||
@Override
|
||||
public byte[] write(ExternalTestsModel testsModel, Class<? extends ExternalTestsModel> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, testsModel);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalTestsModel read(byte[] object, Class<? extends ExternalTestsModel> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return read(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -28,25 +28,17 @@ public final class GradleExtensionsSerializationService implements Serialization
|
||||
@Override
|
||||
public byte[] write(GradleExtensions gradleExtensions, Class<? extends GradleExtensions> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, gradleExtensions);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GradleExtensions read(byte[] object, Class<? extends GradleExtensions> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return read(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -31,25 +31,17 @@ public final class ProjectDependenciesSerializationService implements Serializat
|
||||
@Override
|
||||
public byte[] write(ProjectDependencies dependencies, Class<? extends ProjectDependencies> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, dependencies);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectDependencies read(byte[] object, Class<? extends ProjectDependencies> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return read(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -32,25 +32,17 @@ public class RepositoriesModelSerializationService implements SerializationServi
|
||||
@Override
|
||||
public byte[] write(RepositoriesModel repositoriesModel, Class<? extends RepositoriesModel> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, repositoriesModel);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoriesModel read(byte[] object, Class<? extends RepositoriesModel> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
return read(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-10
@@ -48,8 +48,7 @@ public final class IdeaProjectSerializationService implements SerializationServi
|
||||
@Override
|
||||
public byte[] write(IdeaProject ideaProject, Class<? extends IdeaProject> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IonWriter writer = createIonWriter().build(out);
|
||||
try {
|
||||
try (IonWriter writer = createIonWriter().build(out)) {
|
||||
GradleVersion gradleVersion = getBuildGradleVersion(ideaProject);
|
||||
myWriteContext.setGradleVersion(gradleVersion);
|
||||
writer.stepIn(IonType.STRUCT);
|
||||
@@ -57,16 +56,12 @@ public final class IdeaProjectSerializationService implements SerializationServi
|
||||
writer.stepOut();
|
||||
writeProject(writer, myWriteContext, ideaProject);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdeaProject read(byte[] object, Class<? extends IdeaProject> modelClazz) throws IOException {
|
||||
IonReader reader = IonReaderBuilder.standard().build(object);
|
||||
try {
|
||||
try (IonReader reader = IonReaderBuilder.standard().build(object)) {
|
||||
if (reader.next() == null) return null;
|
||||
reader.stepIn();
|
||||
String gradleVersion = assertNotNull(readString(reader, "gradleVersion"));
|
||||
@@ -74,9 +69,6 @@ public final class IdeaProjectSerializationService implements SerializationServi
|
||||
myReadContext.setGradleVersion(GradleVersion.version(gradleVersion));
|
||||
return readProject(reader, myReadContext);
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -200,11 +200,8 @@ final class FileLoader extends Loader {
|
||||
|
||||
File index = getIndexFileFile();
|
||||
|
||||
DataInputStream reader = null;
|
||||
boolean isOk = false;
|
||||
|
||||
try {
|
||||
reader = new DataInputStream(new BufferedInputStream(new FileInputStream(index)));
|
||||
try (DataInputStream reader = new DataInputStream(new BufferedInputStream(new FileInputStream(index)))) {
|
||||
if (DataInputOutputUtilRt.readINT(reader) == ourVersion) {
|
||||
ClasspathCache.LoaderData loaderData = new ClasspathCache.LoaderData(reader);
|
||||
isOk = true;
|
||||
@@ -217,13 +214,6 @@ final class FileLoader extends Loader {
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
if (!isOk) {
|
||||
index.delete();
|
||||
}
|
||||
@@ -322,13 +312,9 @@ final class FileLoader extends Loader {
|
||||
@NotNull
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
InputStream stream = getInputStream();
|
||||
try {
|
||||
try (InputStream stream = getInputStream()) {
|
||||
return FileUtilRt.loadBytes(stream, (int)myFile.length());
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -242,13 +242,10 @@ class JarLoader extends Loader {
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
ZipFile file = getZipFile();
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = file.getInputStream(myEntry);
|
||||
try (InputStream stream = file.getInputStream(myEntry)) {
|
||||
return FileUtilRt.loadBytes(stream, (int)myEntry.getSize());
|
||||
}
|
||||
finally {
|
||||
if (stream != null) stream.close();
|
||||
releaseZipFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ final class SecureJarLoader extends JarLoader {
|
||||
public byte[] getBytes() throws IOException {
|
||||
JarFile file = (JarFile)getZipFile();
|
||||
try {
|
||||
InputStream stream = file.getInputStream(myEntry);
|
||||
try {
|
||||
try (InputStream stream = file.getInputStream(myEntry)) {
|
||||
byte[] result = FileUtilRt.loadBytes(stream, (int)myEntry.getSize());
|
||||
synchronized (myProtectionDomainMonitor) {
|
||||
if (myProtectionDomain == null) {
|
||||
@@ -58,9 +57,6 @@ final class SecureJarLoader extends JarLoader {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
releaseZipFile(file);
|
||||
|
||||
@@ -34,9 +34,8 @@ public final class JUnit4TestRunnerUtil {
|
||||
// all tests in the package specified
|
||||
try {
|
||||
final Map<String, Set<String>> classMethods = new HashMap<>();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(suiteClassName.substring(1)),
|
||||
StandardCharsets.UTF_8));
|
||||
try {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(suiteClassName.substring(1)),
|
||||
StandardCharsets.UTF_8))) {
|
||||
final String packageName = reader.readLine();
|
||||
if (packageName == null) return null;
|
||||
|
||||
@@ -113,9 +112,6 @@ public final class JUnit4TestRunnerUtil {
|
||||
}
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -120,13 +120,9 @@ public final class JUnitStarter {
|
||||
}
|
||||
try {
|
||||
final Socket socket = new Socket(InetAddress.getByName(host), port); //start collecting tests
|
||||
final DataInputStream os = new DataInputStream(socket.getInputStream());
|
||||
try {
|
||||
try (DataInputStream os = new DataInputStream(socket.getInputStream())) {
|
||||
os.readBoolean();//wait for ready flag
|
||||
}
|
||||
finally {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -247,9 +243,8 @@ public final class JUnitStarter {
|
||||
|
||||
public static void printClassesList(List<String> classNames, String packageName, String category, String filters, File tempFile)
|
||||
throws IOException {
|
||||
final PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8));
|
||||
|
||||
try {
|
||||
try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8))) {
|
||||
writer.println(packageName); //package name
|
||||
writer.println(category); //category
|
||||
writer.println(filters); //patterns
|
||||
@@ -257,8 +252,5 @@ public final class JUnitStarter {
|
||||
writer.println(name);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -21,13 +21,9 @@ public final class MavenModuleMap {
|
||||
String path = System.getProperty(PATHS_FILE_PROPERTY);
|
||||
if (path != null) {
|
||||
try {
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(path));
|
||||
try {
|
||||
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(path))) {
|
||||
myMap.load(in);
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// XXX log
|
||||
|
||||
@@ -43,13 +43,9 @@ public final class RemoteTestNGStarter {
|
||||
final int port = Integer.parseInt(arg.substring(SOCKET.length()));
|
||||
try {
|
||||
final Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), port); //start collecting tests
|
||||
final DataInputStream os = new DataInputStream(socket.getInputStream());
|
||||
try {
|
||||
try (DataInputStream os = new DataInputStream(socket.getInputStream())) {
|
||||
os.readBoolean();//wait for ready flag
|
||||
}
|
||||
finally {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -81,14 +81,10 @@ public final class TestNGXmlSuiteHelper {
|
||||
|
||||
public static void writeToFile(Logger logger, File xmlFile, String content) {
|
||||
try {
|
||||
OutputStream stream = new FileOutputStream(xmlFile, false);
|
||||
try {
|
||||
try (OutputStream stream = new FileOutputStream(xmlFile, false)) {
|
||||
byte[] text = content.getBytes(StandardCharsets.UTF_8);
|
||||
stream.write(text, 0, text.length);
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.log(e);
|
||||
|
||||
Reference in New Issue
Block a user