//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class PPGPreprocessor {
String exe_path = null;
public PPGPreprocessor(String exe_path) {
this.exe_path = exe_path;
}
public Wave preprocess(String file_path) {
Process pr = null;
try {
pr = Runtime.getRuntime().exec(this.exe_path + " --file_path " + file_path);
} catch (IOException var12) {
throw new InvalidWaveException("Running exe error", -1);
}
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
ArrayList<Double> rawDCDataPoints = new ArrayList();
ArrayList<Integer> startIndices = new ArrayList();
ArrayList endIndices = new ArrayList();
try {
line = in.readLine();
if (line.startsWith("Error")) {
if (line.endsWith("0")) {
throw new InvalidWaveException("Reading data error", 0);
}
if (line.endsWith("1")) {
throw new InvalidWaveException("Wave not long enough", 1);
}
if (line.endsWith("2")) {
throw new InvalidWaveException("No valid wavelets detected", 2);
}
if (line.endsWith("3")) {
throw new InvalidWaveException("No valid waveform detected", 3);
}
}
String[] var11;
int var10 = (var11 = line.split(",")).length;
String idx;
int var9;
for(var9 = 0; var9 < var10; ++var9) {
idx = var11[var9];
rawDCDataPoints.add(Double.parseDouble(idx.trim()));
}
line = in.readLine();
var10 = (var11 = line.split(",")).length;
for(var9 = 0; var9 < var10; ++var9) {
idx = var11[var9];
startIndices.add(Integer.parseInt(idx.trim()));
}
line = in.readLine();
var10 = (var11 = line.split(",")).length;
for(var9 = 0; var9 < var10; ++var9) {
idx = var11[var9];
endIndices.add(Integer.parseInt(idx.trim()));
}
in.close();
pr.destroy();
return new Wave(rawDCDataPoints, startIndices, endIndices);
} catch (IOException var13) {
throw new InvalidWaveException("Running exe error", -1);
}
}
public Wave preprocess(double[] data) {
String file_path = (new File(this.exe_path)).getParentFile().getAbsolutePath();
File tempFile = null;
FileWriter f;
try {
new File(file_path);
tempFile = File.createTempFile("tempPPGData", ".txt");
f = new FileWriter(tempFile);
double[] var9 = data;
int var8 = data.length;
for(int var7 = 0; var7 < var8; ++var7) {
double x = var9[var7];
f.write(String.valueOf(x) + " ");
}
f.write(10);
f.flush();
f.close();
} catch (IOException var16) {
var16.printStackTrace();
}
file_path = tempFile.getAbsolutePath();
f = null;
Process pr;
try {
pr = Runtime.getRuntime().exec(this.exe_path + " --file_path " + file_path + " --file_format " + "array");
} catch (IOException var14) {
throw new InvalidWaveException("Running exe error", -1);
}
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
ArrayList<Double> rawDCDataPoints = new ArrayList();
ArrayList<Integer> startIndices = new ArrayList();
ArrayList endIndices = new ArrayList();
try {
line = in.readLine();
if (line.startsWith("Error")) {
if (line.endsWith("0")) {
throw new InvalidWaveException("Reading data error", 0);
}
if (line.endsWith("1")) {
throw new InvalidWaveException("Wave not long enough", 1);
}
if (line.endsWith("2")) {
throw new InvalidWaveException("No valid wavelets detected", 2);
}
if (line.endsWith("3")) {
throw new InvalidWaveException("No valid waveform detected", 3);
}
}
String[] var13;
int var12 = (var13 = line.split(",")).length;
String idx;
int var11;
for(var11 = 0; var11 < var12; ++var11) {
idx = var13[var11];
rawDCDataPoints.add(Double.parseDouble(idx.trim()));
}
line = in.readLine();
var12 = (var13 = line.split(",")).length;
for(var11 = 0; var11 < var12; ++var11) {
idx = var13[var11];
startIndices.add(Integer.parseInt(idx.trim()));
}
line = in.readLine();
var12 = (var13 = line.split(",")).length;
for(var11 = 0; var11 < var12; ++var11) {
idx = var13[var11];
endIndices.add(Integer.parseInt(idx.trim()));
}
in.close();
pr.destroy();
tempFile.delete();
return new Wave(rawDCDataPoints, startIndices, endIndices);
} catch (IOException var15) {
throw new InvalidWaveException("Running exe error", -1);
}
}
}
练习一下:
Java代码:
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @ClassName: test01
* @Description: 测试防范
* @author: 惠涛
* @date: 2024/4/26 1:35
*/
public class test01 {
public static void main(String args[]) {
String exe_path = "H:\\WorkPlace\\JavaPlace\\Hadoop_test\\file\\test.py";
String file_path = "H:\\WorkPlace\\JavaPlace\\Hadoop_test\\Nfile";
Process pr = null;
try {
pr = Runtime.getRuntime().exec("python " + exe_path + " --file_path " + file_path);
} catch (IOException e) {
}
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
try {
line = in.readLine(); //读取第一行的数据
System.out.print(line +"\n");
line = in.readLine(); //读取第一行的数据
System.out.print(line+"\n");
} catch (IOException e) {
}
}
}
python代码:test.py
import sys
def hug():
yu = sys.argv[1:]
print(yu,end="\n")
du = "谢谢!"
les=str.encode(du,"utf-8")
print(les,end="\n")
hug()
结果:
['--file_path', 'H:\\WorkPlace\\JavaPlace\\Hadoop_test\\Nfile']
b'\xe8\xb0\xa2\xe8\xb0\xa2\xef\xbc\x81'