[HUDI-1913] Using streams instead of loops for input/output (#2962)
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
package org.apache.hudi.cli.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.logging.Logger;
|
||||
@@ -41,13 +40,10 @@ public class InputStreamConsumer extends Thread {
|
||||
try {
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
LOG.info(line);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
LOG.severe(ioe.toString());
|
||||
ioe.printStackTrace();
|
||||
br.lines().forEach(LOG::info);
|
||||
} catch (Exception e) {
|
||||
LOG.severe(e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,10 +100,9 @@ public class DFSPropertiesConfiguration {
|
||||
*/
|
||||
public void addProperties(BufferedReader reader) throws IOException {
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
reader.lines().forEach(line -> {
|
||||
if (line.startsWith("#") || line.equals("") || !line.contains("=")) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
String[] split = splitProperty(line);
|
||||
if (line.startsWith("include=") || line.startsWith("include =")) {
|
||||
@@ -111,7 +110,8 @@ public class DFSPropertiesConfiguration {
|
||||
} else {
|
||||
props.setProperty(split[0], split[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
@@ -112,10 +112,7 @@ public class HoodieWithTimelineServer implements Serializable {
|
||||
|
||||
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
rd.lines().forEach(result::append);
|
||||
System.out.println("Got result (" + result + ")");
|
||||
return result.toString();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -212,14 +212,11 @@ public class UtilitiesTestBase {
|
||||
// to get hold of resources bundled with jar
|
||||
private static ClassLoader classLoader = Helpers.class.getClassLoader();
|
||||
|
||||
public static String readFile(String testResourcePath) throws IOException {
|
||||
public static String readFile(String testResourcePath) {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(testResourcePath)));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
reader.lines().forEach(line -> sb.append(line).append("\n"));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -227,10 +224,7 @@ public class UtilitiesTestBase {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(new FileInputStream(absolutePathForResource)));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
reader.lines().forEach(line -> sb.append(line).append("\n"));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user