1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.base64;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.channel.ChannelHandler.Sharable;
20 import io.netty.channel.ChannelHandlerContext;
21 import io.netty.channel.ChannelPipeline;
22 import io.netty.handler.codec.DelimiterBasedFrameDecoder;
23 import io.netty.handler.codec.Delimiters;
24 import io.netty.handler.codec.MessageToMessageEncoder;
25 import io.netty.util.internal.ObjectUtil;
26
27 import java.util.List;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 @Sharable
44 public class Base64Encoder extends MessageToMessageEncoder<ByteBuf> {
45
46 private final boolean breakLines;
47 private final Base64Dialect dialect;
48
49 public Base64Encoder() {
50 this(true);
51 }
52
53 public Base64Encoder(boolean breakLines) {
54 this(breakLines, Base64Dialect.STANDARD);
55 }
56
57 public Base64Encoder(boolean breakLines, Base64Dialect dialect) {
58 super(ByteBuf.class);
59 this.dialect = ObjectUtil.checkNotNull(dialect, "dialect");
60 this.breakLines = breakLines;
61 }
62
63 @Override
64 protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
65 out.add(Base64.encode(msg, msg.readerIndex(), msg.readableBytes(), breakLines, dialect));
66 }
67 }