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   * A transparent layer just doing nothing with the data. Use it as an example framework to start with.
12   *
13   * <p>SPDX-License-Identifier: MIT
14   *
15   * @author Kai Kretschmann
16   */
17  public class TransparentLayer extends AbstractBasicLayer
18  {
19      /**
20       * static name of the layer.
21       */
22      public static final String LAYERNAME = "Transparent Layer";
23  
24      /**
25       * Constructor of TransparentLayer.
26       */
27      public TransparentLayer()
28      {
29          super(TransparentLayer.class, LAYERNAME);
30      }
31  
32      /**
33       * encode Stream function which does the real thing.
34       *
35       * @param inputStream incoming data
36       * @param outputStream outgoing data
37       * @throws JastacryException thrown on error
38       */
39      public final void encodeAndDecode(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
40      {
41          try
42          {
43              int iChar;
44              while ((iChar = inputStream.read()) != -1)
45              { // NOPMD by kai on 21.11.17 17:13
46                  outputStream.write(iChar);
47              }
48              logger.info("close pipe");
49              outputStream.close();
50          }
51          catch (IOException e)
52          {
53              throw (JastacryExceptionl#JastacryException">JastacryException) new JastacryException("encodeAndDecode failed").initCause(e);
54          }
55      }
56  
57      /**
58       * init function.
59       *
60       * @param data to initialise nothing.
61       */
62      @Override
63      public final void init(final String data)
64      {
65          // empty by intend
66      }
67  
68      /**
69       * Override equals method from object class.
70       * @param o object to compare with
71       * @return true or false
72       */
73      @Override
74      public boolean equals(final Object o)
75      {
76          return o == this || o instanceof TransparentLayer;
77      }
78  
79      /**
80       * Override equals method from object class.
81       * @return hash of properties
82       */
83      @Override
84      public int hashCode()
85      {
86          return Objects.hash();
87      }
88  }