Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTransfer.java
More file actions
Latest commit
81 lines (76 loc) · 2.58 KB
/
Copy pathFileTransfer.java
File metadata and controls
81 lines (76 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
importjava.io.*;
importjava.math.BigInteger;
publicclassFileTransfer {
publicStringDoubleToBinary(Stringfile) throwsIOException{
FileReaderin = newFileReader(file);
BufferedReaderbr = newBufferedReader(in);
Stringout = file + "_Binary";
Fileoutput = newFile(out);
if (!output.exists()) {
output.createNewFile();
}
FileWriterfw = newFileWriter(output.getAbsoluteFile());
BufferedWriterbw = newBufferedWriter(fw);
Stringline;
while((line = br.readLine()) != null){
doubled = Double.valueOf(line);
Stringtext = Long.toBinaryString(Double.doubleToRawLongBits(d));
bw.write(text);
}
in.close();
bw.close();
returnout;
}
// index of the number in raw file, start from 0
publicStringBinaryToDouble(Stringfile, intstartIndex, intendIndex) throwsIOException{
FileReaderin = newFileReader(file);
BufferedReaderbr = newBufferedReader(in);
Stringout = file + "_Normal";
Fileoutput = newFile(out);
if (!output.exists()) {
output.createNewFile();
}
FileWriterfw = newFileWriter(output.getAbsoluteFile());
BufferedWriterbw = newBufferedWriter(fw);
intc;
intcounter_bit = 0;
intcounter_num = 0;
StringBuilderline = newStringBuilder();
while ((c = br.read()) != -1) {
if (counter_bit < startIndex * 62) {
counter_bit++;
continue;
} elseif (counter_bit >= (endIndex + 1) * 62) {
break;
}
if(counter_num == 0) line = newStringBuilder();
line.append( (char)c );
if(counter_num == 61){
Stringresult = line.toString();
doubled = Double.longBitsToDouble(newBigInteger(result, 2).longValue());
bw.write(Double.toString(d) + '\n');
counter_num = -1;
}
counter_num ++;
counter_bit ++;
}
in.close();
bw.close();
returnout;
}
publicstaticvoidmain(String[] args) throwsIOException{
// double d = 1.0;
// String text = Long.toBinaryString(Double.doubleToRawLongBits(d));
// System.out.println(text.length());
// System.out.println("0b "+ text);
// double nd = Double.longBitsToDouble(new BigInteger(text, 2).longValue());
// System.out.println("double "+nd);
intstartIndex = 3;
intendIndex = 5;
FileTransfers = newFileTransfer();
Stringinput = "svd.test.data.txt";
StringbinaryFile = s.DoubleToBinary(input);
StringnormalFile = s.BinaryToDouble(binaryFile, startIndex, endIndex);
// System.out.println(Double.doubleToRawLongBits(d));
}
}