From a9621dba5bc8e5a9a812339b787a5f1cdef7d3c7 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 23 Nov 2017 19:01:37 +0100 Subject: [PATCH] [jps] uses NIO in Java module index ... because of better diagnostics --- .../model/java/impl/JavaModuleIndexImpl.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleIndexImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleIndexImpl.java index ec756866c6fb..6fc89eb61b6d 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleIndexImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleIndexImpl.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.java.impl; import com.intellij.openapi.util.io.FileUtil; @@ -30,6 +16,8 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRoot; import org.jetbrains.jps.util.JpsPathUtil; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; import java.util.Map; import java.util.Properties; @@ -104,22 +92,22 @@ public class JavaModuleIndexImpl extends JpsElementBase imp p.setProperty(key, path != null ? FileUtil.toSystemDependentName(path) : NULL_PATH); } - File index = new File(storageRoot, INDEX_PATH); - FileUtil.createParentDirs(index); + Path index = new File(storageRoot, INDEX_PATH).toPath(); + Files.createDirectories(index.getParent()); - try (Writer writer = new OutputStreamWriter(new FileOutputStream(index), CharsetToolkit.UTF8_CHARSET)) { + try (Writer writer = Files.newBufferedWriter(index, CharsetToolkit.UTF8_CHARSET)) { p.store(writer, null); } } public static JavaModuleIndex load(@NotNull File storageRoot, @NotNull JpsCompilerExcludes excludes) { - File index = new File(storageRoot, INDEX_PATH); - if (!index.exists()) { + Path index = new File(storageRoot, INDEX_PATH).toPath(); + if (!Files.exists(index)) { return new JavaModuleIndexImpl(excludes); } Properties p = new Properties(); - try (Reader reader = new InputStreamReader(new FileInputStream(index), CharsetToolkit.UTF8_CHARSET)) { + try (Reader reader = Files.newBufferedReader(index, CharsetToolkit.UTF8_CHARSET)) { p.load(reader); } catch (IOException e) {