forked from sermakov/JavaPatternMirea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsk12.java
More file actions
63 lines (51 loc) · 1.65 KB
/
tsk12.java
File metadata and controls
63 lines (51 loc) · 1.65 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
package a;
import lombok.SneakyThrows;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
@SpringBootApplication
public class tsk12 {
static String __arg1;
static String __arg2;
public static void main(String[] args) {
//noinspection ConstantConditions
final var a = tsk12
.class
.getClassLoader()
.getResource(".")
.getPath();
__arg1 = a + "/a.txt"; // args[0]
__arg2 = a + "/b.hash"; // args[1]
SpringApplication.run(tsk12.class, args);
}
@Component
public static class A {
final File a = new File(__arg1);
final File b = new File(__arg2);
@SuppressWarnings("StringConcatenationInLoop")
@SneakyThrows
@PostConstruct
public void st() {
var c = "";
var e = a.exists();
if (e) {
final var r = new FileReader(a);
var d = 0;
while ((d = r.read()) != -1)
c += (char) d;
r.close();
} else c = "null";
assert b.exists() || b.createNewFile();
final var w = new FileWriter(b);
w.write(String.valueOf(e ? c.hashCode() : c));
w.close();
}
@SuppressWarnings("ResultOfMethodCallIgnored")
@PreDestroy public void en() { a.delete(); }
}
}