View Javadoc
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   * Read write layer for IO purpose.
12   *
13   * <p>SPDX-License-Identifier: MIT
14   * @author kkretsch
15   *
16   */
17  public class ReadWriteLayer extends AbstractBasicLayer
18  {
19      /**
20       * static name of the layer.
21       */
22      public static final String LAYERNAME = "ReadWrite Layer";
23  
24      /**
25       * Constructor of class, calling super.
26       */
27      public ReadWriteLayer()
28      {
29          super(ReadWriteLayer.class, LAYERNAME);
30      }
31  
32      @Override
33      public final void run()
34      {
35          logger.info("started thread");
36          try
37          {
38              int i;
39              while ((i = inputStream.read()) != -1)
40              {
41                  outputStream.write(i);
42              }
43              logger.info("close stream");
44              outputStream.close();
45          }
46          catch (final IOException e)
47          {
48              logger.catching(e);
49          }
50          finally
51          {
52              endController.countDown();
53          }
54          logger.info("finished thread");
55      }
56  
57      @Override
58      public final void encodeAndDecode(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
59      {
60          throw new UnsupportedOperationException();
61      }
62  
63      /**
64       * init function.
65       *
66       * @param data to initialize nothing.
67       */
68      @Override
69      public final void init(final String data)
70      {
71          // empty by intend
72      }
73  
74      /**
75       * Override equals method from object class.
76       * @param o object to compare with
77       * @return true or false
78       */
79      public boolean equals(final Object o)
80      {
81          return o == this || o instanceof ReadWriteLayer;
82      }
83  
84      /**
85       * Override equals method from object class.
86       * @return hash of properties
87       */
88      @Override
89      public int hashCode()
90      {
91          return Objects.hash();
92      }
93  }