1 package org.jastacry.layer;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
6 import java.util.Objects;
7
8 import org.jastacry.JastacryException;
9
10
11
12
13
14
15
16
17
18 public class RandomLayer extends AbstractBasicLayer
19 {
20
21
22
23 public static final String LAYERNAME = "Random Layer";
24
25
26
27
28 private final java.util.Random rand = new java.util.Random();
29
30
31
32
33 private long seed;
34
35
36
37
38 public RandomLayer()
39 {
40 super(RandomLayer.class, LAYERNAME);
41 }
42
43
44
45
46
47 public final long getSeed()
48 {
49 return seed;
50 }
51
52
53
54
55
56 public final void setSeed(final long newSeed)
57 {
58 this.seed = newSeed;
59 }
60
61
62
63
64
65
66 @Override
67 public final void init(final String data)
68 {
69 setSeed(Long.parseLong(data));
70 rand.setSeed(seed);
71 }
72
73
74
75
76
77
78
79
80 public void encodeAndDecode(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
81 {
82 try
83 {
84 int iChar;
85 byte bChar;
86 final byte[] bRand = new byte[1];
87 while ((iChar = inputStream.read()) != -1)
88 {
89 bChar = (byte) iChar;
90 this.rand.nextBytes(bRand);
91 bChar = (byte) (bChar ^ bRand[0]);
92 outputStream.write(bChar);
93 }
94 logger.info("close pipe");
95 outputStream.close();
96 }
97 catch (IOException e)
98 {
99 throw (JastacryExceptionl#JastacryException">JastacryException) new JastacryException("encodeAndDecode failed").initCause(e);
100 }
101 }
102
103
104
105
106
107
108 @Override
109 public boolean equals(final Object o)
110 {
111 return o == this || o instanceof RandomLayer/org/jastacry/layer/RandomLayer.html#RandomLayer">RandomLayer && ((RandomLayer) o).getSeed() == this.getSeed();
112 }
113
114
115
116
117
118 @Override
119 public int hashCode()
120 {
121 return Objects.hash(seed);
122 }
123 }