mbien commented on code in PR #7076:
URL: https://github.com/apache/netbeans/pull/7076#discussion_r1497857133
##########
apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java:
##########
@@ -103,14 +102,11 @@ public void run() {
if (packageName != null) {
String path = packageName.replace(".", "/") +
"/Bundle.properties";
mf.setAttribute("OpenIDE-Module-Localizing-Bundle", path,
null);
- BufferedOutputStream bos = null;
- try {
- bos = new BufferedOutputStream(new FileOutputStream(new
File(src, "manifest.mf")));
+ try (FileOutputStream fos = new FileOutputStream(new File(src,
"manifest.mf"));
+ BufferedOutputStream bos = new
BufferedOutputStream(fos)) {
Review Comment:
wouldn't it be easier to read to use one wrapped stream instead of two?
```java
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(new
File(src, "manifest.mf"))) {
```
or
```java
try (OutputStream os = new
BufferedOutputStream(Files.newOutputStream(Path.of(src, "manifest.mf"))) {
```
##########
java/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java:
##########
@@ -1048,24 +1046,21 @@ private File checkAvailability(String ver, VersionRange
vr, InputOutput ioput) {
LOGGER.log(Level.WARNING, "wasn''t able to download maven
binaries, version {0}", ver);
return null;
}
- str = new ZipInputStream(is);
- ZipEntry entry;
- while ((entry = str.getNextEntry()) != null) {
- //base it of f not child as the zip contains the maven
base folder
- File fileOrDir = new File(f, entry.getName());
- if (entry.isDirectory()) {
- fileOrDir.mkdirs();
- } else {
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(fileOrDir);
- FileUtil.copy(str, fos);
- } finally {
- IOUtil.close(fos);
- }
- // correct way to set executable flag?
- if ("bin".equals(fileOrDir.getParentFile().getName())
&& !fileOrDir.getName().endsWith(".conf")) {
- fileOrDir.setExecutable(true);
+ try (ZipInputStream str = new ZipInputStream(is)) {
+ ZipEntry entry;
+ while ((entry = str.getNextEntry()) != null) {
+ //base it of f not child as the zip contains the maven
base folder
+ File fileOrDir = new File(f, entry.getName());
+ if (entry.isDirectory()) {
+ fileOrDir.mkdirs();
+ } else {
+ try (FileOutputStream fos = new
FileOutputStream(fileOrDir)) {
+ FileUtil.copy(str, fos);
+ }
Review Comment:
could be replaced with:
```java
Files.copy(str, fileOrDir.toPath())
```
`fileOrDir` could be potentially converted to path from the beginning and
use `Files.createDirectories` etc.
or:
```java
in.transferTo(out);
```
what you prefer :)
##########
apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java:
##########
@@ -121,20 +117,14 @@ public void run() {
String path = packageName.replace(".", File.separator);
File res = new File(src, path);
res.mkdirs();
- OutputStream bos = null;
- try {
- bos = new BufferedOutputStream(new FileOutputStream(new
File(res, "Bundle.properties")));
+ try (FileOutputStream fos = new FileOutputStream(new File(res,
"Bundle.properties"));
+ OutputStream bos = new BufferedOutputStream(fos)) {
Review Comment:
same here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists