1 package org.jastacry.layer;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.OutputStream;
7 import java.util.Base64;
8 import java.util.Objects;
9
10 import org.apache.commons.io.IOUtils;
11 import org.jastacry.JastacryException;
12
13
14
15
16
17
18
19
20 public class AsciiTransportLayer extends AbstractBasicLayer
21 {
22
23
24
25 public static final String LAYERNAME = "ASCII Layer";
26
27
28
29
30 public AsciiTransportLayer()
31 {
32 super(AsciiTransportLayer.class, LAYERNAME);
33 }
34
35
36
37
38
39
40 @Override
41 public final void init(final String data)
42 {
43
44 }
45
46
47
48
49
50
51
52
53 @Override
54 public final void encStream(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
55 {
56 try
57 {
58 final Base64.Encoder encoder = Base64.getEncoder();
59 final byte[] bytes = IOUtils.toByteArray(inputStream);
60 final byte[] bytesEncoded = encoder.encode(bytes);
61 final ByteArrayInputStream inputByteStream = new ByteArrayInputStream(bytesEncoded);
62 final int iCount = IOUtils.copy(inputByteStream, outputStream);
63 logger.debug("encStream copied {} bytes", iCount);
64 }
65 catch (IOException e)
66 {
67 throw (JastacryExceptionl#JastacryException">JastacryException) new JastacryException("encStream failed").initCause(e);
68 }
69 }
70
71
72
73
74
75
76
77
78 @Override
79 public final void decStream(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
80 {
81 try
82 {
83 final Base64.Decoder decoder = Base64.getDecoder();
84 final InputStream isDecoded = decoder.wrap(inputStream);
85 final int iCount = IOUtils.copy(isDecoded, outputStream);
86 logger.debug("decStream copied {} bytes", iCount);
87 }
88 catch (IOException e)
89 {
90 throw (JastacryExceptionl#JastacryException">JastacryException) new JastacryException("encStream failed").initCause(e);
91 }
92 }
93
94 @Override
95 public final void encodeAndDecode(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
96 {
97 throw new UnsupportedOperationException();
98 }
99
100
101
102
103
104
105 @Override
106 public boolean equals(final Object o)
107 {
108 return o == this || o instanceof AsciiTransportLayer;
109 }
110
111
112
113
114
115 @Override
116 public int hashCode()
117 {
118 return Objects.hash();
119 }
120 }