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