You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "risdenk (via GitHub)" <gi...@apache.org> on 2023/03/23 03:48:08 UTC

[GitHub] [solr] risdenk commented on a diff in pull request #1478: SOLR-16716: Replace commons-io usages with pure Java

risdenk commented on code in PR #1478:
URL: https://github.com/apache/solr/pull/1478#discussion_r1145640212


##########
solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java:
##########
@@ -93,14 +93,14 @@ private Properties makeCoreProperties(
   }
 
   private void addCoreWithProps(Properties stockProps, File propFile) throws Exception {
-    if (!propFile.getParentFile().exists()) propFile.getParentFile().mkdirs();
-    Writer out = new OutputStreamWriter(new FileOutputStream(propFile), StandardCharsets.UTF_8);
-    try {
+    if (!propFile.getParentFile().exists()) {
+      propFile.getParentFile().mkdirs();
+    }
+    try (Writer out =
+        new OutputStreamWriter(new FileOutputStream(propFile), StandardCharsets.UTF_8)) {

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



##########
solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java:
##########
@@ -42,45 +39,46 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {
 
   @BeforeClass
   public static void beforeTest() throws Exception {
-    File homeDir = createTempDir().toFile();
+    Path homeDir = createTempDir();
 
-    File collDir = new File(homeDir, "collection1");
-    File dataDir = new File(collDir, "data");
-    File confDir = new File(collDir, "conf");
+    Path collDir = homeDir.resolve("collection1");
+    Path dataDir = collDir.resolve("data");
+    Path confDir = collDir.resolve("conf");
 
-    homeDir.mkdirs();
-    collDir.mkdirs();
-    dataDir.mkdirs();
-    confDir.mkdirs();
+    Files.createDirectories(homeDir);
+    Files.createDirectories(collDir);
+    Files.createDirectories(dataDir);
+    Files.createDirectories(confDir);
 
-    FileUtils.copyFile(
-        new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(homeDir, "solr.xml"));
+    Files.copy(Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), homeDir.resolve("solr.xml"));
     String src_dir = TEST_HOME() + "/collection1/conf";
-    FileUtils.copyFile(new File(src_dir, "schema-tiny.xml"), new File(confDir, "schema.xml"));
-    FileUtils.copyFile(
-        new File(src_dir, "solrconfig-coreproperties.xml"), new File(confDir, "solrconfig.xml"));
-    FileUtils.copyFile(
-        new File(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
-        new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));
+    Files.copy(Path.of(src_dir, "schema-tiny.xml"), confDir.resolve("schema.xml"));
+    Files.copy(
+        Path.of(src_dir, "solrconfig-coreproperties.xml"), confDir.resolve("solrconfig.xml"));
+    Files.copy(
+        Path.of(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
+        confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
 
     Properties p = new Properties();
     p.setProperty("foo.foo1", "f1");
     p.setProperty("foo.foo2", "f2");
-    Writer fos =
+    try (Writer fos =
         new OutputStreamWriter(
-            new FileOutputStream(new File(confDir, "solrcore.properties")), StandardCharsets.UTF_8);

Review Comment:
   o neat didn't know `Files.newBufferedWriter` existed



##########
solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java:
##########
@@ -42,45 +39,46 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {
 
   @BeforeClass
   public static void beforeTest() throws Exception {
-    File homeDir = createTempDir().toFile();
+    Path homeDir = createTempDir();
 
-    File collDir = new File(homeDir, "collection1");
-    File dataDir = new File(collDir, "data");
-    File confDir = new File(collDir, "conf");
+    Path collDir = homeDir.resolve("collection1");
+    Path dataDir = collDir.resolve("data");
+    Path confDir = collDir.resolve("conf");
 
-    homeDir.mkdirs();
-    collDir.mkdirs();
-    dataDir.mkdirs();
-    confDir.mkdirs();
+    Files.createDirectories(homeDir);
+    Files.createDirectories(collDir);
+    Files.createDirectories(dataDir);
+    Files.createDirectories(confDir);
 
-    FileUtils.copyFile(
-        new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(homeDir, "solr.xml"));
+    Files.copy(Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), homeDir.resolve("solr.xml"));
     String src_dir = TEST_HOME() + "/collection1/conf";
-    FileUtils.copyFile(new File(src_dir, "schema-tiny.xml"), new File(confDir, "schema.xml"));
-    FileUtils.copyFile(
-        new File(src_dir, "solrconfig-coreproperties.xml"), new File(confDir, "solrconfig.xml"));
-    FileUtils.copyFile(
-        new File(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
-        new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));
+    Files.copy(Path.of(src_dir, "schema-tiny.xml"), confDir.resolve("schema.xml"));
+    Files.copy(
+        Path.of(src_dir, "solrconfig-coreproperties.xml"), confDir.resolve("solrconfig.xml"));
+    Files.copy(
+        Path.of(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
+        confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
 
     Properties p = new Properties();
     p.setProperty("foo.foo1", "f1");
     p.setProperty("foo.foo2", "f2");
-    Writer fos =
+    try (Writer fos =
         new OutputStreamWriter(
-            new FileOutputStream(new File(confDir, "solrcore.properties")), StandardCharsets.UTF_8);

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



##########
solr/core/src/java/org/apache/solr/cloud/ZkCLI.java:
##########
@@ -424,30 +419,27 @@ public static void main(String[] args)
             System.exit(1);
           }
 
-          String path = arglist.get(0).toString();
-          InputStream is = new FileInputStream(arglist.get(1).toString());
-          byte[] data = IOUtils.toByteArray(is);
+          String path = arglist.get(0);
+          byte[] data;
+          try (InputStream inputStream = Files.newInputStream(Path.of(arglist.get(1)))) {
+            data = inputStream.readAllBytes();
+          }

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



##########
solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java:
##########
@@ -112,32 +112,32 @@ public void testCreateSavesSysProps() throws Exception {
     // verify props are in persisted file
 
     Properties props = new Properties();
-    File propFile =
-        new File(solrHomeDirectory, coreSysProps + "/" + CorePropertiesLocator.PROPERTIES_FILENAME);
-    FileInputStream is = new FileInputStream(propFile);
-    try {
+    Path propFile =
+        solrHomeDirectory
+            .toPath()
+            .resolve(coreSysProps)
+            .resolve(CorePropertiesLocator.PROPERTIES_FILENAME);
+    try (InputStream is = Files.newInputStream(propFile)) {

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



##########
solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java:
##########
@@ -290,32 +290,32 @@ public void testCreateSavesRegProps() throws Exception {
 
     // verify props are in persisted file
     Properties props = new Properties();
-    File propFile =
-        new File(solrHomeDirectory, coreNormal + "/" + CorePropertiesLocator.PROPERTIES_FILENAME);
-    FileInputStream is = new FileInputStream(propFile);
-    try {
+    Path propFile =
+        solrHomeDirectory
+            .toPath()
+            .resolve(coreNormal)
+            .resolve(CorePropertiesLocator.PROPERTIES_FILENAME);
+    try (InputStream is = Files.newInputStream(propFile)) {

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



##########
solr/core/src/java/org/apache/solr/cloud/ConfigSetCmds.java:
##########
@@ -70,12 +70,9 @@ private static NamedList<Object> getConfigSetProperties(
       throws IOException {
     byte[] oldPropsData = configSetService.downloadFileFromConfig(configName, propertyPath);
     if (oldPropsData != null) {
-      InputStreamReader reader =
-          new InputStreamReader(new ByteArrayInputStream(oldPropsData), StandardCharsets.UTF_8);
-      try {
+      try (InputStreamReader reader =

Review Comment:
   will keep it in mind for the future



##########
solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java:
##########
@@ -338,7 +337,7 @@ public void testDeleteInstanceDir() throws Exception {
       CoreAdminRequest.renameCore("corerename", "brand_new_core_name", client);
       Properties props = new Properties();
       try (InputStreamReader is =
-          new InputStreamReader(new FileInputStream(renamePropFile), StandardCharsets.UTF_8)) {
+          new InputStreamReader(Files.newInputStream(renamePropFile), StandardCharsets.UTF_8)) {

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



##########
solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java:
##########
@@ -214,15 +213,11 @@ public void testPutFile() throws Exception {
 
     String fromZk =
         new String(zkClient.getData("/solr.xml", null, null, true), StandardCharsets.UTF_8);
-    File locFile = new File(SOLR_HOME + File.separator + "solr-stress-new.xml");
-    InputStream is = new FileInputStream(locFile);
-    String fromLoc;
-    try {
-      fromLoc = new String(IOUtils.toByteArray(is), StandardCharsets.UTF_8);
-    } finally {
-      IOUtils.closeQuietly(is);
+    Path locFile = Path.of(SOLR_HOME, "solr-stress-new.xml");
+    try (InputStream is = Files.newInputStream(locFile)) {
+      String fromLoc = new String(is.readAllBytes(), StandardCharsets.UTF_8);
+      assertEquals("Should get back what we put in ZK", fromZk, fromLoc);
     }

Review Comment:
   Addressed in 7079308294cb7f4d4c468dbdc890afd2a6d67d2e



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org