1 package org.jastacry.layer; 2 3 import java.io.InputStream; 4 import java.io.OutputStream; 5 6 import org.jastacry.JastacryException; 7 import org.jastacry.GlobalData.Action; 8 9 /** 10 * Layer interface for more separation of methods. 11 * @author Kai Kretschmann 12 * 13 */ 14 public interface Layer 15 { 16 17 /** 18 * Optional method for setting encryption or decryption 19 * parameters like keys or passwords. 20 * 21 * @param data a String containing everything the layer needs to know 22 */ 23 void init(String data); 24 25 /** 26 * Local encode Stream function which does the real thing for Random Layer. 27 * 28 * @param newInputStream incoming data 29 * @param newOutputStream outgoing data 30 * @throws JastacryException thrown on error 31 */ 32 void encodeAndDecode(InputStream newInputStream, OutputStream newOutputStream) 33 throws JastacryException; 34 35 /** 36 * Encodes either plain text or an encoded layer to the next encoding layer. 37 * 38 * @param newInputStream existing and opened input stream 39 * @param newOutputStream existing and opened output stream 40 * @throws JastacryException if one of the streams fail 41 */ 42 default void encStream(InputStream newInputStream, OutputStream newOutputStream) throws JastacryException 43 { 44 encodeAndDecode(newInputStream, newOutputStream); 45 } 46 47 /** 48 * Decodes an encrypted stream to either plain text or the next encoded layer. 49 * 50 * @param newInputStream existing and opened input stream 51 * @param newOutputStream existing and opened output stream 52 * @throws JastacryException if one of the streams fail 53 */ 54 default void decStream(InputStream newInputStream, OutputStream newOutputStream) throws JastacryException 55 { 56 encodeAndDecode(newInputStream, newOutputStream); 57 } 58 59 /** 60 * Property setter for input stream. 61 * 62 * @param newInputStream the new stream 63 */ 64 void setInputStream(InputStream newInputStream); 65 66 /** 67 * property setter for output stream. 68 * 69 * @param newOutputStream the new output stream 70 */ 71 void setOutputStream(OutputStream newOutputStream); 72 73 /** 74 * Property setter for action. 75 * 76 * @param newAction the new action 77 */ 78 void setAction(Action newAction); 79 80 /** 81 * Property setter for realLayerName. 82 * 83 * @param newRealLayerName the new layer name 84 */ 85 void setRealLayerName(String newRealLayerName); 86 87 }